[Checkins] SVN: Zope3/trunk/src/zope/app/ - Moved zope.app.ftests into zope.app.testing

Baiju M baiju.m.mail at gmail.com
Tue Feb 20 00:58:10 EST 2007


Log message for revision 72698:
   - Moved zope.app.ftests into zope.app.testing
   - Added AppTestingLayer for the moved ftests
  

Changed:
  U   Zope3/trunk/src/zope/app/apidoc/bookmodule/book.zcml
  D   Zope3/trunk/src/zope/app/ftests/
  A   Zope3/trunk/src/zope/app/testing/doctest.txt
  A   Zope3/trunk/src/zope/app/testing/ftesting.zcml
  A   Zope3/trunk/src/zope/app/testing/ftests.py
  A   Zope3/trunk/src/zope/app/testing/testing.py

-=-
Modified: Zope3/trunk/src/zope/app/apidoc/bookmodule/book.zcml
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/bookmodule/book.zcml	2007-02-19 22:44:37 UTC (rev 72697)
+++ Zope3/trunk/src/zope/app/apidoc/bookmodule/book.zcml	2007-02-20 05:58:08 UTC (rev 72698)
@@ -159,15 +159,13 @@
         parent="test"
         />
   </configure>
-  <configure package="zope.app.ftests">
+  <configure package="zope.app.testing">
     <bookchapter
         id="fdoctest"
         title="Functional DocTest"
         doc_path="doctest.txt"
         parent="test"
         />
-  </configure>
-  <configure package="zope.app.testing">
     <bookchapter
         id="fdoctest-howto"
         title="FDocTest (How to)"

Copied: Zope3/trunk/src/zope/app/testing/doctest.txt (from rev 72675, Zope3/trunk/src/zope/app/ftests/doctest.txt)

Added: Zope3/trunk/src/zope/app/testing/ftesting.zcml
===================================================================
--- Zope3/trunk/src/zope/app/testing/ftesting.zcml	2007-02-19 22:44:37 UTC (rev 72697)
+++ Zope3/trunk/src/zope/app/testing/ftesting.zcml	2007-02-20 05:58:08 UTC (rev 72698)
@@ -0,0 +1,57 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   i18n_domain="zope"
+   package="zope.app.testing"
+   >
+
+  <!-- This file is the equivalent of site.zcml and it is -->
+  <!-- used for functional testing setup -->
+
+  <include package="zope.app.securitypolicy" file="meta.zcml" />
+  <include package="zope.app.zcmlfiles" />
+
+  <include package="zope.app.file"/>
+  <include package="zope.app.authentication" />
+  <include package="zope.app.zptpage"/>
+
+  <include package="zope.app.securitypolicy.tests" file="functional.zcml" />
+  <include package="zope.app.securitypolicy" />
+
+  <securityPolicy
+    component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+
+  <role id="zope.Anonymous" title="Everybody"
+                 description="All users have this role implicitly" />
+  <role id="zope.Manager" title="Site Manager" />
+
+  <!-- Replace the following directive if you don't want public access -->
+  <grant permission="zope.View"
+                  role="zope.Anonymous" />
+
+  <grantAll role="zope.Manager" />
+
+
+  <!-- Principals -->
+
+  <unauthenticatedPrincipal
+      id="zope.anybody"
+      title="Unauthenticated User" />
+
+  <!-- Principal that tests generally run as -->
+  <principal
+      id="zope.mgr"
+      title="Manager"
+      login="mgr"
+      password="mgrpw" />
+
+  <!-- Bootstrap principal used to make local grant to the principal above -->
+  <principal
+      id="zope.globalmgr"
+      title="Manager"
+      login="globalmgr"
+      password="globalmgrpw" />
+
+  <grant role="zope.Manager" principal="zope.globalmgr" />
+
+
+</configure>


Property changes on: Zope3/trunk/src/zope/app/testing/ftesting.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: Zope3/trunk/src/zope/app/testing/ftests.py (from rev 72675, Zope3/trunk/src/zope/app/ftests/test_functional.py)
===================================================================
--- Zope3/trunk/src/zope/app/ftests/test_functional.py	2007-02-19 11:55:00 UTC (rev 72675)
+++ Zope3/trunk/src/zope/app/testing/ftests.py	2007-02-20 05:58:08 UTC (rev 72698)
@@ -0,0 +1,151 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Functional tests for the functional test framework
+
+$Id$
+"""
+__docformat__ = 'restructuredtext'
+
+import unittest
+import transaction
+from zope.app.testing.functional import SampleFunctionalTest, BrowserTestCase
+from zope.app.testing.functional import FunctionalDocFileSuite
+from zope.app.testing.functional import FunctionalTestCase
+from zope.app.testing.testing import AppTestingLayer
+
+class CookieFunctionalTest(BrowserTestCase):
+
+    """Functional tests should handle cookies like a web browser
+    
+    Multiple requests in the same test should acumulate cookies.
+    We also ensure that cookies with path values are only sent for
+    the correct URL's so we can test cookies don't 'leak'. Expiry,
+    secure and other cookie attributes are not being worried about
+    at the moment
+
+    """
+
+    def setUp(self):
+        super(CookieFunctionalTest, self).setUp()
+        self.assertEqual(
+                len(self.cookies.keys()), 0,
+                'cookies store should be empty'
+                )
+
+        root = self.getRootFolder()
+
+        from zope.app.zptpage.zptpage import ZPTPage
+
+        page = ZPTPage()
+
+        page.source = u'''<tal:tag tal:define="
+        cookies python:['%s=%s'%(k,v) for k,v in request.getCookies().items()]"
+        ><tal:tag tal:define="
+        ignored python:cookies.sort()"
+        /><span tal:replace="python:';'.join(cookies)" /></tal:tag>'''
+
+        root['getcookies'] = page
+
+        page = ZPTPage()
+
+        page.source = u'''<tal:tag tal:define="
+            ignored python:request.response.setCookie('bid','bval')" >
+            <h1 tal:condition="ignored" />
+            </tal:tag>'''
+
+        root['setcookie'] = page
+        transaction.commit()
+
+    def tearDown(self):
+        root = self.getRootFolder()
+        del root['getcookies']
+        del root['setcookie']
+        super(CookieFunctionalTest, self).tearDown()
+
+    def testDefaultCookies(self):
+        # By default no cookies are set
+        response = self.publish('/')
+        self.assertEquals(response.getStatus(), 200)
+        self.assert_(not response._request._cookies)
+
+    def testSimpleCookies(self):
+        self.cookies['aid'] = 'aval'
+        response = self.publish('/')
+        self.assertEquals(response.getStatus(), 200)
+        self.assertEquals(response._request._cookies['aid'], 'aval')
+
+    def testCookiePaths(self):
+        # We only send cookies if the path is correct
+        self.cookies['aid'] = 'aval'
+        self.cookies['aid']['Path'] = '/sub/folder'
+        self.cookies['bid'] = 'bval'
+        response = self.publish('/')
+
+        self.assertEquals(response.getStatus(), 200)
+        self.assert_(not response._request._cookies.has_key('aid'))
+        self.assertEquals(response._request._cookies['bid'], 'bval')
+
+    def testHttpCookieHeader(self):
+        # Passing an HTTP_COOKIE header to publish adds cookies
+        response = self.publish('/', env={
+            'HTTP_COOKIE': '$Version=1, aid=aval; $Path=/sub/folder, bid=bval'
+            })
+        self.assertEquals(response.getStatus(), 200)
+        self.failIf(response._request._cookies.has_key('aid'))
+        self.assertEquals(response._request._cookies['bid'], 'bval')
+
+    def testStickyCookies(self):
+        # Cookies should acumulate during the test
+        response = self.publish('/', env={'HTTP_COOKIE': 'aid=aval;'})
+        self.assertEquals(response.getStatus(), 200)
+
+        # Cookies are implicity passed to further requests in this test
+        response = self.publish('/getcookies')
+        self.assertEquals(response.getStatus(), 200)
+        self.assertEquals(response.getBody().strip(), 'aid=aval')
+
+        # And cookies set in responses also acumulate
+        response = self.publish('/setcookie')
+        self.assertEquals(response.getStatus(), 200)
+        response = self.publish('/getcookies')
+        self.assertEquals(response.getStatus(), 200)
+        self.assertEquals(response.getBody().strip(), 'aid=aval;bid=bval')
+
+
+class SkinsAndHTTPCaller(FunctionalTestCase):
+
+    def test_skins(self):
+        # Regression test for http://zope.org/Collectors/Zope3-dev/353
+        from zope.app.testing.functional import HTTPCaller
+        http = HTTPCaller()
+        response = http("GET /++skin++Basic HTTP/1.1\n\n")
+        self.assert_("zopetopBasic.css" in str(response))
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    SampleFunctionalTest.layer = AppTestingLayer
+    CookieFunctionalTest.layer = AppTestingLayer
+    SkinsAndHTTPCaller.layer = AppTestingLayer
+    doc_test = FunctionalDocFileSuite('doctest.txt')
+    doc_test.layer = AppTestingLayer
+    suite.addTest(unittest.makeSuite(SampleFunctionalTest))
+    suite.addTest(unittest.makeSuite(CookieFunctionalTest))
+    suite.addTest(unittest.makeSuite(SkinsAndHTTPCaller))
+    suite.addTest(doc_test)
+    return suite
+
+
+if __name__ == '__main__':
+    unittest.main()

Added: Zope3/trunk/src/zope/app/testing/testing.py
===================================================================
--- Zope3/trunk/src/zope/app/testing/testing.py	2007-02-19 22:44:37 UTC (rev 72697)
+++ Zope3/trunk/src/zope/app/testing/testing.py	2007-02-20 05:58:08 UTC (rev 72698)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# Copyright (c) 2007 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.
+#
+##############################################################################
+"""zope.app.testing common test related classes/functions/objects.
+
+$Id$
+"""
+
+__docformat__ = "reStructuredText"
+
+import os
+from zope.app.testing.functional import ZCMLLayer
+
+AppTestingLayer = ZCMLLayer(
+    os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
+    __name__, 'AppTestingLayer', allow_teardown=True)


Property changes on: Zope3/trunk/src/zope/app/testing/testing.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Checkins mailing list