[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/xmlrpc/tests - __init__.py:1.2 test.pt:1.2 test_directives.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:14:12 -0500


Update of /cvs-repository/Zope3/src/zope/app/publisher/xmlrpc/tests
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/publisher/xmlrpc/tests

Added Files:
	__init__.py test.pt test_directives.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/publisher/xmlrpc/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:12 2002
+++ Zope3/src/zope/app/publisher/xmlrpc/tests/__init__.py	Wed Dec 25 09:13:11 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/publisher/xmlrpc/tests/test.pt 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:12 2002
+++ Zope3/src/zope/app/publisher/xmlrpc/tests/test.pt	Wed Dec 25 09:13:11 2002
@@ -0,0 +1 @@
+<html><body><p>test</p></body></html>


=== Zope3/src/zope/app/publisher/xmlrpc/tests/test_directives.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:12 2002
+++ Zope3/src/zope/app/publisher/xmlrpc/tests/test_directives.py	Wed Dec 25 09:13:11 2002
@@ -0,0 +1,248 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest
+
+from zope.configuration.xmlconfig import xmlconfig, XMLConfig
+from zope.configuration.exceptions import ConfigurationError
+from zope.component.tests.views import IC, V1, VZMI, R1, RZMI
+from zope.component import getView, queryView
+from zope.component import getDefaultViewName
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.security.proxy import ProxyFactory
+from cStringIO import StringIO
+
+from zope.component.tests.request import Request
+
+from zope.publisher.interfaces.xmlrpc import IXMLRPCPresentation
+
+import zope.app.publisher.xmlrpc
+
+template = """<zopeConfigure
+   xmlns='http://namespaces.zope.org/zope'
+   xmlns:xmlrpc='http://namespaces.zope.org/xmlrpc'>
+   %s
+   </zopeConfigure>"""
+
+request = Request(IXMLRPCPresentation)
+
+class Ob:
+    __implements__ = IC
+
+ob = Ob()
+
+class Test(PlacelessSetup, unittest.TestCase):
+
+    def setUp(self):
+        PlacelessSetup.setUp(self)
+        XMLConfig('meta.zcml', zope.app.publisher.xmlrpc)()
+
+    def testView(self):
+        self.assertEqual(queryView(ob, 'test', request),
+                         None)
+
+        xmlconfig(StringIO(template % (
+            """
+            <xmlrpc:view name="test"
+                  factory="zope.component.tests.views.V1"
+                  for="zope.component.tests.views.IC" />
+            """
+            )))
+
+        self.assertEqual(
+            queryView(ob, 'test', request).__class__,
+            V1)
+
+
+    def testInterfaceProtectedView(self):
+        xmlconfig(StringIO(template %
+            """
+            <xmlrpc:view name="test"
+                  factory="zope.component.tests.views.V1"
+                  for="zope.component.tests.views.IC"
+                  permission="zope.Public"
+              allowed_interface="zope.component.tests.views.IV"
+                  />
+            """
+            ))
+
+        v = getView(ob, 'test', request)
+        v = ProxyFactory(v)
+        self.assertEqual(v.index(), 'V1 here')
+        self.assertRaises(Exception, getattr, v, 'action')
+
+
+    def testAttributeProtectedView(self):
+        xmlconfig(StringIO(template %
+            """
+            <xmlrpc:view name="test"
+                  factory="zope.component.tests.views.V1"
+                  for="zope.component.tests.views.IC"
+                  permission="zope.Public"
+                  allowed_methods="action"
+                  />
+            """
+            ))
+
+        v = getView(ob, 'test', request)
+        v = ProxyFactory(v)
+        self.assertEqual(v.action(), 'done')
+        self.assertRaises(Exception, getattr, v, 'index')
+
+
+    def testInterfaceAndAttributeProtectedView(self):
+        xmlconfig(StringIO(template %
+            """
+            <xmlrpc:view name="test"
+                  factory="zope.component.tests.views.V1"
+                  for="zope.component.tests.views.IC"
+                  permission="zope.Public"
+                  allowed_methods="action"
+              allowed_interface="zope.component.tests.views.IV"
+                  />
+            """
+            ))
+
+        v = getView(ob, 'test', request)
+        self.assertEqual(v.index(), 'V1 here')
+        self.assertEqual(v.action(), 'done')
+
+
+    def testDuplicatedInterfaceAndAttributeProtectedView(self):
+        xmlconfig(StringIO(template %
+            """
+            <xmlrpc:view name="test"
+                  factory="zope.component.tests.views.V1"
+                  for="zope.component.tests.views.IC"
+                  permission="zope.Public"
+                  allowed_methods="action index"
+              allowed_interface="zope.component.tests.views.IV"
+                  />
+            """
+            ))
+
+        v = getView(ob, 'test', request)
+        self.assertEqual(v.index(), 'V1 here')
+        self.assertEqual(v.action(), 'done')
+
+
+    def testIncompleteProtectedViewNoPermission(self):
+        self.assertRaises(
+            ConfigurationError,
+            xmlconfig,
+            StringIO(template %
+            """
+            <xmlrpc:view name="test"
+                  factory="zope.component.tests.views.V1"
+                  for="zope.component.tests.views.IC"
+                  allowed_methods="action index"
+                  />
+            """
+            ))
+
+
+    def testMethodViews(self):
+        self.assertEqual(queryView(ob, 'test', request),
+                         None)
+
+        xmlconfig(StringIO(template %
+            """
+            <xmlrpc:view
+                  factory="zope.component.tests.views.V1"
+                  for="zope.component.tests.views.IC">
+
+                <xmlrpc:method name="index.html" attribute="index" />
+                <xmlrpc:method name="action.html" attribute="action" />
+            </xmlrpc:view>
+            """
+            ))
+
+        v = getView(ob, 'index.html', request)
+        self.assertEqual(v(), 'V1 here')
+        v = getView(ob, 'action.html', request)
+        self.assertEqual(v(), 'done')
+
+
+    def testMethodViewsWithName(self):
+        self.assertEqual(queryView(ob, 'test', request),
+                         None)
+
+        xmlconfig(StringIO(template %
+            """
+            <xmlrpc:view name="test"
+                  factory="zope.component.tests.views.V1"
+                  for="zope.component.tests.views.IC">
+
+                <xmlrpc:method name="index.html" attribute="index" />
+                <xmlrpc:method name="action.html" attribute="action" />
+            </xmlrpc:view>
+            """
+            ))
+
+        v = getView(ob, 'index.html', request)
+        self.assertEqual(v(), 'V1 here')
+        v = getView(ob, 'action.html', request)
+        self.assertEqual(v(), 'done')
+        v = getView(ob, 'test', request)
+        self.assertEqual(v.index(), 'V1 here')
+        self.assertEqual(v.action(), 'done')
+
+
+    def testProtectedMethodViews(self):
+        self.assertEqual(queryView(ob, 'test', request),
+                         None)
+
+        xmlconfig(StringIO(template %
+            """
+            <directives namespace="http://namespaces.zope.org/zope">
+              <directive name="permission"
+                 attributes="id title description"
+                 handler="
+               zope.app.security.registries.metaconfigure.definePermission" />
+            </directives>
+
+            <permission id="XXX" title="xxx" />
+
+            <xmlrpc:view
+                  factory="zope.component.tests.views.V1"
+                  for="zope.component.tests.views.IC"
+                  permission="XXX">
+
+                <xmlrpc:method name="index.html" attribute="index" />
+                <xmlrpc:method name="action.html" attribute="action"
+                              permission="zope.Public" />
+            </xmlrpc:view>
+            """
+            ))
+
+        # Need to "log someone in" to turn on checks
+        from zope.security.securitymanagement import newSecurityManager
+        newSecurityManager('someuser')
+
+        v = getView(ob, 'index.html', request)
+        self.assertRaises(Exception, v)
+        v = getView(ob, 'action.html', request)
+        self.assertEqual(v(), 'done')
+
+
+def test_suite():
+    loader=unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())