[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/Browser/tests - __init__.py:1.2 testChangeConfigurations.py:1.2 testConfigurationStatusWidget.py:1.2

Jim Fulton jim@zope.com
Sat, 30 Nov 2002 13:35:56 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv11713/lib/python/Zope/App/OFS/Services/Browser/tests

Added Files:
	__init__.py testChangeConfigurations.py 
	testConfigurationStatusWidget.py 
Log Message:
Added a framework for managing configuration registration. This should
make it much easier to implement configurable services.



=== Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:35:56 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/__init__.py	Sat Nov 30 13:35:55 2002
@@ -0,0 +1,14 @@
+##############################################################################
+#
+# 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.
+# 
+##############################################################################
+


=== Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testChangeConfigurations.py 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:35:56 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testChangeConfigurations.py	Sat Nov 30 13:35:55 2002
@@ -0,0 +1,59 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+XXX longer description goes here.
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from Zope.Publisher.Browser.BrowserRequest import TestRequest
+from Zope.App.OFS.Services.tests.TestingConfigurationRegistry \
+     import TestingConfigurationRegistry
+
+class Test(TestCase):
+
+    def test_applyUpdates_and_setPrefix(self):
+        registry = TestingConfigurationRegistry('a', 'b', 'c')
+        request = TestRequest()
+        from Zope.App.OFS.Services.Browser.ChangeConfigurations \
+             import ChangeConfigurations
+        view = ChangeConfigurations(registry, request)
+        view.setPrefix("Roles")
+
+        # Make sure we don't apply updates unless asked to
+        request.form = {'Roles.active': 'disable'}
+        view.applyUpdates()
+        self.assertEqual(registry._data, ('a', 'b', 'c'))
+
+        # Now test disabling
+        request.form = {'submit_update': '', 'Roles.active': 'disable'}
+        view.applyUpdates()
+        self.assertEqual(registry._data, (None, 'a', 'b', 'c'))
+
+        # Now test enabling c
+        request.form = {'submit_update': '', 'Roles.active': 'c'}
+        view.applyUpdates()
+        self.assertEqual(registry._data, ('c', 'a', 'b'))
+        
+        
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testConfigurationStatusWidget.py 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:35:56 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testConfigurationStatusWidget.py	Sat Nov 30 13:35:55 2002
@@ -0,0 +1,91 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+XXX longer description goes here.
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from Zope.Publisher.Browser.BrowserRequest import TestRequest
+from Zope.App.OFS.Services.ConfigurationInterfaces import ConfigurationStatus
+from Zope.App.OFS.Services.Browser.ConfigurationStatusWidget \
+     import ConfigurationStatusWidget
+from Interface import Interface
+
+
+class Test(TestCase):
+
+    def test_call(self):
+        field = ConfigurationStatus(__name__="status")
+        request = TestRequest()
+        widget = ConfigurationStatusWidget(field, request)
+        widget.setPrefix("f")
+
+        text = ' '.join(widget().split())
+        self.assertEqual(
+            text,
+            '<input type="radio" name="f.status" value="Unregistered" checked>'
+            ' Unregistered<br />'
+            '<input type="radio" name="f.status" value="Registered">'
+            ' Registered<br />'
+            '<input type="radio" name="f.status" value="Active">'
+            ' Active'
+            )
+        
+        request.form['f.status'] = u'Registered'
+        text = ' '.join(widget().split())
+        self.assertEqual(
+            text,
+            '<input type="radio" name="f.status" value="Unregistered">'
+            ' Unregistered<br />'
+            '<input type="radio" name="f.status" value="Registered" checked>'
+            ' Registered<br />'
+            '<input type="radio" name="f.status" value="Active">'
+            ' Active'
+            )
+
+        widget.setData(u"Active")
+        text = ' '.join(widget().split())
+        self.assertEqual(
+            text,
+            '<input type="radio" name="f.status" value="Unregistered">'
+            ' Unregistered<br />'
+            '<input type="radio" name="f.status" value="Registered">'
+            ' Registered<br />'
+            '<input type="radio" name="f.status" value="Active" checked>'
+            ' Active'
+            )
+
+        widget.setData(u"Unregistered")
+        text = ' '.join(widget().split())
+        self.assertEqual(
+            text,
+            '<input type="radio" name="f.status" value="Unregistered" checked>'
+            ' Unregistered<br />'
+            '<input type="radio" name="f.status" value="Registered">'
+            ' Registered<br />'
+            '<input type="radio" name="f.status" value="Active">'
+            ' Active'
+            )
+
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')