Ignore:
Timestamp:
20 Jun 2011, 00:54:45 (14 years ago)
Author:
uli
Message:

Add basic tests for AccessCodeBatch? and other components from
accesscodes. We start to transfer checks from accesscodes.txt to unit
tests so that only the real descriptive things might remain in
accesscodes.txt.

File:
1 edited

Legend:

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

    r6413 r6414  
    2323import tempfile
    2424import unittest
     25from datetime import datetime
    2526from hurry.workflow.interfaces import InvalidTransitionError, IWorkflowState
    2627from zope.app.testing.functional import FunctionalTestCase
    2728from zope.component.hooks import setSite, clearSite
     29from zope.interface.verify import verifyObject, verifyClass
    2830from waeup.sirp.app import University
    2931from waeup.sirp.testing import FunctionalLayer
    3032from waeup.sirp.accesscodes.accesscodes import (
    31     AccessCodeBatch, get_access_code, invalidate_accesscode,
    32     disable_accesscode, reenable_accesscode, fire_transition)
     33    AccessCodeBatch, get_access_code, invalidate_accesscode, AccessCode,
     34    disable_accesscode, reenable_accesscode, fire_transition,
     35    AccessCodeBatchContainer,)
     36from waeup.sirp.accesscodes.interfaces import (
     37    IAccessCode, IAccessCodeBatch,  IAccessCodeBatchContainer,)
    3338from waeup.sirp.accesscodes.workflow import INITIALIZED, USED, DISABLED
    3439
     
    165170            fire_transition, 'APP-1-11111111', 'init') # already initialized
    166171
     172
     173class AccessCodeTests(FunctionalTestCase):
     174    # Tests for AccessCode class
     175
     176    layer = FunctionalLayer
     177
     178    def setUp(self):
     179        super(AccessCodeTests, self).setUp()
     180
     181        # Prepopulate ZODB
     182        app = University()
     183        self.dc_root = tempfile.mkdtemp()
     184        app['datacenter'].setStoragePath(self.dc_root)
     185
     186        # Prepopulate the ZODB...
     187        self.getRootFolder()['app'] = app
     188        self.app = self.getRootFolder()['app']
     189
     190        setSite(self.app)
     191        return
     192
     193    def tearDown(self):
     194        shutil.rmtree(self.dc_root)
     195        super(AccessCodeTests, self).tearDown()
     196        return
     197
     198    def test_iface(self):
     199        ac = AccessCode('1', '12345678')
     200        assert verifyObject(IAccessCode, ac)
     201        assert verifyClass(IAccessCode, AccessCode)
     202
     203class AccessCodeBatchTests(FunctionalTestCase):
     204    # Tests for AccessCodeBatch class
     205
     206    layer = FunctionalLayer
     207
     208    def setUp(self):
     209        super(AccessCodeBatchTests, self).setUp()
     210
     211        # Prepopulate ZODB
     212        app = University()
     213        self.dc_root = tempfile.mkdtemp()
     214        app['datacenter'].setStoragePath(self.dc_root)
     215
     216        # Prepopulate the ZODB...
     217        self.getRootFolder()['app'] = app
     218        self.app = self.getRootFolder()['app']
     219
     220        setSite(self.app)
     221        return
     222
     223    def tearDown(self):
     224        shutil.rmtree(self.dc_root)
     225        super(AccessCodeBatchTests, self).tearDown()
     226        return
     227
     228    def test_iface(self):
     229        batch = AccessCodeBatch(
     230            datetime(2009, 12, 23), 'Fred','APP', 12.12, 3, num=10)
     231        assert verifyObject(IAccessCodeBatch, batch)
     232        assert verifyClass(IAccessCodeBatch, AccessCodeBatch)
     233
     234class AccessCodeBatchContainerTests(FunctionalTestCase):
     235    # Tests for AccessCodeContainer class
     236
     237    layer = FunctionalLayer
     238
     239    def setUp(self):
     240        super(AccessCodeBatchContainerTests, self).setUp()
     241
     242        # Prepopulate ZODB
     243        app = University()
     244        self.dc_root = tempfile.mkdtemp()
     245        app['datacenter'].setStoragePath(self.dc_root)
     246
     247        # Prepopulate the ZODB...
     248        self.getRootFolder()['app'] = app
     249        self.app = self.getRootFolder()['app']
     250
     251        setSite(self.app)
     252        return
     253
     254    def tearDown(self):
     255        shutil.rmtree(self.dc_root)
     256        super(AccessCodeBatchContainerTests, self).tearDown()
     257        return
     258
     259    def test_iface(self):
     260        accesscodes = AccessCodeBatchContainer()
     261        assert verifyObject(IAccessCodeBatchContainer, accesscodes)
     262        assert verifyClass(IAccessCodeBatchContainer, AccessCodeBatchContainer)
Note: See TracChangeset for help on using the changeset viewer.