Changeset 6378 for main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests
- Timestamp:
- 16 Jun 2011, 15:08:47 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests/test_accesscodes.py
r6374 r6378 23 23 import tempfile 24 24 import unittest 25 from hurry.workflow.interfaces import InvalidTransitionError, IWorkflowState 25 26 from zope.app.testing.functional import FunctionalTestCase 26 from zope.component.hooks import setSite 27 from zope.component.hooks import setSite, clearSite 27 28 from waeup.sirp.app import University 28 29 from waeup.sirp.testing import FunctionalLayer 29 30 from waeup.sirp.accesscodes.accesscodes import ( 30 31 AccessCodeBatch, get_access_code, invalidate_accesscode, 31 disable_accesscode, reenable_accesscode) 32 disable_accesscode, reenable_accesscode, fire_transition) 33 from waeup.sirp.accesscodes.workflow import INITIALIZED, USED, DISABLED 32 34 33 35 class AccessCodeHelpersTests(FunctionalTestCase): … … 93 95 assert result is True 94 96 95 def test_invalidate_used_accesscode(self):96 invalidate_accesscode('APP-1-11111111')97 inv_date = self.ac1._invalidation_date98 result = invalidate_accesscode('APP-1-11111111')99 assert result is False100 assert self.ac1._invalidation_date == inv_date101 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 False107 assert self.ac1._disabled is True108 109 97 def test_disable_accesscode_unused(self): 98 # we can disable initialized acs 110 99 assert self.ac1._disabled is False 111 100 disable_accesscode('APP-1-11111111') … … 113 102 114 103 def test_disable_accesscode_used(self): 104 # we can disable already used acs 115 105 assert self.ac1._disabled is False 116 106 invalidate_accesscode('APP-1-11111111') … … 119 109 120 110 def test_reenable_accesscode(self): 111 # we can reenable disabled acs 121 112 disable_accesscode('APP-1-11111111') 122 113 result = reenable_accesscode('APP-1-11111111') … … 124 115 assert self.ac1._disabled is False 125 116 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 117 def test_fire_transition(self): 118 # we can fire transitions generally 119 fire_transition('APP-1-11111111', 'use') 120 assert IWorkflowState(self.ac1).getState() is USED 121 122 def test_fire_transition_toward(self): 123 # the `toward` keyword is respected 124 fire_transition('APP-1-11111111', DISABLED, toward=True) 125 assert IWorkflowState(self.ac1).getState() is DISABLED 126 127 def test_fire_transition_no_site(self): 128 # when no site is available, we will get a TypeError 129 clearSite() 130 self.assertRaises( 131 KeyError, 132 fire_transition, 'APP-1-11111111', 'use') 133 134 def test_fire_transition_broken_ac_id(self): 135 # if we get an invalid access code id (of wrong format) we get 136 # ValueErrors 137 self.assertRaises( 138 ValueError, 139 fire_transition, '11111111', 'use') 140 141 def test_fire_transition_invalid_batch_id(self): 142 # if we request a non-existent batch_id, we'll get a KeyError 143 self.assertRaises( 144 KeyError, 145 fire_transition, 'FOO-1-11111111', 'use') 146 147 def test_fire_transition_invalid_ac(self): 148 # if we request a non-exitent access-code, we'll get a KeyError 149 self.assertRaises( 150 KeyError, 151 fire_transition, 'APP-1-NONSENSE', 'use') 152 153 def test_fire_transition_undef_trans_id(self): 154 # asking for undefined transition id means a KeyError 155 self.assertRaises( 156 KeyError, 157 fire_transition, 'APP-1-11111111', 'nonsense') 158 159 def test_fire_transition_invalid_transition(self): 160 # asking for a forbidden transition will result in 161 # InvalidTransitionError 162 self.assertRaises( 163 InvalidTransitionError, 164 fire_transition, 'APP-1-11111111', 'init') # already initialized
Note: See TracChangeset for help on using the changeset viewer.