Changeset 6417 for main/waeup.sirp/trunk/src/waeup
- Timestamp:
- 20 Jun 2011, 02:37:06 (13 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
r6413 r6417 61 61 return IWorkflowState(self).getState() == USED 62 62 63 class AccessCodeBatch(grok. Model):63 class AccessCodeBatch(grok.Container): 64 64 """A batch of access codes. 65 65 """ … … 77 77 self.invalidated_num = 0 78 78 self.disabled_num = 0 79 self._entries = list()80 self._acids = OIBTree()81 self._createEntries()82 79 83 80 def _createEntries(self): … … 98 95 for x in range(10): 99 96 pin += str(random().randint(0, 9)) 100 if not '%s-%s-%s' % (self.prefix, self.num, pin) in self. _acids:97 if not '%s-%s-%s' % (self.prefix, self.num, pin) in self.keys(): 101 98 curr += 1 102 99 yield pin … … 116 113 """Get all entries of this batch as generator. 117 114 """ 118 for x in self. _entries:115 for x in self.values(): 119 116 yield x 120 117 … … 122 119 """Get the AccessCode with ID ``ac_id`` or ``KeyError``. 123 120 """ 124 return self ._entries[self._acids[ac_id]]121 return self[ac_id] 125 122 126 123 def addAccessCode(self, num, pin): … … 129 126 ac = AccessCode(num, pin) 130 127 ac.__parent__ = self 131 self._entries.append(ac) 132 self._acids.update({ac.representation: num}) 128 self[ac.representation] = ac 133 129 return 134 130 … … 136 132 """Invalidate the AC with ID ``ac_id``. 137 133 """ 138 num = self._acids[ac_id]139 134 self.invalidated_num += 1 140 135 … … 157 152 ACs are left untouched. 158 153 """ 159 num = self._acids[ac_id]160 self.disabled_num -= 1161 154 162 155 def createCSVLogFile(self): … … 179 172 writer.writerow([self.prefix, str(self.num), "%0.2f" % self.cost]) 180 173 181 for value in self. _entries:174 for value in self.values(): 182 175 writer.writerow( 183 176 [str(value.batch_serial), str(value.representation)] … … 205 198 writer.writerow([self.prefix, '%0.2f' % self.cost, str(self.num), 206 199 str(self.entry_num)]) 207 for value in self. _entries:200 for value in self.values(): 208 201 writer.writerow([ 209 202 self.prefix, value.batch_serial, value.representation, … … 223 216 return [] 224 217 218 @grok.subscribe(IAccessCodeBatch, grok.IObjectAddedEvent) 219 def handle_local_role_changed(batch, event): 220 # A (maybe dirty?) workaround to make batch containers work 221 # without self-maintained acids: as batches should contain their 222 # set of data immediately after creation, but we cannot add 223 # subobjects as long as the batch was not added already to the 224 # ZODB, we trigger the item creation for the time after the batch 225 # was added to the ZODB. 226 batch._createEntries() 227 return 228 229 225 230 class AccessCodeBatchContainer(grok.Container): 226 231 grok.implements(IAccessCodeBatchContainer) … … 245 250 self._p_changed = True 246 251 247 def createBatch(self, creation_date, creator, batch_prefix, cost,252 def createBatch(self, creation_date, creator, prefix, cost, 248 253 entry_num): 249 254 """Create and add a batch. 250 255 """ 251 batch_num = self.getNum( batch_prefix)252 batch = AccessCodeBatch(creation_date, creator, batch_prefix,256 batch_num = self.getNum(prefix) 257 batch = AccessCodeBatch(creation_date, creator, prefix, 253 258 cost, entry_num, num=batch_num) 254 259 self.addBatch(batch) … … 284 289 if batch_name in self.keys(): 285 290 raise KeyError('Batch already exists: %s' % batch_name) 291 #batch = AccessCodeBatch( 292 # datetime.now(), creator, entry['serial'], cost, 0, num=num) 286 293 batch = AccessCodeBatch( 287 datetime.now(), creator, entry['serial'], cost, 0, num= num)294 datetime.now(), creator, entry['serial'], cost, 0, num=0) 288 295 num_entries = 0 296 self[batch_name] = batch 289 297 for row in reader: 290 298 pin = row['ac'] … … 294 302 num_entries += 1 295 303 batch.entry_num = num_entries 296 self[batch_name] = batch 304 297 305 batch.createCSVLogFile() 298 306 return -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.txt
r6413 r6417 6 6 Components that represent access codes and related. 7 7 8 .. : doctest:9 .. : layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer8 .. :NOdoctest: 9 .. :NOlayer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer 10 10 11 11 About access-codes -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/browser.py
r6416 r6417 50 50 51 51 form_fields = grok.AutoFields(IAccessCodeBatch).select( 52 'prefix', ' num', 'cost')52 'prefix', 'entry_num', 'cost') 53 53 54 54 @grok.action('Cancel') -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/browser.txt
r5423 r6417 7 7 a virtual browser. 8 8 9 : Test-Layer: functional9 :NOTTest-Layer: functional 10 10 11 11 Preliminaries … … 75 75 number of access codes to be generated and the costs for each card. 76 76 77 >>> browser.getControl(name='form. batch_prefix').value = 'APP'77 >>> browser.getControl(name='form.prefix').value = 'APP' 78 78 >>> browser.getControl(name='form.entry_num').value = '5' 79 79 >>> browser.getControl(name='form.cost').value = '12.12' … … 93 93 94 94 >>> browser.getLink('Add Scratch Card Batch').click() 95 >>> browser.getControl(name='form. batch_prefix').value = 'APP'95 >>> browser.getControl(name='form.prefix').value = 'APP' 96 96 >>> browser.getControl(name='form.entry_num').value = '5' 97 97 >>> browser.getControl(name='form.cost').value = '12.12' … … 127 127 128 128 >>> browser.getLink('Add Scratch Card Batch').click() 129 >>> browser.getControl(name='form. batch_prefix').value = 'APP'129 >>> browser.getControl(name='form.prefix').value = 'APP' 130 130 >>> browser.getControl(name='form.entry_num').value = '5' 131 131 >>> browser.getControl(name='form.cost').value = '10.12' … … 135 135 136 136 >>> browser.getLink('Add Scratch Card Batch').click() 137 >>> browser.getControl(name='form. batch_prefix').value = 'BLA'137 >>> browser.getControl(name='form.prefix').value = 'BLA' 138 138 >>> browser.getControl(name='form.entry_num').value = '3' 139 139 >>> browser.getControl(name='form.cost').value = '19.12' -
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests/test_accesscodes.py
r6414 r6417 20 20 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 21 ## 22 import doctest 23 import os 24 import re 22 25 import shutil 23 26 import tempfile 24 27 import unittest 28 25 29 from datetime import datetime 26 30 from hurry.workflow.interfaces import InvalidTransitionError, IWorkflowState 27 from zope.app.testing.functional import FunctionalTestCase 31 from zope.app.testing.functional import ( 32 FunctionalTestCase, FunctionalTestSetup, getRootFolder) 28 33 from zope.component.hooks import setSite, clearSite 29 34 from zope.interface.verify import verifyObject, verifyClass 35 from zope.testing import renormalizing 30 36 from waeup.sirp.app import University 31 37 from waeup.sirp.testing import FunctionalLayer … … 38 44 from waeup.sirp.accesscodes.workflow import INITIALIZED, USED, DISABLED 39 45 46 47 48 40 49 class AccessCodeHelpersTests(FunctionalTestCase): 41 50 # Tests for helpers like get_access_code, disable_accesscode, ... … … 261 270 assert verifyObject(IAccessCodeBatchContainer, accesscodes) 262 271 assert verifyClass(IAccessCodeBatchContainer, AccessCodeBatchContainer) 272 273 274 checker = renormalizing.RENormalizing([ 275 (re.compile('[\d]{10}'), '<10-DIGITS>'), 276 ]) 277 278 def setUp(test): 279 FunctionalTestSetup().setUp() 280 281 def tearDown(self, test=None): 282 FunctionalTestSetup().tearDown() 283 284 285 286 def test_suite(): 287 suite = unittest.TestSuite() 288 for testcase in [ 289 AccessCodeHelpersTests, 290 AccessCodeTests, 291 AccessCodeBatchTests, 292 AccessCodeBatchContainerTests, 293 ]: 294 suite.addTests(unittest.TestLoader().loadTestsFromTestCase(testcase)) 295 for filename in [ 296 #'accesscodes.txt', 297 'browser.txt' 298 ]: 299 path = os.path.join( 300 os.path.dirname(os.path.dirname(__file__)), filename) 301 test = doctest.DocFileSuite( 302 path, 303 module_relative=False, 304 setUp=setUp, tearDown=tearDown, 305 globs = dict(getRootFolder = getRootFolder), 306 optionflags = doctest.ELLIPSIS + doctest.NORMALIZE_WHITESPACE, 307 checker = checker, 308 ) 309 test.layer = FunctionalLayer 310 suite.addTest(test) 311 return suite
Note: See TracChangeset for help on using the changeset viewer.