[Checkins] SVN: Sandbox/darrylcousins/mars.view/ Writing tests

Darryl Cousins darryl at darrylcousins.net.nz
Mon Jul 16 08:34:27 EDT 2007


Log message for revision 78025:
  Writing tests

Changed:
  U   Sandbox/darrylcousins/mars.view/buildout.cfg
  U   Sandbox/darrylcousins/mars.view/setup.py
  U   Sandbox/darrylcousins/mars.view/src/mars/view/README.txt
  U   Sandbox/darrylcousins/mars.view/src/mars/view/ftests/directive.py
  U   Sandbox/darrylcousins/mars.view/src/mars/view/ftests/ftesting.zcml
  U   Sandbox/darrylcousins/mars.view/src/mars/view/ftests/layout.py
  U   Sandbox/darrylcousins/mars.view/src/mars/view/ftests/pagelet.py
  U   Sandbox/darrylcousins/mars.view/src/mars/view/ftests/template.py
  D   Sandbox/darrylcousins/mars.view/src/mars/view/ftests/test_all.py
  A   Sandbox/darrylcousins/mars.view/src/mars/view/ftests/test_functional.py
  A   Sandbox/darrylcousins/mars.view/src/mars/view/tests.py
  A   Sandbox/darrylcousins/mars.view/src/mars/view/view.txt

-=-
Modified: Sandbox/darrylcousins/mars.view/buildout.cfg
===================================================================
--- Sandbox/darrylcousins/mars.view/buildout.cfg	2007-07-16 11:52:13 UTC (rev 78024)
+++ Sandbox/darrylcousins/mars.view/buildout.cfg	2007-07-16 12:34:26 UTC (rev 78025)
@@ -5,6 +5,9 @@
 [test]
 recipe = zc.recipe.testrunner
 eggs = mars.view [test]
+defaults = ['--tests-pattern', '^f?tests$',
+	'-v'
+	]
 
 [zope3]
 location = .

Modified: Sandbox/darrylcousins/mars.view/setup.py
===================================================================
--- Sandbox/darrylcousins/mars.view/setup.py	2007-07-16 11:52:13 UTC (rev 78024)
+++ Sandbox/darrylcousins/mars.view/setup.py	2007-07-16 12:34:26 UTC (rev 78025)
@@ -25,26 +25,13 @@
     extras_require = dict(
                 test=['zope.app.testing',
                       'zope.testbrowser',
-                      'zope.app.zcmlfiles',
-                      'zope.app.securitypolicy',
-                      'zope.app.authentication',
-                      'z3c.pagelet',
                       'mars.layer',
                       'mars.template',
         ]
                 ),
     install_requires = [
         'setuptools',
-        'zope.app.intid',
-        'zope.app.catalog',
-        'zope.component',
-        'zope.interface',
-        'zope.publisher',
-        'zope.pagetemplate',
         'grok',
-        'martian',
-        'z3c.form',
-        'z3c.layer',
         'z3c.template',
         'z3c.pagelet',
         ],

Modified: Sandbox/darrylcousins/mars.view/src/mars/view/README.txt
===================================================================
--- Sandbox/darrylcousins/mars.view/src/mars/view/README.txt	2007-07-16 11:52:13 UTC (rev 78024)
+++ Sandbox/darrylcousins/mars.view/src/mars/view/README.txt	2007-07-16 12:34:26 UTC (rev 78025)
@@ -29,11 +29,10 @@
 TemplateView provides only a `render` method which returns the rendered
 template.
 
-LayoutView has a `__call__` method that returns the rendered layout template in
-addition to a `render` method inherited from TemplateView which returns the
-rendered template.
+LayoutView has a `__call__` method that returns the rendered layout template.
 
-PageletView provides both a ``render`` method and a ``__call__`` method.
+PageletView provides both a ``render`` method and a ``__call__`` method in the
+manner of z3c.pagelet.
 
 FormView is useful with z3c.form (see mars.formdemo for examples).
 

Modified: Sandbox/darrylcousins/mars.view/src/mars/view/ftests/directive.py
===================================================================
--- Sandbox/darrylcousins/mars.view/src/mars/view/ftests/directive.py	2007-07-16 11:52:13 UTC (rev 78024)
+++ Sandbox/darrylcousins/mars.view/src/mars/view/ftests/directive.py	2007-07-16 12:34:26 UTC (rev 78025)
@@ -2,7 +2,7 @@
 Test the claimed directives.
 
   >>> import grok
-  >>> grok.grok('mars.view.tests.directive')
+  >>> grok.grok('mars.view.ftests.directive')
 
   >>> from zope.testbrowser.testing import Browser
   >>> browser = Browser()

Modified: Sandbox/darrylcousins/mars.view/src/mars/view/ftests/ftesting.zcml
===================================================================
--- Sandbox/darrylcousins/mars.view/src/mars/view/ftests/ftesting.zcml	2007-07-16 11:52:13 UTC (rev 78024)
+++ Sandbox/darrylcousins/mars.view/src/mars/view/ftests/ftesting.zcml	2007-07-16 12:34:26 UTC (rev 78025)
@@ -9,8 +9,6 @@
   <include package="mars.layer" file="meta.zcml" />
   <include package="mars.view" file="meta.zcml" />
 
-  <include package="z3c.layer.minimal.tests" file="ftesting.zcml" />
-
   <include package="grok" />
 
 </configure>

Modified: Sandbox/darrylcousins/mars.view/src/mars/view/ftests/layout.py
===================================================================
--- Sandbox/darrylcousins/mars.view/src/mars/view/ftests/layout.py	2007-07-16 11:52:13 UTC (rev 78024)
+++ Sandbox/darrylcousins/mars.view/src/mars/view/ftests/layout.py	2007-07-16 12:34:26 UTC (rev 78025)
@@ -2,8 +2,8 @@
 Testing the LayoutView, which unlike grok.View will look up a layout.
 
   >>> import grok
-  >>> grok.grok('mars.view.tests.layout')
-  >>> from mars.view.tests.layout import Mammoth
+  >>> grok.grok('mars.view.ftests.layout')
+  >>> from mars.view.ftests.layout import Mammoth
   >>> getRootFolder()["manfred"] = Mammoth()
 
   >>> from zope.testbrowser.testing import Browser
@@ -41,7 +41,7 @@
   >>> from z3c.template.template import TemplateFactory
   >>> from zope.publisher.interfaces.browser import IBrowserRequest
   >>> import zope.component
-  >>> from mars.view.tests.layout import Drawing
+  >>> from mars.view.ftests.layout import Drawing
   >>> factory = TemplateFactory(layout, 'text/html')
   >>> zope.component.provideAdapter(factory,
   ...     (Drawing, IBrowserRequest), ILayoutTemplate)

Modified: Sandbox/darrylcousins/mars.view/src/mars/view/ftests/pagelet.py
===================================================================
--- Sandbox/darrylcousins/mars.view/src/mars/view/ftests/pagelet.py	2007-07-16 11:52:13 UTC (rev 78024)
+++ Sandbox/darrylcousins/mars.view/src/mars/view/ftests/pagelet.py	2007-07-16 12:34:26 UTC (rev 78025)
@@ -2,8 +2,8 @@
 Testing the PageletView, which unlike grok.View will look up a layout.
 
   >>> import grok
-  >>> grok.grok('mars.view.tests.pagelet')
-  >>> from mars.view.tests.pagelet import Mammoth
+  >>> grok.grok('mars.view.ftests.pagelet')
+  >>> from mars.view.ftests.pagelet import Mammoth
   >>> getRootFolder()["manfred"] = Mammoth()
 
   >>> from zope.testbrowser.testing import Browser

Modified: Sandbox/darrylcousins/mars.view/src/mars/view/ftests/template.py
===================================================================
--- Sandbox/darrylcousins/mars.view/src/mars/view/ftests/template.py	2007-07-16 11:52:13 UTC (rev 78024)
+++ Sandbox/darrylcousins/mars.view/src/mars/view/ftests/template.py	2007-07-16 12:34:26 UTC (rev 78025)
@@ -2,8 +2,8 @@
 Testing the TemplateView, which unlike grok.View will look up a template.
 
   >>> import grok
-  >>> from mars.view.tests.template import Mammoth, Painting
-  >>> grok.grok('mars.view.tests.template')
+  >>> from mars.view.ftests.template import Mammoth, Painting
+  >>> grok.grok('mars.view.ftests.template')
   >>> mammoth = getRootFolder()["manfred"] = Mammoth()
 
   >>> from zope.testbrowser.testing import Browser
@@ -49,7 +49,7 @@
 
 We can also use mars.template to provide the template.
 
-  >>> from mars.view.tests.template import View
+  >>> from mars.view.ftests.template import View
   >>> view = View(mammoth, request)
   >>> print view.render()
   <div>View template</div>

Deleted: Sandbox/darrylcousins/mars.view/src/mars/view/ftests/test_all.py
===================================================================
--- Sandbox/darrylcousins/mars.view/src/mars/view/ftests/test_all.py	2007-07-16 11:52:13 UTC (rev 78024)
+++ Sandbox/darrylcousins/mars.view/src/mars/view/ftests/test_all.py	2007-07-16 12:34:26 UTC (rev 78025)
@@ -1,22 +0,0 @@
-import unittest
-from pkg_resources import resource_listdir
-
-from grok.ftests.test_grok_functional import FunctionalDocTestSuite
-
-from zope.app.testing import functional
-functional.defineLayer('TestLayer', 'ftesting.zcml')
-
-def test_suite():
-    suite = unittest.TestSuite()
-    dottedname = 'mars.view.tests.%s'
-    for name in ['layout', 'template', 'pagelet']:
-        test = FunctionalDocTestSuite(dottedname % name)
-        test.layer = TestLayer
-        suite.addTest(test)
-
-    return suite
-
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')
-

Added: Sandbox/darrylcousins/mars.view/src/mars/view/ftests/test_functional.py
===================================================================
--- Sandbox/darrylcousins/mars.view/src/mars/view/ftests/test_functional.py	                        (rev 0)
+++ Sandbox/darrylcousins/mars.view/src/mars/view/ftests/test_functional.py	2007-07-16 12:34:26 UTC (rev 78025)
@@ -0,0 +1,29 @@
+import unittest
+from zope.testing import doctest
+
+from zope.app.testing.functional import FunctionalTestSetup, getRootFolder
+from zope.app.testing import functional
+functional.defineLayer('TestLayer', 'ftesting.zcml')
+
+optionflags = doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS
+globs = dict(getRootFolder=getRootFolder)
+
+def setUp(test):
+    FunctionalTestSetup().setUp()
+
+def tearDown(test):
+    FunctionalTestSetup().tearDown()
+
+def test_suite():
+    suite = unittest.TestSuite()
+    dottedname = 'mars.view.ftests.%s'
+    for name in ['layout', 'template', 'pagelet']:
+        test = doctest.DocTestSuite(
+                    dottedname % name, setUp=setUp, globs=globs,
+                    tearDown=tearDown, optionflags=optionflags)
+        test.layer = TestLayer
+        suite.addTest(test)
+    return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: Sandbox/darrylcousins/mars.view/src/mars/view/ftests/test_functional.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: Sandbox/darrylcousins/mars.view/src/mars/view/tests.py
===================================================================
--- Sandbox/darrylcousins/mars.view/src/mars/view/tests.py	                        (rev 0)
+++ Sandbox/darrylcousins/mars.view/src/mars/view/tests.py	2007-07-16 12:34:26 UTC (rev 78025)
@@ -0,0 +1,23 @@
+import unittest
+from zope.testing import doctest
+
+optionflags = doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS
+
+def setUp(test):
+    pass
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTests([doctest.DocFileSuite('view.txt',
+                             setUp=setUp,
+                             optionflags=optionflags),
+                   ])
+
+    return suite
+
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+
+
+


Property changes on: Sandbox/darrylcousins/mars.view/src/mars/view/tests.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: Sandbox/darrylcousins/mars.view/src/mars/view/view.txt
===================================================================
--- Sandbox/darrylcousins/mars.view/src/mars/view/view.txt	                        (rev 0)
+++ Sandbox/darrylcousins/mars.view/src/mars/view/view.txt	2007-07-16 12:34:26 UTC (rev 78025)
@@ -0,0 +1,121 @@
+=========
+Mars View
+=========
+
+z3c packages bring significant clarity and a pattern for forms, view and
+templates.
+
+This package uses martian to configure views. The views here defined are
+TemplateView and LayoutView, both use adapter lookup to locate the template to
+be used (but can class attributes `template` for TemplateView and LayoutView and `layout` for
+LayoutView will be used before adapter lookup).
+
+Setting Up
+----------
+
+First the usual imports.
+
+  >>> import zope.interface
+  >>> import zope.component
+  >>> import grok
+  >>> import mars.view
+  >>> import mars.layer
+  >>> import mars.template
+
+  >>> import os, tempfile
+  >>> temp_dir = tempfile.mkdtemp()
+
+Let's create a content object that will act as the context to the views.
+
+  >>> class Content(object):
+  ...     zope.interface.implements(zope.interface.Interface)
+  >>> content = Content()
+
+We also need a fake module info object to pass to the ``grokkers``.
+
+  >>> from martian.interfaces import IModuleInfo
+  >>> class ModuleInfo(object):
+  ...     zope.interface.implements(IModuleInfo)
+  ...     path = ''
+  ...     package_dotted_name = ''
+  ...     def getAnnotation(self, name, default):
+  ...         return default
+
+And a request object for ``viewing`` the views.
+
+  >>> from zope.publisher.browser import TestRequest
+  >>> request = TestRequest()
+
+Templates
+---------
+
+We need a couple of template files to use for the templates themselves.
+
+  >>> viewTemplate = os.path.join(temp_dir, 'viewTemplate.pt')
+  >>> open(viewTemplate, 'w').write('''<div>My view template</div>''')
+
+  >>> layoutTemplate = os.path.join(temp_dir, 'layoutTemplate.pt')
+  >>> open(layoutTemplate, 'w').write('''<div>My layout template</div>''')
+
+  >>> pageletTemplate = os.path.join(temp_dir, 'pageletTemplate.pt')
+  >>> open(pageletTemplate, 'w').write('''<div>My pagelet template</div>''')
+
+Template View
+-------------
+
+TemplateView provides only a `render` method which returns the rendered
+template. This is a good match for the ``template`` directive of z3c.template
+and is used most often with mars.template.TemplateFactory as in the following
+example.
+
+  >>> class View(mars.view.TemplateView):
+  ...     """This is the view class"""
+  ...     grok.context(zope.interface.Interface)
+
+  >>> class ViewTemplate(mars.template.TemplateFactory):
+  ...     """This is a template"""
+  ...     grok.template(viewTemplate)
+  ...     grok.context(View)
+
+We need to manually ``grok`` these classes in the doctest. Usually this happens
+at start up.
+
+  >>> from mars.view.meta import TemplateViewGrokker
+  >>> TemplateViewGrokker().grok('', View, None, ModuleInfo(), None)
+  True
+
+  >>> from mars.template.meta import TemplateFactoryGrokker
+  >>> TemplateFactoryGrokker().grok('', ViewTemplate, None, ModuleInfo(), None)
+  True
+
+We can now look up the view and expect the template to be rendered.
+
+  >>> view = zope.component.getMultiAdapter((content, request),
+  ...                                       name='view')
+  >>> print view.render()
+  <div>My content</div>
+
+
+Layout View
+-----------
+
+LayoutView has a `__call__` method that returns the rendered layout template.
+This is a good match for the ``layout`` directive of z3c.template and is used
+most often with mars.template.LayoutFactory as in the following example.
+
+
+Pagelet View
+------------
+
+PageletView provides both a ``render`` method and a ``__call__`` method in the
+manner of z3c.pagelet. In effect it combines both of the above views and
+duplicates z3c.pagelet.browser.BrowserPagelet.
+
+Form View
+---------
+
+FormView is useful with z3c.form (see mars.formdemo for examples). It provides
+neither a ``render`` nor a ``__call__`` method but may be used with z3c.form as
+in the following example.
+
+


Property changes on: Sandbox/darrylcousins/mars.view/src/mars/view/view.txt
___________________________________________________________________
Name: svn:keywords
   + Date Author



More information about the Checkins mailing list