Index: main/waeup.sirp/trunk/src/waeup/sirp/jambtables/tests/test_authentication.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/jambtables/tests/test_authentication.py	(revision 5462)
+++ main/waeup.sirp/trunk/src/waeup/sirp/jambtables/tests/test_authentication.py	(revision 5463)
@@ -22,9 +22,24 @@
 import grok
 import unittest
+#import zope.session.tests.setUp
+#import zope.session.tests.tearDown
+from zope.component import provideAdapter
 from zope.component.hooks import setSite
+from zope.interface import verify
+from zope.pluggableauth.interfaces import  IAuthenticatedPrincipalFactory
+from zope.publisher.browser import TestRequest
+from zope.publisher.interfaces import IRequest
+from zope.session.session import RAMSessionDataContainer
+from zope.session.interfaces import ISession
 from zope.site import LocalSiteManager
 from zope.site.folder import Folder
 from zope.site.testing import siteSetUp, siteTearDown
-from waeup.sirp.jambtables.authentication import ApplicantsAuthenticatorPlugin
+from zope.testing import cleanup
+from waeup.sirp.jambtables.authentication import (
+    ApplicantsAuthenticatorPlugin, WAeUPApplicantCredentialsPlugin,
+    ApplicantCredentials, AuthenticatedApplicantPrincipalFactory,
+    ApplicantPrincipalInfo, ApplicantPrincipal)
+from waeup.sirp.jambtables.interfaces import(
+    IJAMBApplicantSessionCredentials,)
 
 class FakeBatch(dict):
@@ -173,10 +188,158 @@
             dict(accesscode='APP-54321', jambregno='JAMB3'))
         assert result is not None
-        return
-
+
+        # check the `principalInfo` method of authenticator
+        # plugin. This is only here to satisfy the coverage report.
+        assert self.plugin.principalInfo('not-an-id') is None
+        return
+
+session_data = {
+    'zope.pluggableauth.browserplugins': {}
+    }
+
+class FakeSession(dict):
+    def __init__(self, request):
+        pass
+
+    def get(self, key, default=None):
+        return self.__getitem__(key, default)
+    
+    def __getitem__(self, key, default=None):
+        return session_data.get(key, default)
+
+    def __setitem__(self, key, value):
+        session_data[key] = value
+        return
+
+class CredentialsPluginTest(unittest.TestCase):
+
+    def setUp(self):
+        self.request = TestRequest()
+        provideAdapter(FakeSession, (IRequest,), ISession)
+        self.plugin = WAeUPApplicantCredentialsPlugin()
+        self.full_request = TestRequest()
+        session_data['zope.pluggableauth.browserplugins'] = {}
+        return
+
+    def tearDown(self):
+        cleanup.tearDown()
+        return
+
+    def filled_request(self, form_dict):
+        request = TestRequest()
+        for key, value in form_dict.items():
+            request.form[key] = value
+        return request
+
+    def test_extractCredentials_invalid(self):
+        result = self.plugin.extractCredentials('not-a-request')
+        assert result is None
+        return
+
+    def test_extractCredentials_empty(self):
+        result = self.plugin.extractCredentials(self.request)
+        assert result is None
+        return
+
+    def test_extractCredentials_full_set(self):
+        request = self.filled_request({
+                'form.prefix': 'APP',
+                'form.ac_series': '1',
+                'form.ac_number': '1234567890',
+                'form.jamb_reg_no': 'JAMB_NUMBER',
+                })
+        result = self.plugin.extractCredentials(request)
+        self.assertEqual(result, {'jambregno': 'JAMB_NUMBER',
+                                  'accesscode': 'APP-1-1234567890'})
+        return
+
+    def test_extractCredentials_accesscode_only(self):
+        request = self.filled_request({
+                'form.prefix': 'APP',
+                'form.ac_series': '1',
+                'form.ac_number': '1234567890',
+                })
+        result = self.plugin.extractCredentials(request)
+        self.assertEqual(result, {'accesscode': 'APP-1-1234567890'})
+        return
+
+    def test_extractCredentials_from_empty_session(self):
+        session_data['zope.pluggableauth.browserplugins']['credentials'] = None
+        result = self.plugin.extractCredentials(self.request)
+        assert result is None
+        return
+
+    def test_extractCredentials_from_nonempty_session(self):
+        credentials = ApplicantCredentials('APP-1-12345')
+        session_data['zope.pluggableauth.browserplugins'][
+            'credentials'] = credentials
+        result = self.plugin.extractCredentials(self.request)
+        self.assertEqual(result, {'accesscode': 'APP-1-12345'})
+        return
+
+
+class ApplicantCredentialsTest(unittest.TestCase):
+
+    def setUp(self):
+        self.credentials = ApplicantCredentials('SOME_ACCESSCODE')
+        return
+
+    def tearDown(self):
+        return
+
+    def test_methods(self):
+        self.assertEqual(self.credentials.getAccessCode(), 'SOME_ACCESSCODE')
+        assert self.credentials.getLogin() is None
+        assert self.credentials.getPassword() is None
+        return
+
+class FakePluggableAuth(object):
+    prefix = 'foo'
+
+class PrincipalFactoryTest(unittest.TestCase):
+
+    def setUp(self):
+        self.info = ApplicantPrincipalInfo('APP-1-1234567890')
+        return
+
+    def tearDown(self):
+        pass
+
+    def test_principalFactory_interface(self):
+        verify.verifyClass(IAuthenticatedPrincipalFactory,
+                           AuthenticatedApplicantPrincipalFactory
+                           )
+        return
+
+    def test_principalFactory_create(self):
+        factory = AuthenticatedApplicantPrincipalFactory(self.info, None)
+
+        assert factory.info is self.info
+        assert factory.request is None
+        return
+
+    def test_principalFactory_call_w_prefix(self):
+        factory = AuthenticatedApplicantPrincipalFactory(self.info, None)
+        principal = factory(FakePluggableAuth())
+
+        assert isinstance(principal, ApplicantPrincipal)
+        self.assertEqual(principal.__repr__(),
+                         "ApplicantPrincipal('foo.APP-1-1234567890')")
+        self.assertEqual(principal.id, 'foo.APP-1-1234567890')
+        return
+
+    def test_principalFactory_call_wo_prefix(self):
+        factory = AuthenticatedApplicantPrincipalFactory(self.info, None)
+        fake_auth = FakePluggableAuth()
+        fake_auth.prefix = None
+        principal = factory(fake_auth)
+        self.assertEqual(principal.id, 'APP-1-1234567890')
+        return
+        
 def test_suite():
     suite = unittest.TestSuite()
     for testcase in [
-        AuthenticatorPluginTest,
+        AuthenticatorPluginTest, CredentialsPluginTest,
+        ApplicantCredentialsTest, PrincipalFactoryTest,
         ]:
         suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
