[Zope-CVS] SVN: book/trunk/fdoctests/ Added session data and Python code of the functional doctest chapter.

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Aug 26 15:38:24 EDT 2004


Log message for revision 27283:
  Added session data and Python code of the functional doctest chapter.
  


Changed:
  A   book/trunk/fdoctests/
  A   book/trunk/fdoctests/__init__.py
  A   book/trunk/fdoctests/ftests.py
  A   book/trunk/fdoctests/tmp/
  A   book/trunk/fdoctests/tmp/watch0001.request
  A   book/trunk/fdoctests/tmp/watch0001.response
  A   book/trunk/fdoctests/zptpage.txt
  A   book/trunk/fdoctests/zptpage_raw.txt


-=-
Added: book/trunk/fdoctests/__init__.py
===================================================================
--- book/trunk/fdoctests/__init__.py	2004-08-26 19:37:52 UTC (rev 27282)
+++ book/trunk/fdoctests/__init__.py	2004-08-26 19:38:24 UTC (rev 27283)
@@ -0,0 +1 @@
+# Make directory a package

Added: book/trunk/fdoctests/ftests.py
===================================================================
--- book/trunk/fdoctests/ftests.py	2004-08-26 19:37:52 UTC (rev 27282)
+++ book/trunk/fdoctests/ftests.py	2004-08-26 19:38:24 UTC (rev 27283)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# 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 'ZPT Page'
+
+$Id: functional.py 26214 2004-07-08 19:00:07Z srichter $
+"""
+__docformat__ = 'restructuredtext'
+import unittest
+from zope.app.tests.functional import FunctionalDocFileSuite
+
+def test_suite():
+    return FunctionalDocFileSuite('zptpage.txt')
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')

Added: book/trunk/fdoctests/tmp/watch0001.request
===================================================================
--- book/trunk/fdoctests/tmp/watch0001.request	2004-08-26 19:37:52 UTC (rev 27282)
+++ book/trunk/fdoctests/tmp/watch0001.request	2004-08-26 19:38:24 UTC (rev 27283)
@@ -0,0 +1,11 @@
+GET /newzptpage HTTP/1.1
+Connection: Keep-Alive
+User-Agent: Mozilla/5.0 (compatible; Konqueror/3.3; Linux; X11; en_US) (KHTML, like Gecko)
+Pragma: no-cache
+Cache-control: no-cache
+Accept: text/html, image/jpeg, image/png, text/*, image/*, */*
+Accept-Encoding: x-gzip, x-deflate, gzip, deflate
+Accept-Charset: utf-8, utf-8;q=0.5, *;q=0.5
+Accept-Language: en
+Host: localhost:8081
+

Added: book/trunk/fdoctests/tmp/watch0001.response
===================================================================
--- book/trunk/fdoctests/tmp/watch0001.response	2004-08-26 19:37:52 UTC (rev 27282)
+++ book/trunk/fdoctests/tmp/watch0001.response	2004-08-26 19:38:24 UTC (rev 27283)
@@ -0,0 +1,12 @@
+HTTP/1.1 200 Ok
+Date: Thu, 26 Aug 2004 16:24:25 GMT
+Content-Length: 72
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Content-Type: text/html;charset=utf-8
+Server: zope.server.http (HTTP)
+
+<html>
+  <body>
+    <h1>Thu Aug 26 12:24:26 2004</h1>
+  </body>
+</html>

Added: book/trunk/fdoctests/zptpage.txt
===================================================================
--- book/trunk/fdoctests/zptpage.txt	2004-08-26 19:37:52 UTC (rev 27282)
+++ book/trunk/fdoctests/zptpage.txt	2004-08-26 19:38:24 UTC (rev 27283)
@@ -0,0 +1,46 @@
+========
+ZPT Page
+========
+
+This file demonstrates how a page template is rendered in content
+space. Before we can render the page though, we have to create one. The
+template content will be:
+
+  >>> template = u'''\
+  ... <html>
+  ...   <body>
+  ...     <h1 tal:content="modules/time/asctime" />
+  ...   </body>
+  ... </html>'''
+
+Next we have to create the ZPT Page in the root folder. The root folder of the
+test setup can be simply retrieved by calling `getRootFolder()`. At the end we
+have to commit the transaction, so that the page will be stored in the ZODB
+and available for requests to be accessed.
+
+  >>> from transaction import get_transaction
+  >>> from zope.app.zptpage.zptpage import ZPTPage
+  >>> root = getRootFolder()
+  >>> root['newzptpage'] = ZPTPage()
+  >>> root['newzptpage'].setSource(template, 'text/html')
+  >>> get_transaction().commit()
+
+Now that we have the page setup, we can just send the HTTP request by calling
+the function `http()`, which will return the complete HTTP response. When
+comparing the 
+
+  >>> print http(r"""
+  ... GET /newzptpage HTTP/1.1
+  ... Cache-Control: no-cache
+  ... Pragma: no-cache
+  ... """)
+  HTTP/1.1 200 Ok
+  Content-Length: 72
+  Content-Type: text/html;charset=utf-8
+  <BLANKLINE>
+  <html>
+    <body>
+      <h1>...</h1>
+    </body>
+  </html>
+  <BLANKLINE>

Added: book/trunk/fdoctests/zptpage_raw.txt
===================================================================
--- book/trunk/fdoctests/zptpage_raw.txt	2004-08-26 19:37:52 UTC (rev 27282)
+++ book/trunk/fdoctests/zptpage_raw.txt	2004-08-26 19:38:24 UTC (rev 27283)
@@ -0,0 +1,17 @@
+
+
+  >>> print http(r"""
+  ... GET /newzptpage HTTP/1.1
+  ... Cache-Control: no-cache
+  ... Pragma: no-cache
+  ... """)
+  HTTP/1.1 200 Ok
+  Content-Length: 72
+  Content-Type: text/html;charset=utf-8
+  <BLANKLINE>
+  <html>
+    <body>
+      <h1>Thu Aug 26 12:24:26 2004</h1>
+    </body>
+  </html>
+  <BLANKLINE>



More information about the Zope-CVS mailing list