Changeset 6374 for main/waeup.sirp/trunk/src/waeup/sirp
- Timestamp:
- 15 Jun 2011, 23:45:04 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/accesscodes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/__init__.py
r6359 r6374 1 1 # Make this a package. 2 2 from waeup.sirp.accesscodes.accesscodes import ( 3 get_access_code, invalidate_accesscode) 3 get_access_code, invalidate_accesscode, disable_accesscode, 4 reenable_accesscode) 4 5 5 6 # Public API of this submodule … … 7 8 get_access_code, 8 9 invalidate_accesscode, 10 disable_accesscode, 11 reenable_accesscode, 9 12 ] 10 13 -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py
r6359 r6374 6 6 from BTrees.OIBTree import OIBTree 7 7 from datetime import datetime 8 from hurry.workflow.interfaces import IWorkflowInfo 8 from hurry.workflow.interfaces import IWorkflowInfo, InvalidTransitionError 9 9 from random import SystemRandom as random 10 10 from waeup.sirp.interfaces import IWAeUPSIRPPluggable … … 12 12 IAccessCode, IAccessCodeBatch, IAccessCodeBatchContainer 13 13 ) 14 from waeup.sirp.accesscodes.workflow import DISABLED 14 from waeup.sirp.accesscodes.workflow import DISABLED, INITIALIZED 15 15 16 16 class ManageACBatches(grok.Permission): … … 448 448 return code 449 449 450 def _fire_transition(info, arg, toward=False): 451 try: 452 if toward: 453 info.fireTransitionToward(arg) 454 else: 455 info.fireTransition(arg) 456 except InvalidTransitionError: 457 return False 458 return True 459 450 460 def invalidate_accesscode(access_code): 461 """Invalidate AccessCode denoted by string ``access_code``. 462 463 The access code that belongs to the passed string must exist. 464 465 Fires an appropriate transition to perform the task. 466 467 Returns ``True`` if the ac was invalidated, ``False`` else. 468 """ 451 469 ac = get_access_code(access_code) 452 470 info = IWorkflowInfo(ac) 453 info.fireTransition('use') 454 return 471 return _fire_transition(info, 'use') 455 472 456 473 def disable_accesscode(access_code): 474 """Disable AccessCode denoted by string ``access_code``. 475 476 The access code that belongs to the passed string must exist. 477 478 Fires an appropriate transition to perform the task. 479 480 Returns ``True`` if the ac was disabled, ``False`` else. 481 """ 457 482 ac = get_access_code(access_code) 458 483 info = IWorkflowInfo(ac) 459 info.fireTransitionToward(DISABLED) 460 return 484 return _fire_transition(info, DISABLED, toward=True) 461 485 462 486 def reenable_accesscode(access_code): 487 """Reenable AccessCode denoted by string ``access_code``. 488 489 The access code that belongs to the passed string must exist. 490 491 Fires an appropriate transition to perform the task. 492 493 Returns ``True`` if the ac was reenabled, ``False`` else. 494 """ 463 495 ac = get_access_code(access_code) 464 496 info = IWorkflowInfo(ac) 465 info.fireTransition('reenable') 466 return 497 return _fire_transition(info, 'reenable') -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests/test_accesscodes.py
r6359 r6374 29 29 from waeup.sirp.accesscodes.accesscodes import ( 30 30 AccessCodeBatch, get_access_code, invalidate_accesscode, 31 disable_accesscode )31 disable_accesscode, reenable_accesscode) 32 32 33 33 class AccessCodeHelpersTests(FunctionalTestCase): … … 89 89 def test_invalidate_accesscode(self): 90 90 assert self.ac1._invalidation_date is None 91 result = invalidate_accesscode('APP-1-11111111') 92 assert self.ac1._invalidation_date is not None 93 assert result is True 94 95 def test_invalidate_used_accesscode(self): 91 96 invalidate_accesscode('APP-1-11111111') 92 assert self.ac1._invalidation_date is not None 97 inv_date = self.ac1._invalidation_date 98 result = invalidate_accesscode('APP-1-11111111') 99 assert result is False 100 assert self.ac1._invalidation_date == inv_date 101 102 def test_invalidate_disabled_accesscode(self): 103 # disabled acs cannot be invalidated. 104 disable_accesscode('APP-1-11111111') 105 result = invalidate_accesscode('APP-1-11111111') 106 assert result is False 107 assert self.ac1._disabled is True 93 108 94 109 def test_disable_accesscode_unused(self): … … 102 117 disable_accesscode('APP-1-11111111') 103 118 assert self.ac1._disabled is True 119 120 def test_reenable_accesscode(self): 121 disable_accesscode('APP-1-11111111') 122 result = reenable_accesscode('APP-1-11111111') 123 assert result is True 124 assert self.ac1._disabled is False 125 126 def test_reenable_accesscode_enabled(self): 127 result = reenable_accesscode('APP-1-11111111') 128 assert result is False 129 assert self.ac1._disabled is False
Note: See TracChangeset for help on using the changeset viewer.