[Checkins] SVN: Sandbox/luciano/testedsample/ added Grok sample app with working functional test

Luciano Ramalho luciano at ramalho.org
Sat Aug 11 10:03:37 EDT 2007


Log message for revision 78747:
  added Grok sample app with working functional test
  

Changed:
  A   Sandbox/luciano/testedsample/
  A   Sandbox/luciano/testedsample/src/
  A   Sandbox/luciano/testedsample/src/testedsample/
  A   Sandbox/luciano/testedsample/src/testedsample/__init__.py
  A   Sandbox/luciano/testedsample/src/testedsample/app.py
  A   Sandbox/luciano/testedsample/src/testedsample/app_templates/
  A   Sandbox/luciano/testedsample/src/testedsample/app_templates/index.pt
  A   Sandbox/luciano/testedsample/src/testedsample/configure.zcml
  A   Sandbox/luciano/testedsample/src/testedsample/ftesting.zcml
  A   Sandbox/luciano/testedsample/src/testedsample/ftests/
  A   Sandbox/luciano/testedsample/src/testedsample/ftests/__init__.py
  A   Sandbox/luciano/testedsample/src/testedsample/ftests/index.txt
  A   Sandbox/luciano/testedsample/src/testedsample/ftests/test_functional.py
  A   Sandbox/luciano/testedsample/src/testedsample/testing.py

-=-
Added: Sandbox/luciano/testedsample/src/testedsample/__init__.py
===================================================================
--- Sandbox/luciano/testedsample/src/testedsample/__init__.py	                        (rev 0)
+++ Sandbox/luciano/testedsample/src/testedsample/__init__.py	2007-08-11 14:03:36 UTC (rev 78747)
@@ -0,0 +1 @@
+# this directory is a package

Added: Sandbox/luciano/testedsample/src/testedsample/app.py
===================================================================
--- Sandbox/luciano/testedsample/src/testedsample/app.py	                        (rev 0)
+++ Sandbox/luciano/testedsample/src/testedsample/app.py	2007-08-11 14:03:36 UTC (rev 78747)
@@ -0,0 +1,7 @@
+import grok
+
+class TestedSample(grok.Application, grok.Container):
+    pass
+
+class Index(grok.View):
+    pass # see app_templates/index.pt
\ No newline at end of file

Added: Sandbox/luciano/testedsample/src/testedsample/app_templates/index.pt
===================================================================
--- Sandbox/luciano/testedsample/src/testedsample/app_templates/index.pt	                        (rev 0)
+++ Sandbox/luciano/testedsample/src/testedsample/app_templates/index.pt	2007-08-11 14:03:36 UTC (rev 78747)
@@ -0,0 +1,11 @@
+<html>
+<head>
+</head>
+<body>
+  <h1>Congratulations!</h1>
+
+  <p>Your Grok application is up and running.
+  Edit <code>testedsample/app_templates/index.pt</code> to change
+  this page.</p>
+</body>
+</html>

Added: Sandbox/luciano/testedsample/src/testedsample/configure.zcml
===================================================================
--- Sandbox/luciano/testedsample/src/testedsample/configure.zcml	                        (rev 0)
+++ Sandbox/luciano/testedsample/src/testedsample/configure.zcml	2007-08-11 14:03:36 UTC (rev 78747)
@@ -0,0 +1,5 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+           xmlns:grok="http://namespaces.zope.org/grok">
+  <include package="grok" />
+  <grok:grok package="." />
+</configure>

Added: Sandbox/luciano/testedsample/src/testedsample/ftesting.zcml
===================================================================
--- Sandbox/luciano/testedsample/src/testedsample/ftesting.zcml	                        (rev 0)
+++ Sandbox/luciano/testedsample/src/testedsample/ftesting.zcml	2007-08-11 14:03:36 UTC (rev 78747)
@@ -0,0 +1,35 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   i18n_domain="testedsample"
+   package="testedsample"
+   >
+
+  <include package="grok" />
+  <include package="testedsample" />
+
+  <!-- Typical functional testing security setup -->
+  <securityPolicy
+      component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy"
+      />
+
+  <unauthenticatedPrincipal
+      id="zope.anybody"
+      title="Unauthenticated User"
+      />
+  <grant
+      permission="zope.View"
+      principal="zope.anybody"
+      />
+
+  <principal
+      id="zope.mgr"
+      title="Manager"
+      login="mgr"
+      password="mgrpw"
+      />
+
+  <role id="zope.Manager" title="Site Manager" />
+  <grantAll role="zope.Manager" />
+  <grant role="zope.Manager" principal="zope.mgr" />
+
+</configure>

Added: Sandbox/luciano/testedsample/src/testedsample/ftests/__init__.py
===================================================================
--- Sandbox/luciano/testedsample/src/testedsample/ftests/__init__.py	                        (rev 0)
+++ Sandbox/luciano/testedsample/src/testedsample/ftests/__init__.py	2007-08-11 14:03:36 UTC (rev 78747)
@@ -0,0 +1 @@
+# this directory is a package

Added: Sandbox/luciano/testedsample/src/testedsample/ftests/index.txt
===================================================================
--- Sandbox/luciano/testedsample/src/testedsample/ftests/index.txt	                        (rev 0)
+++ Sandbox/luciano/testedsample/src/testedsample/ftests/index.txt	2007-08-11 14:03:36 UTC (rev 78747)
@@ -0,0 +1,30 @@
+Use the Grok admin UI to create an instance of the app::
+
+  >>> browser = Browser()
+  >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+  >>> browser.handleErrors = False
+  >>> browser.open('http://localhost:8080/')                  
+  >>> browser.getControl('Application').displayValue = ['testedsample.app.TestedSample']
+  >>> browser.getControl('Name').value = 'sample01'
+  >>> browser.getControl('Add').click()
+
+Navigate to the index page and verify its contents::
+
+  >>> browser.getLink('sample01').click()
+  >>> "Your Grok application is up and running." in browser.contents
+  True
+
+The default Grok app is also a container, but initially it's empty:: 
+
+  >>> root = getRootFolder()
+  >>> sample = root['sample01']
+  >>> print sample.keys()
+  <OOBTreeItems object at ...>
+  >>> print len(sample.keys())
+  0
+
+To test your sample app with this doctest, run::
+
+  $ sample/bin/test 
+
+  

Added: Sandbox/luciano/testedsample/src/testedsample/ftests/test_functional.py
===================================================================
--- Sandbox/luciano/testedsample/src/testedsample/ftests/test_functional.py	                        (rev 0)
+++ Sandbox/luciano/testedsample/src/testedsample/ftests/test_functional.py	2007-08-11 14:03:36 UTC (rev 78747)
@@ -0,0 +1,31 @@
+import os
+import unittest
+import testedsample
+from zope.testing import doctest
+from zope.app.testing.functional import (FunctionalTestSetup, ZCMLLayer,
+                                         getRootFolder, FunctionalDocFileSuite)
+import zope.testbrowser.browser
+import zope.testbrowser.testing
+
+ftesting_zcml = os.path.join(os.path.dirname(testedsample.__file__), 'ftesting.zcml')
+TestedSampleFunctionalLayer = ZCMLLayer(ftesting_zcml, __name__, 'TestedSampleFunctionalLayer')
+
+def test_suite():
+    suite = unittest.TestSuite()
+    docfiles = ['index.txt']
+
+    for docfile in docfiles:
+        test = FunctionalDocFileSuite(
+             docfile,
+             globs=dict(getRootFolder=getRootFolder, Browser=zope.testbrowser.testing.Browser),
+             optionflags = (doctest.ELLIPSIS
+                            | doctest.REPORT_NDIFF
+                            | doctest.NORMALIZE_WHITESPACE),)
+        test.layer = TestedSampleFunctionalLayer
+        suite.addTest(test)
+
+    return suite
+
+if __name__ == '__main__':
+    unittest.main()
+

Added: Sandbox/luciano/testedsample/src/testedsample/testing.py
===================================================================
--- Sandbox/luciano/testedsample/src/testedsample/testing.py	                        (rev 0)
+++ Sandbox/luciano/testedsample/src/testedsample/testing.py	2007-08-11 14:03:36 UTC (rev 78747)
@@ -0,0 +1,7 @@
+import os.path
+import testedsample
+from zope.app.testing.functional import ZCMLLayer
+
+ftesting_zcml = os.path.join(
+    os.path.dirname(testedsample.__file__), 'ftesting.zcml')
+FunctionalLayer = ZCMLLayer(ftesting_zcml, __name__, 'FunctionalLayer')



More information about the Checkins mailing list