Index: main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests/test_accesscodes.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests/test_accesscodes.py	(revision 6550)
+++ main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests/test_accesscodes.py	(revision 6554)
@@ -35,10 +35,10 @@
 from zope.testing import renormalizing
 from waeup.sirp.app import University
-from waeup.sirp.interfaces import IObjectHistory
+from waeup.sirp.interfaces import IObjectHistory, IWAeUPSIRPPluggable
 from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
 from waeup.sirp.accesscodes.accesscodes import (
     AccessCodeBatch, get_access_code, invalidate_accesscode, AccessCode,
     disable_accesscode, reenable_accesscode, fire_transition,
-    AccessCodeBatchContainer,)
+    AccessCodeBatchContainer, AccessCodePlugin)
 from waeup.sirp.accesscodes.interfaces import (
     IAccessCode, IAccessCodeBatch,  IAccessCodeBatchContainer,)
@@ -240,4 +240,9 @@
             self.ac1.history)
         assert match is not None
+
+    def test_cost(self):
+        # We get the cost set in batch
+        cost = self.ac1.cost
+        assert cost == 6.6
 
 class AccessCodeBatchTests(FunctionalTestCase):
@@ -321,4 +326,16 @@
             os.path.dirname(__file__), 'sample_import.csv')
 
+        batch = AccessCodeBatch(    # create batch with zero entries
+            datetime.now(), 'testuser', 'BAR', 9.99, 0)
+        self.app['accesscodes'].addBatch(batch)
+
+        self.ac1 = AccessCode(0, '11111111')
+        self.ac2 = AccessCode(1, '22222222')
+        self.ac3 = AccessCode(2, '33333333')
+        batch['BAR-1-11111111'] = self.ac1
+        batch['BAR-1-22222222'] = self.ac2
+        batch['BAR-1-33333333'] = self.ac3
+        self.batch = batch
+
         setSite(self.app)
         return
@@ -349,4 +366,71 @@
             [u'FOO-1-11111111', u'FOO-1-22222222', u'FOO-1-33333333'])
 
+    def test_getAccessCode(self):
+        batchcontainer = self.app['accesscodes']
+        result1 = batchcontainer.getAccessCode('BAR-1-11111111')
+        result2 = batchcontainer.getAccessCode('BAR-1-not-existent')
+        assert isinstance(result1, AccessCode)
+        assert result2 is None
+
+    def test_disableAccessCode(self):
+        batchcontainer = self.app['accesscodes']
+        result1 = batchcontainer.disable('BAR-1-11111111')
+        result2 = batchcontainer.disable('BAR-1-not-existent')
+        assert self.ac1.state is DISABLED
+        assert result2 is None
+
+    def test_enableAccessCode(self):
+        batchcontainer = self.app['accesscodes']
+        batchcontainer.disable('BAR-1-11111111')
+        result1 = batchcontainer.enable('BAR-1-11111111')
+        result2 = batchcontainer.enable('BAR-1-not-existent')
+        assert self.ac1.state is INITIALIZED
+        assert result2 is None
+
+class AccessCodePluginTests(FunctionalTestCase):
+    # Tests for AccessCodeContainer class
+
+    layer = FunctionalLayer
+
+    def setUp(self):
+        super(AccessCodePluginTests, self).setUp()
+
+        # Prepopulate ZODB
+        app = University()
+        self.dc_root = tempfile.mkdtemp()
+        app['datacenter'].setStoragePath(self.dc_root)
+
+        # Prepopulate the ZODB...
+        self.getRootFolder()['app'] = app
+        self.app = self.getRootFolder()['app']
+
+    def tearDown(self):
+        shutil.rmtree(self.dc_root)
+        super(AccessCodePluginTests, self).tearDown()
+        return
+
+    def test_iface(self):
+        plugin = AccessCodePlugin()
+        assert verifyObject(IWAeUPSIRPPluggable, plugin)
+        assert verifyClass(IWAeUPSIRPPluggable, AccessCodePlugin)
+
+    def test_update_w_ac_container(self):
+        # The plugin changes nothing, if there is already a container
+        plugin = AccessCodePlugin()
+        site = self.app
+        logger = site.logger
+        accesscodes = site['accesscodes']
+        plugin.update(site, 'app', logger)
+        assert site['accesscodes'] is accesscodes
+
+    def test_update_wo_ac_container(self):
+        # The plugin creates a new accesscodes container if it is missing
+        plugin = AccessCodePlugin()
+        site = self.app
+        logger = site.logger
+        del site['accesscodes']
+        plugin.update(site, 'app', logger)
+        assert 'accesscodes' in site
+
 checker = renormalizing.RENormalizing([
         (re.compile('[\d]{10}'), '<10-DIGITS>'),
@@ -368,4 +452,5 @@
         AccessCodeBatchTests,
         AccessCodeBatchContainerTests,
+        AccessCodePluginTests,
         ]:
         suite.addTests(unittest.TestLoader().loadTestsFromTestCase(testcase))
