[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/exception/browser/tests/test_unauthorized.py Fixed unit tests after we broke them earlier.

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Oct 12 14:11:45 EDT 2004


Log message for revision 28024:
  Fixed unit tests after we broke them earlier.
  


Changed:
  U   Zope3/trunk/src/zope/app/exception/browser/tests/test_unauthorized.py


-=-
Modified: Zope3/trunk/src/zope/app/exception/browser/tests/test_unauthorized.py
===================================================================
--- Zope3/trunk/src/zope/app/exception/browser/tests/test_unauthorized.py	2004-10-12 18:11:29 UTC (rev 28023)
+++ Zope3/trunk/src/zope/app/exception/browser/tests/test_unauthorized.py	2004-10-12 18:11:44 UTC (rev 28024)
@@ -18,6 +18,7 @@
 from unittest import TestCase, main, makeSuite
 from zope.interface import implements
 from zope.publisher.browser import TestRequest
+from zope.app import zapi
 from zope.app.security.interfaces import IAuthenticationService, IPrincipal
 from zope.app.container.contained import contained
 from zope.app.exception.browser.unauthorized import Unauthorized
@@ -47,11 +48,22 @@
         self.principal_id = principal_id
         self.request = request
 
+
 class DummyPrincipalSource(object):
     pass
 
 class Test(TestCase, PlacelessSetup):
 
+    def setUp(self):
+        super(Test, self).setUp()
+        self.temp = zapi.getService
+        self.authservice = DummyAuthService()
+        zapi.getService = lambda name: self.authservice
+
+    def tearDown(self):
+        zapi.getService = self.temp
+        super(Test, self).tearDown()
+
     def test(self):
         exception = Exception()
         try:
@@ -59,8 +71,7 @@
         except:
             pass
         request = TestRequest('/')
-        authservice = DummyAuthService()
-        request.setPrincipal(contained(DummyPrincipal(23), authservice))
+        request.setPrincipal(DummyPrincipal(23))
         u = Unauthorized(exception, request)
         u.issueChallenge()
 
@@ -68,8 +79,8 @@
         self.assertEqual(request.response.getStatus(), 403)
 
         # Make sure the auth service was called
-        self.failUnless(authservice.request is request)
-        self.assertEqual(authservice.principal_id, 23)
+        self.failUnless(self.authservice.request is request)
+        self.assertEqual(self.authservice.principal_id, 23)
 
     def testPluggableAuthService(self):
         exception = Exception()
@@ -78,10 +89,8 @@
         except:
             pass
         request = TestRequest('/')
-        authservice = DummyAuthService()
         psrc = DummyPrincipalSource()
-        psrc = contained(psrc, authservice)
-        request.setPrincipal(contained(DummyPrincipal(23), psrc))
+        request.setPrincipal(DummyPrincipal(23))
         u = Unauthorized(exception, request)
         u.issueChallenge()
 
@@ -89,8 +98,8 @@
         self.assertEqual(request.response.getStatus(), 403)
 
         # Make sure the auth service was called
-        self.failUnless(authservice.request is request)
-        self.assertEqual(authservice.principal_id, 23)
+        self.failUnless(self.authservice.request is request)
+        self.assertEqual(self.authservice.principal_id, 23)
 
 def test_suite():
     return makeSuite(Test)



More information about the Zope3-Checkins mailing list