[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/component/browser/ Addressed issue 475 by reactivating the tests and updating them to the new

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Nov 16 18:37:26 EST 2005


Log message for revision 40187:
  Addressed issue 475 by reactivating the tests and updating them to the new 
  API.
  

Changed:
  U   Zope3/trunk/src/zope/app/component/browser/configure.zcml
  U   Zope3/trunk/src/zope/app/component/browser/registration.py
  A   Zope3/trunk/src/zope/app/component/browser/tests/test_directives.py
  A   Zope3/trunk/src/zope/app/component/browser/tests/test_editregistration.py
  A   Zope3/trunk/src/zope/app/component/browser/tests/test_registrationview.py
  D   Zope3/trunk/src/zope/app/component/browser/xxx_tests/

-=-
Modified: Zope3/trunk/src/zope/app/component/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/component/browser/configure.zcml	2005-11-16 23:13:23 UTC (rev 40186)
+++ Zope3/trunk/src/zope/app/component/browser/configure.zcml	2005-11-16 23:37:25 UTC (rev 40187)
@@ -44,7 +44,7 @@
       />
 
   <page
-      name="index.html" 
+      name="index.html"
       for="zope.app.component.interfaces.registration.IRegistrationManager"
       menu="zmi_views" title="Registration"
       permission="zope.ManageSite"
@@ -105,9 +105,9 @@
 
   <page
       for="zope.app.component.interfaces.ISiteManagementFolder"
-      permission="zope.ManageSite" 
+      permission="zope.ManageSite"
       class="zope.app.container.browser.contents.JustContents"
-      name="index.html" attribute="index" 
+      name="index.html" attribute="index"
       />
 
   <page
@@ -116,7 +116,7 @@
       menu="zmi_views" title="Contents"
       permission="zope.ManageSite"
       class="zope.app.container.browser.contents.Contents"
-      attribute="contents" 
+      attribute="contents"
       />
 
   <view
@@ -183,7 +183,7 @@
       menu="zmi_actions" title="Add Site Management Folder"
       for="zope.app.component.interfaces.ILocalSiteManager"
       permission="zope.ManageSite"
-      class="zope.app.container.browser.adding.Adding" 
+      class="zope.app.container.browser.adding.Adding"
       >
     <page name="index.html" attribute="index"/>
     <page name="action.html" attribute="action"/>
@@ -225,8 +225,8 @@
       arguments="name provided component"
       fields="name provided component status permission"
       >
-    <widget 
-        field="name" 
+    <widget
+        field="name"
         class="zope.app.form.browser.TextWidget"
         required="False"
         convert_missing_value="False"
@@ -264,7 +264,7 @@
       arguments="required provided factoryName"
       keyword_arguments="name permission"
       permission="zope.ManageServices"
-      fields="required provided name permission factoryName" 
+      fields="required provided name permission factoryName"
       menu="add_registration" title="Adapter Registration"
       /-->
 

Modified: Zope3/trunk/src/zope/app/component/browser/registration.py
===================================================================
--- Zope3/trunk/src/zope/app/component/browser/registration.py	2005-11-16 23:13:23 UTC (rev 40186)
+++ Zope3/trunk/src/zope/app/component/browser/registration.py	2005-11-16 23:37:25 UTC (rev 40187)
@@ -85,68 +85,6 @@
             for reg in registered.registrations()]
 
 
-class ChangeRegistrations(BrowserView):
-
-    _prefix = 'registrations'
-    name = _prefix + ".active"
-    message = ''
-    configBase = ''
-
-    def setPrefix(self, prefix):
-        self._prefix = prefix
-        self.name = prefix + ".active"
-
-    def applyUpdates(self):
-        message = ''
-        if 'submit_update' in self.request.form:
-            id = self.request.form.get(self.name)
-            if id == "disable":
-                active = self.context.active()
-                if active is not None:
-                    self.context.activate(None)
-                    message = _("Disabled")
-            else:
-                for info in self.context.info():
-                    infoid = zapi.getPath(info['registration'])
-                    if infoid == id and not info['active']:
-                        self.context.activate(info['registration'])
-                        message = _("Updated")
-                        break
-
-        return message
-
-    def update(self):
-        message = self.applyUpdates()
-
-        self.configBase = zapi.absoluteURL(zapi.getSiteManager(), self.request)
-
-        registrations = self.context.info()
-
-        # This is OK because registrations is just a list of dicts
-        registrations = removeSecurityProxy(registrations)
-
-        inactive = 1
-        for info in registrations:
-            if info['active']:
-                inactive = None
-            else:
-                info['active'] = False
-
-            reg = info['registration']
-            info['summary'] = reg.implementationSummary()
-            info['id'] = zapi.getPath(reg)
-
-        # Add a dummy registration since the stack removes trailing None.
-        registrations.append({"active": False,
-                              "id": "disable",
-                              "summary": ""})
-
-        self.inactive = inactive
-        self.registrations = registrations
-
-        self.message = message
-
-
 #############################################################################
 # BBB: Only for backward compatibility. 12/07/2004
 class ComponentPathWidget(SimpleInputWidget):

Copied: Zope3/trunk/src/zope/app/component/browser/tests/test_directives.py (from rev 40163, Zope3/trunk/src/zope/app/component/browser/xxx_tests/test_directives.py)
===================================================================
--- Zope3/trunk/src/zope/app/component/browser/xxx_tests/test_directives.py	2005-11-16 17:16:26 UTC (rev 40163)
+++ Zope3/trunk/src/zope/app/component/browser/tests/test_directives.py	2005-11-16 23:37:25 UTC (rev 40187)
@@ -0,0 +1,70 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Directives Tests
+
+$Id$
+"""
+import unittest
+from zope.interface import Interface
+from zope.testing.doctestunit import DocTestSuite
+
+from zope.app.testing.placelesssetup import setUp, tearDown
+
+class FauxContext(object):
+    def __init__(self):
+        self.actions = []
+        self.info = 'info'
+
+    def action(self, **kw):
+        self.actions.append(kw)
+
+class IDummyUtility(Interface):
+    """Represents a dummy utility."""
+
+def test_toolDirective():
+    r"""
+    >>> from zope.app.component.browser import metaconfigure
+    >>> context = FauxContext()
+    >>> metaconfigure.tool(context, IDummyUtility, folder="dummy",
+    ...                    title="dummy", description="the description")
+
+    >>> iface = context.actions[0]
+    >>> iface['discriminator']
+
+    >>> iface['callable'].__module__
+    'zope.app.component.interface'
+
+    >>> iface['args'][1].getName()
+    'IDummyUtility'
+
+    >>> iface['args'][2].getName()
+    'IToolType'
+
+    >>> tool = context.actions[1]
+    >>> from pprint import pprint
+    >>> pprint([n for n in tool['discriminator']])
+    ['utility',
+     <InterfaceClass zope.app.component.browser.tools.IToolConfiguration>,
+     'IDummyUtility']
+
+    >>> tool['callable'].__module__
+    'zope.app.component.metaconfigure'
+    """
+
+def test_suite():
+    return unittest.TestSuite((
+        DocTestSuite(setUp=setUp, tearDown=tearDown),
+        ))
+
+if __name__ == '__main__': unittest.main()

Copied: Zope3/trunk/src/zope/app/component/browser/tests/test_editregistration.py (from rev 40163, Zope3/trunk/src/zope/app/component/browser/xxx_tests/test_editregistration.py)
===================================================================
--- Zope3/trunk/src/zope/app/component/browser/xxx_tests/test_editregistration.py	2005-11-16 17:16:26 UTC (rev 40163)
+++ Zope3/trunk/src/zope/app/component/browser/tests/test_editregistration.py	2005-11-16 23:37:25 UTC (rev 40187)
@@ -0,0 +1,83 @@
+##############################################################################
+#
+# 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.1 (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.
+#
+##############################################################################
+"""Registration Editing Tests
+
+$Id$
+"""
+from zope.app.testing import ztapi
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.app.component.browser.registration import EditRegistration
+from zope.app.container.interfaces import IContainer
+from zope.app.container.interfaces import IObjectRemovedEvent
+from zope.app.component.interfaces.registration import ActiveStatus
+from zope.app.traversing.interfaces import IContainmentRoot
+from zope.app.site.tests.placefulsetup import PlacefulSetup
+from zope.interface import Interface, implements
+from zope.app.publisher.browser import BrowserView
+from zope.publisher.browser import TestRequest
+from zope.app.container.contained import Contained
+
+class Container(dict):
+    implements(IContainer, IContainmentRoot)
+
+class I(Interface):
+    pass
+
+class C(Contained):
+    implements(I)
+    status = ActiveStatus
+
+
+class Test(PlacefulSetup, TestCase):
+
+    def test_remove_objects(self):
+        c1 = C()
+        c2 = C()
+        c7 = C()
+        d = Container({'1': c1, '2': c2, '7': c7})
+        view = EditRegistration(d, TestRequest())
+        view.remove_objects(['2', '7'])
+        self.assertEqual(d, {'1': c1})
+
+    def test_registrationInfo(self):
+
+        class V(BrowserView):
+            def setPrefix(self, p):
+                self._prefix = p
+
+        ztapi.browserView(I, 'ItemEdit', V)
+
+        c1 = C()
+        c2 = C()
+        c7 = C()
+        d = Container({'1': c1, '2': c2, '7': c7})
+        c1.__parent__ = d; c1.__name__ = '1'
+        c2.__parent__ = d; c2.__name__ = '2'
+        c7.__parent__ = d; c7.__name__ = '7'
+
+        view = EditRegistration(d, TestRequest())
+
+        info = view.registrationInfo()
+        self.assertEqual(len(info), 3)
+        self.assertEqual(info[0]['name'], '1')
+        self.assertEqual(info[1]['name'], '2')
+        self.assertEqual(info[2]['name'], '7')
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')

Copied: Zope3/trunk/src/zope/app/component/browser/tests/test_registrationview.py (from rev 40163, Zope3/trunk/src/zope/app/component/browser/xxx_tests/test_registrationview.py)
===================================================================
--- Zope3/trunk/src/zope/app/component/browser/xxx_tests/test_registrationview.py	2005-11-16 17:16:26 UTC (rev 40163)
+++ Zope3/trunk/src/zope/app/component/browser/tests/test_registrationview.py	2005-11-16 23:37:25 UTC (rev 40187)
@@ -0,0 +1,190 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Tests for the RegistrationView view class.
+
+$Id$
+"""
+import unittest
+import zope.component
+from zope.interface import implements
+from zope.publisher.browser import TestRequest
+from zope.testing import doctest, doctestunit
+from zope.app.testing import setup
+from zope.app.traversing.interfaces import IContainmentRoot
+
+from zope.app.component.interfaces.registration import IRegistered
+from zope.app.component.interfaces.registration import InactiveStatus
+from zope.app.component.interfaces.registration import ActiveStatus
+from zope.app.component.browser.registration import RegistrationView
+
+pprint = doctestunit.pprint
+
+
+def test():
+    """
+    >>> request = TestRequest()
+
+    Check results when using an unregisted object:
+
+    >>> view = RegistrationView(FakeRegisterable([]), request)
+    >>> view.registered()
+    False
+
+    Returns for the active() and registration() methods are undefined
+    for unregistred objects.
+
+    The update() method shouldn't do anything with an action specified
+    in the form:
+
+    >>> request.response.setStatus(200)
+    >>> view.update()
+    >>> view.registered()
+    False
+    >>> request.response.getStatus()
+    200
+
+    This simulates submitting the form using the 'Activate' button:
+
+    >>> request.form['activate'] = 'Activate'
+    >>> view.update()
+    >>> request.response.getStatus()
+    302
+    >>> request.response.getHeader('location')
+    'addRegistration.html'
+
+    Let's look at the case when the object has a single registration
+    to begin with:
+
+    >>> request = TestRequest()
+    >>> reg = FakeRegistration(InactiveStatus)
+    >>> reg.name = 'my fake'
+    >>> view = RegistrationView(FakeRegisterable([reg]), request)
+    >>> view.active()
+    False
+    >>> view.registered()
+    True
+    >>> pprint(view.registration())
+    {'details': 'my fake',
+     'url': 'http://127.0.0.1'}
+
+    Make sure calling `update()` without an action doesn't change the
+    registration:
+
+    >>> request.response.setStatus(200)
+    >>> view.update()
+    >>> request.response.getStatus()
+    200
+    >>> view.active()
+    False
+    >>> view.registered()
+    True
+    >>> pprint(view.registration())
+    {'details': 'my fake',
+     'url': 'http://127.0.0.1'}
+
+    Now test activating the object:
+
+    >>> request.form['activate'] = 'Activate'
+    >>> request.response.setStatus(200)
+    >>> view.update()
+    >>> request.response.getStatus()
+    200
+    >>> view.active()
+    True
+    >>> view.registered()
+    True
+    >>> pprint(view.registration())
+    {'details': 'my fake',
+     'url': 'http://127.0.0.1'}
+    >>> reg.status == ActiveStatus
+    True
+
+    Now test deactivating an active object:
+
+    >>> request.form = {'deactivate': 'Deactivate'}
+    >>> request.response.setStatus(200)
+    >>> view.update()
+    >>> request.response.getStatus()
+    200
+    >>> view.active()
+    False
+    >>> view.registered()
+    True
+    >>> pprint(view.registration())
+    {'details': 'my fake',
+     'url': 'http://127.0.0.1'}
+    >>> reg.status == InactiveStatus
+    True
+    """
+
+def test_multiple_registrations():
+    """
+    >>> request = TestRequest()
+    >>> reg1 = FakeRegistration(InactiveStatus)
+    >>> reg1.name = 'reg1'
+    >>> reg2 = FakeRegistration(ActiveStatus)
+    >>> reg2.name = 'reg2'
+    >>> view = RegistrationView(FakeRegisterable([reg1, reg2]), request)
+    >>> view.active()
+    False
+    >>> view.registered()
+    True
+    >>> pprint(view.registration())
+    {'details': 'reg1',
+     'url': 'http://127.0.0.1'}
+
+    Now make sure this view redirects us to the advanced registrations
+    form since we have more than one registraion:
+
+    >>> request.response.setStatus(200)
+    >>> view.update()
+    >>> request.response.getStatus()
+    302
+    """
+
+
+class FakeRegisterable(object):
+    implements(IRegistered)
+
+    def __init__(self, usages):
+        self._usages = usages
+
+    def registrations(self):
+        return self._usages
+
+
+class FakeRegistration(object):
+    implements(IContainmentRoot)
+
+    def __init__(self, status):
+        self.status = status
+
+
+def setUp(test):
+    zope.component.testing.setUp(test)
+    setup.setUpTraversal()
+    zope.component.provideAdapter(
+        lambda x, y: x.name,
+        (FakeRegistration, TestRequest), zope.interface.Interface,
+        name='details')
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocTestSuite(
+        setUp=setUp, tearDown=zope.component.testing.tearDown,
+        optionflags=doctest.NORMALIZE_WHITESPACE),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(default='test_suite')



More information about the Zope3-Checkins mailing list