Changeset 6554 for main/waeup.sirp/trunk


Ignore:
Timestamp:
24 Jul 2011, 03:25:38 (13 years ago)
Author:
uli
Message:

Add missing tests for accesscode components. accesscode subpackage now
at 100% test coverage :)

File:
1 edited

Legend:

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

    r6545 r6554  
    3535from zope.testing import renormalizing
    3636from waeup.sirp.app import University
    37 from waeup.sirp.interfaces import IObjectHistory
     37from waeup.sirp.interfaces import IObjectHistory, IWAeUPSIRPPluggable
    3838from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
    3939from waeup.sirp.accesscodes.accesscodes import (
    4040    AccessCodeBatch, get_access_code, invalidate_accesscode, AccessCode,
    4141    disable_accesscode, reenable_accesscode, fire_transition,
    42     AccessCodeBatchContainer,)
     42    AccessCodeBatchContainer, AccessCodePlugin)
    4343from waeup.sirp.accesscodes.interfaces import (
    4444    IAccessCode, IAccessCodeBatch,  IAccessCodeBatchContainer,)
     
    240240            self.ac1.history)
    241241        assert match is not None
     242
     243    def test_cost(self):
     244        # We get the cost set in batch
     245        cost = self.ac1.cost
     246        assert cost == 6.6
    242247
    243248class AccessCodeBatchTests(FunctionalTestCase):
     
    321326            os.path.dirname(__file__), 'sample_import.csv')
    322327
     328        batch = AccessCodeBatch(    # create batch with zero entries
     329            datetime.now(), 'testuser', 'BAR', 9.99, 0)
     330        self.app['accesscodes'].addBatch(batch)
     331
     332        self.ac1 = AccessCode(0, '11111111')
     333        self.ac2 = AccessCode(1, '22222222')
     334        self.ac3 = AccessCode(2, '33333333')
     335        batch['BAR-1-11111111'] = self.ac1
     336        batch['BAR-1-22222222'] = self.ac2
     337        batch['BAR-1-33333333'] = self.ac3
     338        self.batch = batch
     339
    323340        setSite(self.app)
    324341        return
     
    349366            [u'FOO-1-11111111', u'FOO-1-22222222', u'FOO-1-33333333'])
    350367
     368    def test_getAccessCode(self):
     369        batchcontainer = self.app['accesscodes']
     370        result1 = batchcontainer.getAccessCode('BAR-1-11111111')
     371        result2 = batchcontainer.getAccessCode('BAR-1-not-existent')
     372        assert isinstance(result1, AccessCode)
     373        assert result2 is None
     374
     375    def test_disableAccessCode(self):
     376        batchcontainer = self.app['accesscodes']
     377        result1 = batchcontainer.disable('BAR-1-11111111')
     378        result2 = batchcontainer.disable('BAR-1-not-existent')
     379        assert self.ac1.state is DISABLED
     380        assert result2 is None
     381
     382    def test_enableAccessCode(self):
     383        batchcontainer = self.app['accesscodes']
     384        batchcontainer.disable('BAR-1-11111111')
     385        result1 = batchcontainer.enable('BAR-1-11111111')
     386        result2 = batchcontainer.enable('BAR-1-not-existent')
     387        assert self.ac1.state is INITIALIZED
     388        assert result2 is None
     389
     390class AccessCodePluginTests(FunctionalTestCase):
     391    # Tests for AccessCodeContainer class
     392
     393    layer = FunctionalLayer
     394
     395    def setUp(self):
     396        super(AccessCodePluginTests, self).setUp()
     397
     398        # Prepopulate ZODB
     399        app = University()
     400        self.dc_root = tempfile.mkdtemp()
     401        app['datacenter'].setStoragePath(self.dc_root)
     402
     403        # Prepopulate the ZODB...
     404        self.getRootFolder()['app'] = app
     405        self.app = self.getRootFolder()['app']
     406
     407    def tearDown(self):
     408        shutil.rmtree(self.dc_root)
     409        super(AccessCodePluginTests, self).tearDown()
     410        return
     411
     412    def test_iface(self):
     413        plugin = AccessCodePlugin()
     414        assert verifyObject(IWAeUPSIRPPluggable, plugin)
     415        assert verifyClass(IWAeUPSIRPPluggable, AccessCodePlugin)
     416
     417    def test_update_w_ac_container(self):
     418        # The plugin changes nothing, if there is already a container
     419        plugin = AccessCodePlugin()
     420        site = self.app
     421        logger = site.logger
     422        accesscodes = site['accesscodes']
     423        plugin.update(site, 'app', logger)
     424        assert site['accesscodes'] is accesscodes
     425
     426    def test_update_wo_ac_container(self):
     427        # The plugin creates a new accesscodes container if it is missing
     428        plugin = AccessCodePlugin()
     429        site = self.app
     430        logger = site.logger
     431        del site['accesscodes']
     432        plugin.update(site, 'app', logger)
     433        assert 'accesscodes' in site
     434
    351435checker = renormalizing.RENormalizing([
    352436        (re.compile('[\d]{10}'), '<10-DIGITS>'),
     
    368452        AccessCodeBatchTests,
    369453        AccessCodeBatchContainerTests,
     454        AccessCodePluginTests,
    370455        ]:
    371456        suite.addTests(unittest.TestLoader().loadTestsFromTestCase(testcase))
Note: See TracChangeset for help on using the changeset viewer.