Ignore:
Timestamp:
23 Jul 2011, 10:23:30 (13 years ago)
Author:
uli
Message:

Add test for reimport of accesscodes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests/test_accesscodes.py

    r6471 r6544  
    3030from hurry.workflow.interfaces import InvalidTransitionError, IWorkflowState
    3131from zope.app.testing.functional import (
    32     FunctionalTestCase, FunctionalTestSetup, getRootFolder)
     32    FunctionalTestSetup, getRootFolder)
    3333from zope.component.hooks import setSite, clearSite
    3434from zope.interface.verify import verifyObject, verifyClass
     
    3636from waeup.sirp.app import University
    3737from waeup.sirp.interfaces import IObjectHistory
    38 from waeup.sirp.testing import FunctionalLayer
     38from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
    3939from waeup.sirp.accesscodes.accesscodes import (
    4040    AccessCodeBatch, get_access_code, invalidate_accesscode, AccessCode,
     
    4646
    4747
    48 
     48optionflags = (
     49    doctest.REPORT_NDIFF + doctest.ELLIPSIS + doctest.NORMALIZE_WHITESPACE)
    4950
    5051class AccessCodeHelpersTests(FunctionalTestCase):
     
    257258        self.app = self.getRootFolder()['app']
    258259
     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
    259272        setSite(self.app)
    260273        return
     
    271284        assert verifyClass(IAccessCodeBatch, AccessCodeBatch)
    272285
     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
    273303class AccessCodeBatchContainerTests(FunctionalTestCase):
    274304    # Tests for AccessCodeContainer class
     
    288318        self.app = self.getRootFolder()['app']
    289319
     320        self.import_sample1_src = os.path.join(
     321            os.path.dirname(__file__), 'sample_import.csv')
     322
    290323        setSite(self.app)
    291324        return
     
    300333        assert verifyObject(IAccessCodeBatchContainer, accesscodes)
    301334        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')
    302351
    303352
Note: See TracChangeset for help on using the changeset viewer.