[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_auth.py:1.3

R. David Murray bitz@bitdance.com
Thu, 26 Dec 2002 18:21:48 -0500


Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv21705/src/zope/app/services/tests

Modified Files:
	test_auth.py 
Log Message:
Improve the efficiency of the basic persistent auth source.  Instead of
a BTreeContainer, use two BTrees, one mapping from ids to Users,
and one from login to Users.  This eliminates the need to look at
every User when looking up the user at login time.  Also standarize
the implementation of the helper method getPrincipalByLogin to raise
an error (NotFoundError) when the login isn't found, and provide
the corresponding query method.  Fix the tests to check for NotFoundError
as per the IAuthenticationService spec for getPrincipal.  Finally,
eliminate the ILocalAuthenticationService interface, since it doesn't
seem to add anything we need.  XXX the IContainer implementation is
not fully unit tested, since the BaseTestIContainer tests need to be
refactored first to facilitate it.


=== Zope3/src/zope/app/services/tests/test_auth.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/services/tests/test_auth.py:1.2	Wed Dec 25 09:13:20 2002
+++ Zope3/src/zope/app/services/tests/test_auth.py	Thu Dec 26 18:21:47 2002
@@ -23,8 +23,9 @@
 
 from zope.exceptions import NotFoundError
 from zope.publisher.interfaces.http import IHTTPCredentials
-from zope.app.services.tests.placefulsetup \
-           import PlacefulSetup
+from zope.app.services.tests.placefulsetup import PlacefulSetup
+
+from zope.app.container.tests.test_icontainer import BaseTestIContainer
 
 class Request:
 
@@ -98,14 +99,25 @@
     def testGetPrincipal(self):
         auth = self._auth
         self.assertEqual(auth['srichter'], auth.getPrincipal('srichter'))
-        self.assertEqual(None, auth.getPrincipal('srichter2'))
+        self.assertRaises(NotFoundError, auth.getPrincipal, 'srichter2')
 
     def testGetPrincipals(self):
         auth = self._auth
         self.assertEqual([auth['srichter']], auth.getPrincipals('srichter'))
 
+
+class TestAuthAsIContainer(BaseTestIContainer, TestCase):
+
+    def _Test__new(self):
+        return AuthenticationService()
+
+
 def test_suite():
-    return makeSuite(AuthServiceTest)
+    t1 = makeSuite(AuthServiceTest)
+    #XXX Need to fix IContainer to get the object list from subclass
+    #t2 = makeSuite(TestAuthAsIContainer)
+    #return TestSuite((t1, t2))
+    return TestSuite((t1,))
 
 if __name__=='__main__':
     main(defaultTest='test_suite')