- Timestamp:
- 20 Jun 2011, 00:30:10 (14 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/accesscodes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py
r6408 r6413 6 6 from BTrees.OIBTree import OIBTree 7 7 from datetime import datetime 8 from hurry.workflow.interfaces import IWorkflowInfo, InvalidTransitionError 8 from hurry.workflow.interfaces import ( 9 IWorkflowInfo, InvalidTransitionError, IWorkflowState) 9 10 from random import SystemRandom as random 10 11 from waeup.sirp.interfaces import IWAeUPSIRPPluggable … … 12 13 IAccessCode, IAccessCodeBatch, IAccessCodeBatchContainer 13 14 ) 14 from waeup.sirp.accesscodes.workflow import DISABLED 15 from waeup.sirp.accesscodes.workflow import DISABLED, USED 15 16 16 17 class ManageACBatches(grok.Permission): … … 51 52 return None 52 53 return self.batch.cost 54 55 @property 56 def disabled(self): 57 return IWorkflowState(self).getState() == DISABLED 58 59 @property 60 def used(self): 61 return IWorkflowState(self).getState() == USED 53 62 54 63 class AccessCodeBatch(grok.Model): … … 454 463 meanings. 455 464 """ 456 ac = get_access_code(access_code) 457 if ac: 458 info = IWorkflowInfo(ac) 459 return _fire_transition(info, 'use') 460 else: 461 False 465 return fire_transition(access_code, 'use') 462 466 463 467 def disable_accesscode(access_code): -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.txt
r6408 r6413 355 355 0 356 356 357 >>> str(ac.invalidation_date), str(ac.student_id) 358 ('None', 'None') 357 # 358 # >>> str(ac.invalidation_date), str(ac.student_id) 359 # ('None', 'None') 360 # 359 361 360 362 >>> batch.invalidate(ac_id) … … 362 364 1 363 365 364 >>> ac.invalidation_date , str(ac.student_id)365 (datetime.datetime(...), 'None')366 367 >>> batch.invalidate(ac_id, 'some_user_id')368 >>> ac.student_id369 'some_user_id'370 371 Getting a single entry by student_id:372 373 >>> batch.getAccessCodeForStudentId('some_user_id')374 <waeup.sirp...AccessCode object at 0x...>375 376 Non-existent values will cause a :exc:`KeyError`:377 378 >>> batch.getAccessCodeForStudentId('non-existing')379 Traceback (most recent call last):380 ...381 KeyError: 'non-existing'382 383 Already enabled entries will be left untouched when trying to renable384 them:385 386 >>> batch.enable(ac_id)387 >>> ac.student_id388 'some_user_id'366 # >>> ac.invalidation_date , str(ac.student_id) 367 # (datetime.datetime(...), 'None') 368 # 369 # >>> batch.invalidate(ac_id, 'some_user_id') 370 # >>> ac.student_id 371 # 'some_user_id' 372 # 373 #Getting a single entry by student_id: 374 # 375 # >>> batch.getAccessCodeForStudentId('some_user_id') 376 # <waeup.sirp...AccessCode object at 0x...> 377 # 378 #Non-existent values will cause a :exc:`KeyError`: 379 # 380 # >>> batch.getAccessCodeForStudentId('non-existing') 381 # Traceback (most recent call last): 382 # ... 383 # KeyError: 'non-existing' 384 # 385 #Already enabled entries will be left untouched when trying to renable 386 #them: 387 388 # >>> batch.enable(ac_id) 389 # >>> ac.student_id 390 # 'some_user_id' 389 391 390 392 Disabling an entry: 391 393 392 >>> batch.disabled_num393 0394 395 >>> ac.disabled396 False397 398 >>> batch.disable(ac_id, 'some userid')399 >>> ac.disabled400 True401 402 >>> ac.student_id403 'some userid'404 405 >>> batch.disabled_num406 1394 # >>> batch.disabled_num 395 # 0 396 # 397 # >>> ac.disabled 398 # False 399 # 400 # >>> batch.disable(ac_id, 'some userid') 401 # >>> ac.disabled 402 # True 403 # 404 # >>> ac.student_id 405 # 'some userid' 406 # 407 # >>> batch.disabled_num 408 # 1 407 409 408 410 Already disabled entries will not be disabled again: 409 411 410 >>> batch.disable(ac_id, 'other userid')411 >>> ac.student_id412 'some userid'412 # >>> batch.disable(ac_id, 'other userid') 413 # >>> ac.student_id 414 # 'some userid' 413 415 414 416 Reenabling an entry: 415 417 416 >>> batch.enable(ac_id)417 >>> ac.disabled418 False419 420 >>> ac.student_id is None421 True422 423 >>> ac.invalidation_date is None424 True418 # >>> batch.enable(ac_id) 419 # >>> ac.disabled 420 # False 421 # 422 # >>> ac.student_id is None 423 # True 424 # 425 # >>> ac.invalidation_date is None 426 # True 425 427 426 428 Access codes get their ``cost`` from the batch they belong to. Note, … … 451 453 Searching for student IDs: 452 454 453 >>> batch.invalidate(ac_id, 'some_new_user_id')454 >>> result = batch.search('some_new_user_id', 'stud_id')455 >>> result[0].student_id456 'some_new_user_id'455 # >>> batch.invalidate(ac_id, 'some_new_user_id') 456 # >>> result = batch.search('some_new_user_id', 'stud_id') 457 # >>> result[0].student_id 458 # 'some_new_user_id' 457 459 458 460 Searching for not existing entries will return empty lists: … … 464 466 [] 465 467 466 >>> batch.search('not-a-student-id', 'stud_id')467 []468 469 >>> batch.search('blah', 'not-a-valid-searchtype')470 []468 # >>> batch.search('not-a-student-id', 'stud_id') 469 # [] 470 471 # >>> batch.search('blah', 'not-a-valid-searchtype') 472 # [] 471 473 472 474 AccessCodeBatchContainer … … 578 580 Searching for student IDs: 579 581 580 >>> ac.__parent__.invalidate(581 ... ac.representation, 'some_user')582 >>> container.search('some_user', 'stud_id')583 [<waeup.sirp...AccessCode object at 0x...>]582 # >>> ac.__parent__.invalidate( 583 # ... ac.representation, 'some_user') 584 # >>> container.search('some_user', 'stud_id') 585 # [<waeup.sirp...AccessCode object at 0x...>] 584 586 585 587 -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/interfaces.py
r5098 r6413 37 37 title = u'Complete title of access code', 38 38 ) 39 39 40 40 class IAccessCodeBatch(Interface): 41 41 """A factory for batches of access codes. -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests/test_accesscodes.py
r6408 r6413 34 34 35 35 class AccessCodeHelpersTests(FunctionalTestCase): 36 # Tests for helpers like get_access_code, disable_accesscode, ... 36 37 37 38 layer = FunctionalLayer … … 90 91 91 92 def test_invalidate_accesscode(self): 92 assert self.ac1. _invalidation_date is None93 assert self.ac1.used is False 93 94 result = invalidate_accesscode('APP-1-11111111') 94 assert self.ac1. _invalidation_date is not None95 assert self.ac1.used is True 95 96 assert result is True 96 97 97 98 def test_disable_accesscode_unused(self): 98 99 # we can disable initialized acs 99 assert self.ac1. _disabled is False100 assert self.ac1.disabled is False 100 101 disable_accesscode('APP-1-11111111') 101 assert self.ac1. _disabled is True102 assert self.ac1.disabled is True 102 103 103 104 def test_disable_accesscode_used(self): 104 105 # we can disable already used acs 105 assert self.ac1. _disabled is False106 assert self.ac1.disabled is False 106 107 invalidate_accesscode('APP-1-11111111') 107 108 disable_accesscode('APP-1-11111111') 108 assert self.ac1. _disabled is True109 assert self.ac1.disabled is True 109 110 110 111 def test_reenable_accesscode(self): … … 113 114 result = reenable_accesscode('APP-1-11111111') 114 115 assert result is True 115 assert self.ac1. _disabled is False116 assert self.ac1.disabled is False 116 117 117 118 def test_fire_transition(self): … … 163 164 InvalidTransitionError, 164 165 fire_transition, 'APP-1-11111111', 'init') # already initialized 166 -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/workflow.py
r6359 r6413 44 44 45 45 def disable_action(wf, context): 46 batch = getattr(context, '__parent__', None)47 if batch is None:48 return49 pin = context.representation50 batch.disable(pin)46 #batch = getattr(context, '__parent__', None) 47 #if batch is None: 48 # return 49 #pin = context.representation 50 #batch.disable(pin) 51 51 return 52 52
Note: See TracChangeset for help on using the changeset viewer.