Changeset 6544 for main/waeup.sirp/trunk/src/waeup/sirp
- Timestamp:
- 23 Jul 2011, 10:23:30 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests/test_accesscodes.py
r6471 r6544 30 30 from hurry.workflow.interfaces import InvalidTransitionError, IWorkflowState 31 31 from zope.app.testing.functional import ( 32 FunctionalTest Case, FunctionalTestSetup, getRootFolder)32 FunctionalTestSetup, getRootFolder) 33 33 from zope.component.hooks import setSite, clearSite 34 34 from zope.interface.verify import verifyObject, verifyClass … … 36 36 from waeup.sirp.app import University 37 37 from waeup.sirp.interfaces import IObjectHistory 38 from waeup.sirp.testing import FunctionalLayer 38 from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase 39 39 from waeup.sirp.accesscodes.accesscodes import ( 40 40 AccessCodeBatch, get_access_code, invalidate_accesscode, AccessCode, … … 46 46 47 47 48 48 optionflags = ( 49 doctest.REPORT_NDIFF + doctest.ELLIPSIS + doctest.NORMALIZE_WHITESPACE) 49 50 50 51 class AccessCodeHelpersTests(FunctionalTestCase): … … 257 258 self.app = self.getRootFolder()['app'] 258 259 260 batch = AccessCodeBatch( # create batch with zero entries 261 datetime.now(), 'testuser', 'FOO', 9.99, 0) 262 self.app['accesscodes'].addBatch(batch) 263 264 self.ac1 = AccessCode(0, '11111111') 265 self.ac2 = AccessCode(1, '22222222') 266 self.ac3 = AccessCode(2, '33333333') 267 batch['FOO-1-11111111'] = self.ac1 268 batch['FOO-1-22222222'] = self.ac2 269 batch['FOO-1-33333333'] = self.ac3 270 self.batch = batch 271 259 272 setSite(self.app) 260 273 return … … 271 284 assert verifyClass(IAccessCodeBatch, AccessCodeBatch) 272 285 286 def test_csv_export(self): 287 # Make sure CSV export of accesscodes works 288 batch = self.batch 289 invalidate_accesscode('FOO-1-11111111', comment='comment with "quotes"') 290 disable_accesscode('FOO-1-33333333') 291 basename = batch.archive() 292 result_path = os.path.join(batch._getStoragePath(), basename) 293 expected = ''' 294 "prefix","serial","ac","state","history" 295 "FOO","9.99","1","0" 296 "FOO","0","FOO-1-11111111","used","<YYYY-MM-DD hh:mm:ss> - ..." 297 "FOO","1","FOO-1-22222222","initialized","<YYYY-MM-DD hh:mm:ss> - ..." 298 "FOO","2","FOO-1-33333333","disabled","<YYYY-MM-DD hh:mm:ss> - ..." 299 '''[1:] 300 contents = open(result_path, 'rb').read() 301 self.assertMatches(expected, contents) 302 273 303 class AccessCodeBatchContainerTests(FunctionalTestCase): 274 304 # Tests for AccessCodeContainer class … … 288 318 self.app = self.getRootFolder()['app'] 289 319 320 self.import_sample1_src = os.path.join( 321 os.path.dirname(__file__), 'sample_import.csv') 322 290 323 setSite(self.app) 291 324 return … … 300 333 assert verifyObject(IAccessCodeBatchContainer, accesscodes) 301 334 assert verifyClass(IAccessCodeBatchContainer, AccessCodeBatchContainer) 335 336 def test_csv_import(self): 337 # Make sure we can reimport sample data from local sample_import.csv 338 batchcontainer = self.app['accesscodes'] 339 shutil.copyfile( # Copy sample to import dir 340 os.path.join(os.path.dirname(__file__), 'sample_import.csv'), 341 os.path.join(batchcontainer._getStoragePath(), 'sample_import.csv') 342 ) 343 batchcontainer.reimport('sample_import.csv') 344 batch = batchcontainer.get(u'FOO-1', None) 345 self.assertTrue(batch is not None) 346 keys = [x for x in batch.keys()] 347 self.assertEqual( 348 keys, 349 [u'FOO-1-11111111', u'FOO-1-22222222', u'FOO-1-33333333']) 350 self.fail('Continue writing tests here') 302 351 303 352
Note: See TracChangeset for help on using the changeset viewer.