Index: /main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_authentication.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_authentication.py	(revision 6122)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_authentication.py	(revision 6123)
@@ -38,8 +38,9 @@
 from waeup.sirp.testing import FunctionalLayer
 from waeup.sirp.app import University
+from waeup.sirp.applicants import  ApplicantsContainer, Applicant
 from waeup.sirp.applicants.authentication import (
     ApplicantsAuthenticatorPlugin, WAeUPApplicantCredentialsPlugin,
     ApplicantCredentials, AuthenticatedApplicantPrincipalFactory,
-    ApplicantPrincipalInfo, ApplicantPrincipal)
+    ApplicantPrincipalInfo, ApplicantPrincipal,)
 
 
@@ -66,15 +67,15 @@
         self['applicants'] = {
             'APP': {
-                'APP-12345': FakeApplication('APP-12345'),
-                'APP-54321': FakeApplication('APP-54321'),
-                'APP-22222': FakeApplication('APP-OTHER'),
+                'APP-12345': FakeApplication(u'APP-12345'),
+                'APP-54321': FakeApplication(u'APP-54321'),
+                'APP-22222': FakeApplication(u'APP-OTHER'),
                 'APP-44444': FakeApplication(),
-                'APP-55555': FakeApplication('APP-OTHER'),
+                'APP-55555': FakeApplication(u'APP-OTHER'),
                 },
             'JAMB': {
                 'JAMB1': FakeApplication(),
-                'JAMB2': FakeApplication('APP-12345'),
-                'JAMB3': FakeApplication('APP-54321'),
-                'JAMB4': FakeApplication('APP-44444'),
+                'JAMB2': FakeApplication(u'APP-12345'),
+                'JAMB3': FakeApplication(u'APP-54321'),
+                'JAMB4': FakeApplication(u'APP-44444'),
                 },
             }
@@ -93,15 +94,77 @@
             }
 
-class AuthenticatorPluginTest(unittest.TestCase):
+def FakeSite():
+    return {
+        'applicants': {
+            'APP': {
+                'APP-12345': FakeApplication(u'APP-12345'),
+                'APP-54321': FakeApplication(u'APP-54321'),
+                'APP-22222': FakeApplication(u'APP-OTHER'),
+                'APP-44444': FakeApplication(),
+                'APP-55555': FakeApplication(u'APP-OTHER'),
+                },
+            'JAMB': {
+                'JAMB1': FakeApplication(),
+                'JAMB2': FakeApplication(u'APP-12345'),
+                'JAMB3': FakeApplication(u'APP-54321'),
+                'JAMB4': FakeApplication(u'APP-44444'),
+                },
+            },
+        'accesscodes': {
+            'APP': FakeBatch({
+                    'APP-12345': FakeAccessCode('APP-12345'),
+                    'APP-54321': FakeAccessCode('APP-54321', True),
+                    'APP-11111': FakeAccessCode('APP-11111'),
+                    'APP-22222': FakeAccessCode('APP-22222'),
+                    'APP-33333': FakeAccessCode('APP-33333', True),
+                    'APP-44444': FakeAccessCode('APP-44444', True),
+                    'APP-55555': FakeAccessCode('APP-55555', True),
+                    'APP-66666': FakeAccessCode('APP-66666', True, False),
+                    'APP-77777': FakeAccessCode('APP-77777', False, False),
+                    })
+            }
+        }
+
+class AuthenticatorPluginTest(FunctionalTestCase):
+
+    layer = FunctionalLayer
+
+    def create_applicant(self, cname, aname, ac=None):
+        # Create an applicant in an applicants container
+        setSite(self.app)
+        if not cname in self.app['applicants'].keys():
+            container = ApplicantsContainer()
+            self.app['applicants'][cname] = container
+        applicant = Applicant()
+        if ac is not None:
+            applicant.access_code = ac
+        self.app['applicants'][cname][aname] = applicant
+        return
 
     def setUp(self):
-        self.app = FakeSite()
-        self.app.setSiteManager(LocalSiteManager(self.app))
+        super(AuthenticatorPluginTest, 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']
+
+        fake_site = FakeSite()
+        for ckey, fake_container in fake_site['applicants'].items():
+            for akey, fake_appl in fake_container.items():
+                self.create_applicant(ckey, akey, fake_appl.access_code)
+        del self.app['accesscodes']
+        self.app['accesscodes'] = fake_site['accesscodes']
+
         self.plugin = ApplicantsAuthenticatorPlugin()
-        setSite(self.app)
         return
 
     def tearDown(self):
-        clearSite()
+        super(AuthenticatorPluginTest, self).tearDown()
+        shutil.rmtree(self.dc_root)
         return
 
@@ -120,4 +183,5 @@
         # Possible cases, where formal correct authentication
         # data is not valid:
+        # XXX: fails
         result = self.plugin.authenticateCredentials(
             dict(accesscode='APP-22222'))
@@ -131,5 +195,5 @@
             dict(accesscode='APP-44444'))
         assert result is None
-        
+
         result = self.plugin.authenticateCredentials(
             dict(accesscode='APP-55555'))
@@ -177,5 +241,5 @@
     def get(self, key, default=None):
         return self.__getitem__(key, default)
-    
+
     def __getitem__(self, key, default=None):
         return session_data.get(key, default)
@@ -317,7 +381,7 @@
     # credentials plugin) to be registered with the local PAU. Admins
     # can remove these components on the fly later-on if they wish.
-    
+
     layer = FunctionalLayer
-    
+
     def setUp(self):
         super(PAUSetupTest, self).setUp()
@@ -348,5 +412,5 @@
         cred_names = [name for name, plugin in cred_plugins]
         auth_names = [name for name, plugin in auth_plugins]
-        
+
         # Make sure our local ApplicantsAuthenticatorPlugin is registered...
         self.assertTrue('applicants' in auth_names)
