[Zope3-checkins] CVS: Zope3/src/zope/modulealias/tests -
__init__.py:1.2 dummymodule.py:1.2 test_modulealias.py:1.2
Chris McDonough
chrism at plope.com
Wed Jan 14 17:56:02 EST 2004
Update of /cvs-repository/Zope3/src/zope/modulealias/tests
In directory cvs.zope.org:/tmp/cvs-serv5558/src/zope/modulealias/tests
Added Files:
__init__.py dummymodule.py test_modulealias.py
Log Message:
Merge security policy refactoring:
- Moved all role- and grant-related functionality into
zope.products.securitypolicy (and out of zope.app.security.grant).
The zope.products.securitypolicy implementation is exactly
the same as the old implementation; no changes were made
to the actual mechanics of role-permission or principal-permission
grants. The only real difference is that all functionality
that is the purview of what we want a security policy to have
control of is now in that one place.
- Created new modulealias directive which can be used to provide
aliases to older modules (to not break existing ZODBs when
module locations change).
- Added minor feature: "make debug" launches a debug session in the
spirit of Zope 2's "zopectl debug".
=== Zope3/src/zope/modulealias/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null Wed Jan 14 17:56:02 2004
+++ Zope3/src/zope/modulealias/tests/__init__.py Wed Jan 14 17:55:31 2004
@@ -0,0 +1 @@
+# A package
=== Zope3/src/zope/modulealias/tests/dummymodule.py 1.1 => 1.2 ===
--- /dev/null Wed Jan 14 17:56:02 2004
+++ Zope3/src/zope/modulealias/tests/dummymodule.py Wed Jan 14 17:55:31 2004
@@ -0,0 +1 @@
+# dummy module for testing.
=== Zope3/src/zope/modulealias/tests/test_modulealias.py 1.1 => 1.2 ===
--- /dev/null Wed Jan 14 17:56:02 2004
+++ Zope3/src/zope/modulealias/tests/test_modulealias.py Wed Jan 14 17:55:31 2004
@@ -0,0 +1,89 @@
+import unittest
+import sys
+from zope.configuration import xmlconfig
+from zope.configuration.config import ConfigurationContext
+# math is imported as an example module to test with
+import math
+
+stuff = """
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="zope"
+ >
+
+ <include package="zope.modulealias" file="meta.zcml"/>
+
+ <modulealias module="unittest" alias="unittest_alias"/>
+
+</configure>
+"""
+
+
+class Test(unittest.TestCase):
+ def setUp(self):
+ self.keys = sys.modules.keys()
+
+ def tearDown(self):
+ keys = sys.modules.keys()
+ for key in keys:
+ if key not in self.keys:
+ del sys.modules[key]
+
+ def test_definemodulealias(self):
+ context = ConfigurationContext()
+ from zope.modulealias.metaconfigure import alias_module
+ alias_module(module='unittest', alias='unittest_alias',
+ context=context)
+ self.assert_('unittest_alias' in sys.modules.keys())
+ self.assertEqual(sys.modules['unittest_alias'],sys.modules['unittest'])
+
+ def test_cantoverride(self):
+ context = ConfigurationContext()
+ from zope.modulealias.metaconfigure import alias_module
+ from zope.modulealias.metaconfigure import ModuleAliasException
+ self.assertRaises(ModuleAliasException, alias_module,
+ module='unittest', alias='zope.modulealias.tests',
+ context=context)
+
+ def test_samemodule_doesntfail(self):
+ context = ConfigurationContext()
+ from zope.modulealias.metaconfigure import alias_module
+ self.assert_('math' in sys.modules)
+ sys.modules['zope.modulealias.tests.test_modulealias.math'] = math
+ alias_module(module='zope.modulealias.tests.test_modulealias.math',
+ alias='math',
+ context=context)
+
+ def test_module_not_imported(self):
+ context = ConfigurationContext()
+ from zope.modulealias.metaconfigure import alias_module
+ m1 = 'zope.modulealias.tests.dummymodule'
+ m2 = 'zope.modulealias.tests.dummymodule2'
+ self.assert_(m1 not in sys.modules)
+ alias_module(module=m1, alias=m2, context=context)
+ self.assert_(m1 in sys.modules)
+ self.assert_(sys.modules[m1] is sys.modules[m2])
+
+ def test_nonmodule_alias(self):
+ from zope.modulealias.metaconfigure import ModuleAliasException
+ context = ConfigurationContext()
+ from zope.modulealias.metaconfigure import alias_module
+ m1 = 'zope.modulealias.tests.test_modulealias.Test'
+ m2 = 'zope.modulealias.tests.test_modulealias.Test2'
+ self.assertRaises(ModuleAliasException,
+ alias_module, module=m1, alias=m2, context=context,
+ )
+
+ def test_zcml(self):
+ context = xmlconfig.string(stuff)
+ self.assert_('unittest_alias' in sys.modules.keys())
+ self.assertEqual(sys.modules['unittest_alias'],sys.modules['unittest'])
+
+
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
More information about the Zope3-Checkins
mailing list