[Zope3-checkins] SVN: Zope3/branches/mgedmin-security/src/zope/app/ Changed unit tests to use newInteraction instead of newSecurityManager.

Marius Gedminas marius at pov.lt
Wed May 12 17:33:47 EDT 2004


Log message for revision 24613:
Changed unit tests to use newInteraction instead of newSecurityManager.




-=-
Modified: Zope3/branches/mgedmin-security/src/zope/app/component/tests/test_contentdirective.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/component/tests/test_contentdirective.py	2004-05-12 21:18:14 UTC (rev 24612)
+++ Zope3/branches/mgedmin-security/src/zope/app/component/tests/test_contentdirective.py	2004-05-12 21:33:46 UTC (rev 24613)
@@ -26,7 +26,8 @@
 from zope.component.exceptions import ComponentLookupError
 from zope.configuration.xmlconfig import xmlconfig, XMLConfig
 from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.security.management import newSecurityManager, system_user
+from zope.security.management import system_user
+from zope.security.management import newInteraction
 from zope.app.component.interface import queryInterface
 
 # explicitly import ExampleClass and IExample using full paths
@@ -35,6 +36,13 @@
 from zope.app.component.tests.exampleclass import IExample, IExample2
 
 
+class ParticipationStub:
+
+    def __init__(self, principal):
+        self.principal = principal
+        self.interaction = None
+
+
 def configfile(s):
     return StringIO("""<configure
       xmlns='http://namespaces.zope.org/zope'
@@ -46,7 +54,7 @@
 class TestContentDirective(PlacelessSetup, unittest.TestCase):
     def setUp(self):
         super(TestContentDirective, self).setUp()
-        newSecurityManager(system_user)
+        newInteraction(ParticipationStub(system_user))
         XMLConfig('meta.zcml', zope.app.component)()
         XMLConfig('meta.zcml', zope.app.security)()
 
@@ -64,7 +72,7 @@
 
 
     def testImplements(self):
-        self.assertEqual(queryInterface( 
+        self.assertEqual(queryInterface(
             "zope.app.component.tests.exampleclass.IExample"), None)
 
         f = configfile("""
@@ -75,7 +83,7 @@
         xmlconfig(f)
         self.failUnless(IExample.implementedBy(ExampleClass))
 
-        self.assertEqual(queryInterface( 
+        self.assertEqual(queryInterface(
             "zope.app.component.tests.exampleclass.IExample"), IExample)
 
 
@@ -133,7 +141,7 @@
 class TestFactorySubdirective(PlacelessSetup, unittest.TestCase):
     def setUp(self):
         super(TestFactorySubdirective, self).setUp()
-        newSecurityManager(system_user)
+        newInteraction(ParticipationStub(system_user))
         XMLConfig('meta.zcml', zope.app.component)()
         XMLConfig('meta.zcml', zope.app.security)()
 

Modified: Zope3/branches/mgedmin-security/src/zope/app/component/tests/test_factory.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/component/tests/test_factory.py	2004-05-12 21:18:14 UTC (rev 24612)
+++ Zope3/branches/mgedmin-security/src/zope/app/component/tests/test_factory.py	2004-05-12 21:33:46 UTC (rev 24613)
@@ -23,7 +23,7 @@
 from zope.component import createObject
 from zope.proxy import removeAllProxies
 from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.security.management import newSecurityManager, system_user
+from zope.security.management import newInteraction, system_user
 
 from zope.app import zapi
 import zope.app.security
@@ -31,6 +31,14 @@
 
 from zope.app.component.tests.exampleclass import ExampleClass
 
+
+class ParticipationStub:
+
+    def __init__(self, principal):
+        self.principal = principal
+        self.interaction = None
+
+
 def configfile(s):
     return StringIO("""<configure
       xmlns='http://namespaces.zope.org/zope'
@@ -42,7 +50,7 @@
 class Test(PlacelessSetup, unittest.TestCase):
     def setUp(self):
         super(Test, self).setUp()
-        newSecurityManager(system_user)
+        newInteraction(ParticipationStub(system_user))
         XMLConfig('meta.zcml', zope.app.component)()
         XMLConfig('meta.zcml', zope.app.security)()
 

Modified: Zope3/branches/mgedmin-security/src/zope/app/component/tests/test_servicedirective.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/component/tests/test_servicedirective.py	2004-05-12 21:18:14 UTC (rev 24612)
+++ Zope3/branches/mgedmin-security/src/zope/app/component/tests/test_servicedirective.py	2004-05-12 21:33:46 UTC (rev 24613)
@@ -29,6 +29,14 @@
 from zope.component import getService
 from zope.app.tests.placelesssetup import PlacelessSetup
 
+
+class ParticipationStub:
+
+    def __init__(self, principal):
+        self.principal = principal
+        self.interaction = None
+
+
 template = """<configure
    xmlns='http://namespaces.zope.org/zope'
    xmlns:test='http://www.zope.org/NS/Zope3/test'
@@ -180,8 +188,8 @@
 
 
         # Need to "log someone in" to turn on checks
-        from zope.security.management import newSecurityManager
-        newSecurityManager('someuser')
+        from zope.security.management import newInteraction
+        newInteraction(ParticipationStub('someuser'))
 
         service = getService(None, "Foo")
         service = ProxyFactory(service) # simulate untrusted code!
@@ -191,9 +199,9 @@
         self.assertRaises(Forbidden, getattr, service, 'bar')
 
 
-
 def test_suite():
     loader=unittest.TestLoader()
     return loader.loadTestsFromTestCase(Test)
+
 if __name__=='__main__':
     unittest.TextTestRunner().run(test_suite())

Modified: Zope3/branches/mgedmin-security/src/zope/app/menu/browser/tests.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/menu/browser/tests.py	2004-05-12 21:18:14 UTC (rev 24612)
+++ Zope3/branches/mgedmin-security/src/zope/app/menu/browser/tests.py	2004-05-12 21:33:46 UTC (rev 24613)
@@ -20,7 +20,7 @@
 from zope.interface import Interface, implements
 from zope.component import getServiceManager
 
-from zope.security.management import newSecurityManager
+from zope.security.management import newInteraction
 from zope.security.checker import defineChecker, NamesChecker, CheckerPublic
 from zope.security.proxy import ProxyFactory
 
@@ -71,7 +71,13 @@
     def __call__(self):
         pass
 
+class ParticipationStub:
 
+    def __init__(self, principal):
+        self.principal = principal
+        self.interaction = None
+
+
 class Test(PlacefulSetup, unittest.TestCase):
 
     def setUp(self):
@@ -89,7 +95,7 @@
                                       abad='waaa'))
 
     def test(self):
-        newSecurityManager('who')
+        newInteraction(ParticipationStub('who'))
         v = MenuAccessView(ProxyFactory(ob), TestRequest())
         self.assertEqual(v['zmi_views'],
                          [{'description': '', 'title':'l1', 'action':'a1'},

Modified: Zope3/branches/mgedmin-security/src/zope/app/publisher/browser/tests/test_directives.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/publisher/browser/tests/test_directives.py	2004-05-12 21:18:14 UTC (rev 24612)
+++ Zope3/branches/mgedmin-security/src/zope/app/publisher/browser/tests/test_directives.py	2004-05-12 21:33:46 UTC (rev 24613)
@@ -706,8 +706,8 @@
 
         # XXX this seems to be no longer needed
         # Need to "log someone in" to turn on checks
-        #from zope.security.management import newSecurityManager
-        #newSecurityManager('someuser')
+        #from zope.security.management import newInteraction
+        #newInteraction(ParticipationStub('someuser'))
 
         view = getView(ob, 'test', request)
         self.assertEqual(view.browserDefault(request)[1], (u'index.html', ))
@@ -873,8 +873,8 @@
 
         # XXX This seems to be no longer needed
         # Need to "log someone in" to turn on checks
-        #from zope.security.management import newSecurityManager
-        #newSecurityManager('someuser')
+        #from zope.security.management import newInteraction
+        #newInteraction(ParticipationStub('someuser'))
 
         v = getView(ob, 'xxx.html', request)
         v = ProxyFactory(v)

Modified: Zope3/branches/mgedmin-security/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py	2004-05-12 21:18:14 UTC (rev 24612)
+++ Zope3/branches/mgedmin-security/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py	2004-05-12 21:33:46 UTC (rev 24613)
@@ -20,7 +20,8 @@
 from zope.interface import Interface, implements
 from zope.publisher.browser import TestRequest
 from zope.publisher.interfaces.browser import IBrowserPublisher
-from zope.security.management import newSecurityManager, system_user
+from zope.security.management import newInteraction, endInteraction
+from zope.security.management import system_user
 
 from zope.app import zapi
 from zope.app.tests import ztapi
@@ -61,6 +62,13 @@
             }
 
 
+class ParticipationStub:
+
+    def __init__(self, principal):
+        self.principal = principal
+        self.interaction = None
+
+
 class GlobalBrowserMenuServiceTest(PlacelessSetup, unittest.TestCase):
 
     def __reg(self):
@@ -89,7 +97,7 @@
 
     def test_w_permission(self):
         ztapi.provideUtility(IPermission, Permission('p', 'P'), 'p')
-        
+
         r = self.__reg()
         r.menu('test_id', 'test menu')
         r.menuItem('test_id', Interface, 'a1', 't1', 'd1')
@@ -102,17 +110,18 @@
         r.menuItem('test_id', I111, 'u8', 't8', 'd8')
         r.menuItem('test_id', I12, 'a9', 't9', 'd9')
 
-        newSecurityManager('test')
+        newInteraction(ParticipationStub('test'))
 
         menu = r.getMenu('test_id', TestObject(), TestRequest())
 
         self.assertEqual(list(menu), [d(6), d(3), d(2), d(1)])
 
-        newSecurityManager(system_user)
+        endInteraction()
 
+        newInteraction(ParticipationStub(system_user))
+
         menu = r.getMenu('test_id', TestObject(), TestRequest())
         self.assertEqual(list(menu), [d(5), d(6), d(3), d(2), d(1)])
-        
 
     def test_no_dups(self):
         r = self.__reg()

Modified: Zope3/branches/mgedmin-security/src/zope/app/schema/tests/test_field.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/schema/tests/test_field.py	2004-05-12 21:18:14 UTC (rev 24612)
+++ Zope3/branches/mgedmin-security/src/zope/app/schema/tests/test_field.py	2004-05-12 21:33:46 UTC (rev 24613)
@@ -22,12 +22,20 @@
 from zope.configuration import xmlconfig
 from zope.schema import Text, getFieldsInOrder
 from zope.security.checker import ProxyFactory
-from zope.security.management import system_user, newSecurityManager
+from zope.security.management import system_user, newInteraction
 from zope.app.tests import setup
 from zope.app.schema.wrapper import Struct
 from zope.security.checker import getChecker, _defaultChecker
 import zope.app.schema.tests
 
+
+class ParticipationStub:
+
+    def __init__(self, principal):
+        self.principal = principal
+        self.interaction = None
+
+
 class FieldPersistence(unittest.TestCase):
 
     def test_field_change(self):
@@ -46,7 +54,7 @@
     def setUp(self):
         setup.placefulSetUp()
         self.context = xmlconfig.file("fields.zcml", zope.app.schema.tests)
-        newSecurityManager(system_user)
+        newInteraction(ParticipationStub(system_user))
 
     def test_wrapped_field_checker(self):
         f1 = Text(title=u'alpha')

Modified: Zope3/branches/mgedmin-security/src/zope/app/schema/tests/test_fieldfactory.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/schema/tests/test_fieldfactory.py	2004-05-12 21:18:14 UTC (rev 24612)
+++ Zope3/branches/mgedmin-security/src/zope/app/schema/tests/test_fieldfactory.py	2004-05-12 21:33:46 UTC (rev 24613)
@@ -23,18 +23,25 @@
 from zope.component.exceptions import ComponentLookupError
 from zope.component.interfaces import IFactory
 from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.security.management import newSecurityManager, system_user
+from zope.security.management import newInteraction, system_user
 from zope.schema.interfaces import IField, IText
 from zope.interface import Interface
 from zope.configuration import xmlconfig
 
+
+class ParticipationStub:
+
+    def __init__(self, principal):
+        self.principal = principal
+        self.interaction = None
+
 class IFoo(Interface): pass
 
 class TestFieldFactory(PlacelessSetup, unittest.TestCase):
 
     def setUp(self):
         super(TestFieldFactory, self).setUp()
-        newSecurityManager(system_user)
+        newInteraction(ParticipationStub(system_user))
         context = xmlconfig.file('tests/test_fieldfactory.zcml',
                                  zope.app.schema)
 

Modified: Zope3/branches/mgedmin-security/src/zope/app/schema/tests/test_schemautility.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/schema/tests/test_schemautility.py	2004-05-12 21:18:14 UTC (rev 24612)
+++ Zope3/branches/mgedmin-security/src/zope/app/schema/tests/test_schemautility.py	2004-05-12 21:33:46 UTC (rev 24613)
@@ -18,13 +18,20 @@
 
 from zope.configuration import xmlconfig
 from zope.schema import Text, getFieldNamesInOrder, getFieldsInOrder
-from zope.security.management import system_user, newSecurityManager
+from zope.security.management import system_user, newInteraction
 from zope.security.checker import getChecker, _defaultChecker, ProxyFactory
 from zope.app.schema.schema import SchemaUtility
 from zope.app.tests import setup
 from zope.app import zapi
 import zope.app.schema.tests
 
+class ParticipationStub:
+
+    def __init__(self, principal):
+        self.principal = principal
+        self.interaction = None
+
+
 class SchemaUtilityTests(TestCase):
 
     def _createSchemaUtility(self):
@@ -182,7 +189,7 @@
         s = self.s
         s.addField(u'alpha', self.alpha)
         s = ProxyFactory(s)
-        newSecurityManager(system_user)
+        newInteraction(ParticipationStub(system_user))
         f1 = ProxyFactory(s[u'alpha'])
         order = f1.order
         f1 = zapi.traverse(s, 'alpha')

Modified: Zope3/branches/mgedmin-security/src/zope/app/traversing/tests/test_traverser.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/traversing/tests/test_traverser.py	2004-05-12 21:18:14 UTC (rev 24612)
+++ Zope3/branches/mgedmin-security/src/zope/app/traversing/tests/test_traverser.py	2004-05-12 21:33:46 UTC (rev 24613)
@@ -39,9 +39,15 @@
 from zope.app.site.tests.placefulsetup import PlacefulSetup
 from zope.security.checker \
     import ProxyFactory, defineChecker, CheckerPublic, Checker
-from zope.security.management import newSecurityManager
+from zope.security.management import newInteraction
 from zope.app.container.contained import Contained, contained
 
+class ParticipationStub:
+
+    def __init__(self, principal):
+        self.principal = principal
+        self.interaction = None
+
 class C(Contained):
     def __init__(self, name):
         self.name = name
@@ -181,7 +187,7 @@
         self.assertEquals(tr.traverse(('folder', 'item')), item)
 
     def testItemDenied(self):
-        newSecurityManager('no one')
+        newInteraction(ParticipationStub('no one'))
         defineChecker(C, Denied('item'))
         tr = Traverser(ProxyFactory(self.root))
         folder = self.folder




More information about the Zope3-Checkins mailing list