Changeset 8849 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 29 Jun 2012, 14:40:37 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/mandates
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/mandates/interfaces.py
r8846 r8849 34 34 35 35 class IMandate(IKofaObject): 36 """A base representation ofmandates.36 """A representation of all mandates. 37 37 38 38 """ … … 40 40 expires = Attribute('Expiration Datetime') 41 41 params = Attribute('Dictionary with mandate parameters') 42 category = Attribute('Mandate Category') 42 43 def execute(): 44 """Method which is performed by the mandate. 45 """ -
main/waeup.kofa/trunk/src/waeup/kofa/mandates/mandate.py
r8848 r8849 21 21 import grok 22 22 import hashlib 23 import os 23 24 from datetime import datetime, timedelta 24 from time import time25 25 from grok import index 26 26 from waeup.kofa.interfaces import IUserAccount … … 28 28 from waeup.kofa.mandates.interfaces import IMandate 29 29 30 class Mandate(grok. Container):31 """This is a mandate which can set a student password.30 class Mandate(grok.Model): 31 """This is a mandate. 32 32 """ 33 33 grok.implements(IMandate) 34 34 grok.provides(IMandate) 35 grok.baseclass() 35 36 36 def __init__(self, days=1, category=None,mandate_id=None):37 def __init__(self, days=1, mandate_id=None): 37 38 super(Mandate, self).__init__() 38 39 self.creation_date = datetime.utcnow() # offset-naive datetime … … 40 41 self.expires = datetime.utcnow() + delta 41 42 if mandate_id is None: 42 timestamp = "%d" % int(time()*1000)43 mandate_id = hashlib.md5( timestamp).hexdigest()43 mandate_id = os.urandom(20) 44 mandate_id = hashlib.md5(mandate_id).hexdigest() 44 45 self.mandate_id = mandate_id 45 self.category = category46 46 self.params = {} 47 47 return 48 49 def execute(self): 50 return _('Nothing to do.') 51 52 class StudentPasswordMandate(Mandate): 53 """This is a mandate which can set a student password. 54 """ 48 55 49 56 def _setStudentPassword(self): … … 60 67 if self.expires < datetime.utcnow(): 61 68 msg = _('Mandate expired.') 62 elif self.category == 'student_password': 63 if self._setStudentPassword(): 64 msg = _('Password has been successfully set.') 69 if self._setStudentPassword(): 70 msg = _('Password has been successfully set.') 65 71 del self.__parent__[self.mandate_id] 66 72 return msg -
main/waeup.kofa/trunk/src/waeup/kofa/mandates/tests.py
r8848 r8849 31 31 IMandatesContainer, IMandate) 32 32 from waeup.kofa.mandates.container import MandatesContainer 33 from waeup.kofa.mandates.mandate import Mandate33 from waeup.kofa.mandates.mandate import StudentPasswordMandate 34 34 from waeup.kofa.testing import (FunctionalLayer, FunctionalTestCase) 35 35 … … 50 50 self.assertTrue( 51 51 verifyClass( 52 IMandate, Mandate)52 IMandate, StudentPasswordMandate) 53 53 ) 54 54 self.assertTrue( 55 55 verifyObject( 56 IMandate, Mandate())56 IMandate, StudentPasswordMandate()) 57 57 ) 58 58 return … … 88 88 self.app['students'].addStudent(student) 89 89 # Add and execute a mandate with missing parameters. 90 mandate = Mandate()90 mandate = StudentPasswordMandate() 91 91 mandate.category = 'student_password' 92 92 self.app['mandates'].addMandate(mandate) … … 94 94 self.assertEqual(msg, u'Wrong mandate parameters.') 95 95 # Add and execute an expired mandate. 96 mandate = Mandate(days=0)96 mandate = StudentPasswordMandate(days=0) 97 97 mandate.category = 'student_password' 98 98 self.app['mandates'].addMandate(mandate) … … 100 100 self.assertEqual(msg, u'Mandate expired.') 101 101 # Add and execute a perfect mandate 102 mandate = Mandate()102 mandate = StudentPasswordMandate() 103 103 mandate.category = 'student_password' 104 104 mandate.params['student_id'] = student.student_id … … 114 114 def test_remove_expired(self): 115 115 # mandate1 is an old mandate which just expired. 116 mandate1 = Mandate(days=0)116 mandate1 = StudentPasswordMandate(days=0) 117 117 self.app['mandates'].addMandate(mandate1) 118 118 # mandate2 is a new mandate with default time delta. 119 mandate2 = Mandate(mandate_id='23456')119 mandate2 = StudentPasswordMandate(mandate_id='23456') 120 120 self.app['mandates'].addMandate(mandate2) 121 121 self.assertEqual(len(self.app['mandates'].keys()), 2) … … 128 128 student = createObject('waeup.Student') 129 129 self.app['students'].addStudent(student) 130 mandate = Mandate()130 mandate = StudentPasswordMandate() 131 131 mandate.category = 'student_password' 132 132 mandate.params['student_id'] = student.student_id
Note: See TracChangeset for help on using the changeset viewer.