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

Jim Fulton jim@zope.com
Thu, 19 Dec 2002 15:38:54 -0500


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

Added Files:
	test_field_widget.py 
Log Message:
Merged changes made by Albertas and Jim from the AdapterAndView-branch
branch:

- Added TTW adapter service

  Todo: 

    o Named adapters

    o Getting classes in persistent modules working so we can actually
      create TTW adapters.

- Added TTW view service

  o View service

  o View configurations
 
    For configuting views from view factories

  o Page configurations 

    For configuring views based on templates (and optional classes)

  o View (sub)packages.  These get added to packages. You configure
    them with default configuration info and then add page templates
    to them. Added page temlates are automatically added as views with
    the same name.




=== Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/test_field_widget.py 1.1 => 1.2 ===
--- /dev/null	Thu Dec 19 15:38:54 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/test_field_widget.py	Thu Dec 19 15:38:24 2002
@@ -0,0 +1,107 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""ComponentLocationWidget tests.
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup \
+     import PlacefulSetup
+from Zope.App.Traversing import traverse
+from Interface import Interface
+from Zope.App.OFS.Services.ServiceManager.ServiceManager import ServiceManager
+from Zope.Publisher.Browser.BrowserRequest import TestRequest
+from Zope.App.OFS.Services.Browser.field import ComponentLocationWidget
+
+class FakeComponentLocation:
+
+    default = None
+    
+    def __init__(self, context, type):
+        self.context = context
+        self.type = type
+
+    def validate(self, value): pass
+
+    __name__ = 'X'
+    
+class I1(Interface):  pass
+
+class I2(Interface):  pass
+
+class C:
+    __implements__ = I1
+
+class D:
+    __implements__ = I2
+
+class Test(PlacefulSetup, TestCase):
+
+    def test(self):
+        self.buildFolders()
+        self.rootFolder.setServiceManager(ServiceManager())
+        default = traverse(self.rootFolder,
+                           '++etc++Services/Packages/default')
+        default.setObject('c1', C())
+        default.setObject('c2', C())
+        default.setObject('c3', C())
+        default.setObject('d1', D())
+        default.setObject('d2', D())
+        default.setObject('d3', D())
+
+        request = TestRequest()
+
+        fake = FakeComponentLocation(default, I1)
+        widget = ComponentLocationWidget(fake, request)
+
+        expected = (
+            '<select name="field.X">\n'
+            '<option></option>\n'
+            '<option>/++etc++Services/Packages/default/c1</option>\n'
+            '<option>/++etc++Services/Packages/default/c2</option>\n'
+            '<option>/++etc++Services/Packages/default/c3</option>\n'
+            '</select>'
+            )
+
+        self.assertEqual(widget(), expected)
+
+        request.form['field.X'] = u'/++etc++Services/Packages/default/c2'
+        
+        expected = (
+            '<select name="field.X">\n'
+            '<option></option>\n'
+            '<option>/++etc++Services/Packages/default/c1</option>\n'
+            '<option selected>/++etc++Services/Packages/default/c2</option>\n'
+            '<option>/++etc++Services/Packages/default/c3</option>\n'
+            '</select>'
+            )
+
+        self.assertEqual(widget(), expected)
+
+    def test_convert(self):
+        request = TestRequest()
+        fake = FakeComponentLocation(None, I1)
+        widget = ComponentLocationWidget(fake, request)
+        self.assertEqual(widget._convert(u''), None)
+        self.assertEqual(widget._convert(u'/a'), u'/a')
+        
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')