[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/Browser/tests - TestViews.py:1.2 __init__.py:1.2 testAttributePublisher.py:1.2 testBrowserLanguages.py:1.2 testBrowserRequest.py:1.2
Jim Fulton
jim@zope.com
Mon, 10 Jun 2002 19:30:02 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv20468/lib/python/Zope/Publisher/Browser/tests
Added Files:
TestViews.py __init__.py testAttributePublisher.py
testBrowserLanguages.py testBrowserRequest.py
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.
=== Zope3/lib/python/Zope/Publisher/Browser/tests/TestViews.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+"""
+
+Revision information: $Id$
+"""
+
+from Interface import Interface
+from Zope.Publisher.Browser.BrowserView import BrowserView
+from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
+
+class IC(Interface): pass
+
+class V1(BrowserView): pass
+
+class VZMI(V1): pass
+
+class R1:
+ __implements__ = IBrowserPresentation
+ def __init__(self, request): self.request = request
+
+class RZMI(R1):
+ pass
=== Zope3/lib/python/Zope/Publisher/Browser/tests/__init__.py 1.1 => 1.2 ===
+#
+# 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/Publisher/Browser/tests/testAttributePublisher.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+import unittest, sys
+
+from Zope.Publisher.Browser.BrowserView import BrowserView
+from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
+
+from Interface.Verify import verifyClass
+from Interface.Implements import instancesOfObjectImplements
+
+class Presentation(BrowserView, AttributePublisher):
+ index = 'index'
+ action = 'action'
+ foo = 'foo'
+
+class TestAttributePublisher(unittest.TestCase):
+ def setUp(self):
+ self.pres = Presentation(None, None)
+
+ def testInterfacesVerify(self):
+ for interface in instancesOfObjectImplements(Presentation):
+ verifyClass(interface, Presentation)
+
+ def testBrowserDefault(self):
+ self.assertEquals(self.pres.browserDefault(None),
+ (self.pres, ('index.html',)))
+
+ def testBrowserTraverseIndexHtml(self):
+ self.assertEquals(self.pres.publishTraverse(None, 'index.html'),
+ 'index')
+
+ def testBrowserTraverseIndex(self):
+ self.assertEquals(self.pres.publishTraverse(None, 'index'),
+ 'index')
+
+ def testBrowserTraverseActionHtml(self):
+ self.assertEquals(self.pres.publishTraverse(None, 'action.html'),
+ 'action')
+
+ def testBrowserTraverseAction(self):
+ self.assertEquals(self.pres.publishTraverse(None, 'action'),
+ 'action')
+
+ def testBrowserTraverseNotFound(self):
+ self.failUnlessRaises(AttributeError, self.pres.publishTraverse,
+ None, 'bar')
+
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(TestAttributePublisher)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/Publisher/Browser/tests/testBrowserLanguages.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+import unittest, sys
+
+class Test(unittest.TestCase):
+
+ def test(self):
+ request = {'HTTP_ACCEPT_LANGUAGE': 'da, en-gb;q=0.8, en;q=0.7'}
+
+ from Zope.Publisher.Browser.BrowserLanguages import BrowserLanguages
+
+ browser_languages = BrowserLanguages(request)
+
+ self.assertEqual(list(browser_languages.getLanguages()),
+ ['da', 'en-gb', 'en'])
+
+ # XXX Add support for quality statements
+
+
+
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/Publisher/Browser/tests/testBrowserRequest.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+import unittest
+
+from Zope.Publisher.Browser.BrowserRequest import BrowserRequest
+from Zope.Publisher.Browser.BrowserResponse import BrowserResponse
+
+from Zope.Publisher.Publish import publish
+from Zope.Publisher.DefaultPublication import DefaultPublication
+from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
+
+from StringIO import StringIO
+
+from Zope.Publisher.HTTP.tests.testHTTP import HTTPTests
+
+class Publication(DefaultPublication):
+
+ def getDefaultTraversal(self, request, ob):
+ if hasattr(ob, 'browserDefault'):
+ return ob.browserDefault(request)
+ return ob, ()
+
+
+
+class BrowserTests(HTTPTests):
+
+ _testEnv = {
+ 'PATH_INFO': '/folder/item',
+ 'QUERY_STRING': 'a=5&b:int=6',
+ 'SERVER_URL': 'http://foobar.com',
+ 'HTTP_HOST': 'foobar.com',
+ 'CONTENT_LENGTH': '0',
+ 'HTTP_AUTHORIZATION': 'Should be in accessible',
+ 'GATEWAY_INTERFACE': 'TestFooInterface/1.0',
+ 'HTTP_OFF_THE_WALL': "Spam 'n eggs",
+ }
+
+ def setUp(self):
+ class AppRoot:
+ " "
+
+ class Folder:
+ " "
+
+ class Item:
+ " "
+ def __call__(self, a, b):
+ return "%s, %s" % (`a`, `b`)
+
+ class View:
+ " "
+ def browserDefault(self, request):
+ return self, ['index']
+
+ def index(self, a, b):
+ " "
+ return "%s, %s" % (`a`, `b`)
+
+ class Item2:
+ " "
+ view = View()
+
+ def browserDefault(self, request):
+ return self, ['view']
+
+
+ self.app = AppRoot()
+ self.app.folder = Folder()
+ self.app.folder.item = Item()
+ self.app.folder.item2 = Item2()
+
+ def _createRequest(self, extra_env={}, body="", outstream=None):
+ env = self._testEnv.copy()
+ env.update(extra_env)
+ if len(body):
+ env['CONTENT_LENGTH'] = str(len(body))
+
+ publication = Publication(self.app)
+ if outstream is None:
+ outstream = StringIO()
+ instream = StringIO(body)
+ request = BrowserRequest(instream, outstream, env)
+ request.setPublication(publication)
+ return request
+
+ def testTraversalToItem(self):
+ return
+ res = self._publisherResults()
+ self.failUnlessEqual(
+ res,
+ "Status: 200 Ok\r\n"
+ "Content-Length: 6\r\n"
+ "Content-Type: text/plain\r\n"
+ "X-Powered-By: Zope (www.zope.org), Python (www.python.org)\r\n"
+ "\r\n"
+ "'5', 6")
+
+ def testIPresentationRequest(self):
+ ''' test the IView request'''
+
+ r = self._createRequest()
+
+ self.failUnless( r.getPresentationType() is IBrowserPresentation)
+ self.assertEqual( r.getPresentationSkin(), '')
+ r.setViewSkin( 'morefoo' )
+ self.assertEqual( r.getPresentationSkin(), 'morefoo')
+
+ def testNoDefault(self):
+ request = self._createRequest()
+ response = request.getResponse()
+ publish(request)
+ self.failIf(response.getBase())
+
+ def testDefault(self):
+ extra = {'PATH_INFO': '/folder/item2'}
+ request = self._createRequest(extra)
+ response = request.getResponse()
+ publish(request)
+ self.assertEqual(response.getBase(),
+ 'http://foobar.com/folder/item2/view/index')
+
+ def testDefaultPOST(self):
+ extra = {'PATH_INFO': '/folder/item2', "REQUEST_METHOD": "POST"}
+ request = self._createRequest(extra)
+ response = request.getResponse()
+ publish(request)
+ self.assertEqual(response.getBase(),
+ 'http://foobar.com/folder/item2/view/index')
+
+ def testDefault2(self):
+ extra = {'PATH_INFO': '/folder/item2/view'}
+ request = self._createRequest(extra)
+ response = request.getResponse()
+ publish(request)
+ self.assertEqual(response.getBase(),
+ 'http://foobar.com/folder/item2/view/index')
+
+ def testDefault3(self):
+ extra = {'PATH_INFO': '/folder/item2/view/index'}
+ request = self._createRequest(extra)
+ response = request.getResponse()
+ publish(request)
+ self.failIf(response.getBase())
+
+ def testDefault4(self):
+ extra = {'PATH_INFO': '/folder/item2/view/'}
+ request = self._createRequest(extra)
+ response = request.getResponse()
+ publish(request)
+ self.failIf(response.getBase())
+
+ def testDefault6(self):
+ extra = {'PATH_INFO': '/folder/item2/'}
+ request = self._createRequest(extra)
+ response = request.getResponse()
+ publish(request)
+ self.assertEqual(response.getBase(),
+ 'http://foobar.com/folder/item2/view/index')
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase(BrowserTests)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run( test_suite() )
+
+
+