Index: /main/waeup.sirp/trunk/src/waeup/sirp/university/tests/__init__.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/university/tests/__init__.py	(revision 6222)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/university/tests/__init__.py	(revision 6222)
@@ -0,0 +1,1 @@
+# Make this a package.
Index: /main/waeup.sirp/trunk/src/waeup/sirp/university/tests/test_certificatecontainer.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/university/tests/test_certificatecontainer.py	(revision 6222)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/university/tests/test_certificatecontainer.py	(revision 6222)
@@ -0,0 +1,118 @@
+##
+## test_certificatecontainer.py
+## Login : <uli@pu.smp.net>
+## Started on  Sun May 29 02:21:16 2011 Uli Fouquet
+## $Id$
+## 
+## Copyright (C) 2011 Uli Fouquet
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+"""
+Tests for certificate containers and related components.
+"""
+import shutil
+import tempfile
+import os
+import unittest
+from zope.interface.verify import verifyClass, verifyObject
+from waeup.sirp.testing import FunctionalLayer, WAeUPSIRPUnitTestLayer
+from waeup.sirp.university.certificate import Certificate
+from waeup.sirp.university.interfaces import (
+    ICertificateContainer, )
+from waeup.sirp.university.certificatecontainer import CertificateContainer
+from zope.catalog.tests import PlacelessSetup
+from zope.app.testing.functional import FunctionalTestCase
+from zope.component.hooks import setSite, clearSite
+from waeup.sirp.app import University
+
+class CertificateContainerTests(FunctionalTestCase):
+
+    layer = FunctionalLayer
+
+    def setUp(self):
+        super(CertificateContainerTests, self).setUp()
+
+        # Setup a sample site for each test
+        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']
+        setSite(self.app)
+
+    def tearDown(self):
+        super(CertificateContainerTests, self).tearDown()
+        clearSite()
+        shutil.rmtree(self.dc_root)
+
+    def test_create(self):
+        # we can create instances
+        container = CertificateContainer()
+        result = isinstance(container, CertificateContainer)
+        assert result is True
+
+    def test_provides_icertificatecontainer(self):
+        # instances tell they provide their main interface
+        container = CertificateContainer()
+        result = ICertificateContainer.providedBy(container)
+        assert result is True
+
+    def test_interfaces(self):
+        # class and instances comply with their main interface
+        container = CertificateContainer()
+        result1 = verifyClass(ICertificateContainer, CertificateContainer)
+        result2 = verifyObject(ICertificateContainer, container)
+
+    def test_add_certificate_non_icertificate(self):
+        # we cannot add certificates that do not implement ICertificate.
+        container = CertificateContainer()
+        self.assertRaises(
+            TypeError, container.addCertificate, 'some_string')
+
+    def test_add_certificate_no_duplicate_entry(self):
+        # we cannot add certificates that are registered already.
+        container = CertificateContainer()
+        # We must place this container in the ZODB to make catalogs work.
+        self.app['certs'] = container
+        cert1 = Certificate(code="CERT1")
+        cert2 = Certificate(code="CERT1")
+        container.addCertificate(cert1)
+        self.assertRaises(
+            ValueError,
+            container.addCertificate, cert2)
+
+    def test_setitem_duplicate_entry(self):
+        # we cannot add certificates whose code exists already in catalog
+        container = CertificateContainer()
+        self.app['certs'] = container # enable catalogs
+        cert1 = Certificate(code="CERT1")
+        cert2 = Certificate(code="CERT1")
+        self.app['certs']['SomeKey'] = cert1
+        self.assertRaises(
+            ValueError,
+            container.__setitem__, 'OtherKey', cert2)
+        assert len(container) == 1
+
+
+def test_suite():
+
+    return unittest.TestSuite((
+        unittest.makeSuite(CertificateContainerTests),
+        ))
+
+if __name__=='__main__':
+    unittest.main(defaultTest='test_suite')
