[Checkins] SVN: grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/ We can't test require in a functional test.

Souheil CHELFOUH souheil at chelfouh.com
Fri Mar 18 07:19:24 EDT 2011


Log message for revision 121027:
  We can't test require in a functional test.
  That would be assuming that the app can handle authentication.
  We have currently no such things.
  
  Using now infrae.testbrowser
  

Changed:
  U   grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros.py
  D   grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/require.py
  U   grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/view.py

-=-
Modified: grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros.py	2011-03-18 10:54:00 UTC (rev 121026)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/macros.py	2011-03-18 11:19:23 UTC (rev 121027)
@@ -1,10 +1,13 @@
 """
-  >>> getRootFolder()["manfred"] = Mammoth()
+  >>> root = getRootFolder()
+  >>> application = getApplication()
+  >>> root["manfred"] = Mammoth()
 
-  >>> from zope.app.wsgi.testlayer import Browser
-  >>> browser = Browser()
-  >>> browser.handleErrors = False
-  >>> browser.open("http://localhost/manfred/@@painting")
+  >>> from infrae.testbrowser.browser import Browser
+  >>> browser = Browser(application)
+  >>> browser.options.handle_errors = False
+
+  >>> browser("http://localhost/manfred/@@painting")
   >>> print browser.contents
   <html>
   <body>
@@ -17,14 +20,14 @@
 
 Views without a template do not support macros:
 
-  >>> browser.open("http://localhost/manfred/@@dancing")
+  >>> browser("http://localhost/manfred/@@dancing")
   Traceback (most recent call last):
   AttributeError: 'DancingHall' object has no attribute 'template'
 
 If the view has an attribute with the same name as a macro, the macro
 shadows the view. XXX This should probably generate a warning at runtime.
 
-  >>> browser.open("http://localhost/manfred/@@grilldish")
+  >>> browser("http://localhost/manfred/@@grilldish")
   >>> print browser.contents
   <html>
   Curry
@@ -37,7 +40,7 @@
   >>> saved_warn = warnings.warn
   >>> warnings.warn = warn
 
-  >>> browser.open("http://localhost/manfred/@@burnt")
+  >>> browser("http://localhost/manfred/@@burnt")
   From grok.testing's warn():
   ... DeprecationWarning: Calling macros directly on the view is deprecated. Please use context/@@viewname/macros/macroname
   ...
@@ -55,7 +58,7 @@
   >>> before = open(template_file, 'r').read()
   >>> changed = before.replace('GROK', 'GROK RELOADED')
   >>> open(template_file, 'w').write(changed)
-  >>> browser.open("http://localhost/manfred/@@painting")
+  >>> browser("http://localhost/manfred/@@painting")
   >>> print browser.contents
   <html>
   <body>

Deleted: grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/require.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/require.py	2011-03-18 10:54:00 UTC (rev 121026)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/require.py	2011-03-18 11:19:23 UTC (rev 121027)
@@ -1,48 +0,0 @@
-"""
-Viewing a protected view with insufficient privileges will yield
-Unauthorized:
-
-  >>> from zope.app.wsgi.testlayer import Browser
-  >>> browser = Browser()
-  >>> browser.open("http://localhost/@@painting")
-  Traceback (most recent call last):
-  HTTPError: HTTP Error 401: Unauthorized
-
-When we log in (e.g. as a manager), we can access the view just fine:
-
-  >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
-  >>> browser.handleErrors = False
-  >>> browser.open("http://localhost/@@painting")
-  >>> print browser.contents
-  What a beautiful painting.
-
-A view protected with 'zope.Public' is always accessible:
-
-  >>> browser = Browser()
-  >>> browser.open("http://localhost/@@publicnudity")
-  >>> print browser.contents
-  Everybody can see this.
-"""
-
-import grokcore.view as grok
-import zope.interface
-
-
-class ViewPainting(grok.Permission):
-    grok.name('cave.ViewPainting')
-
-
-class Painting(grok.View):
-    grok.context(zope.interface.Interface)
-    grok.require(ViewPainting)
-
-    def render(self):
-        return 'What a beautiful painting.'
-
-
-class PublicNudity(grok.View):
-    grok.context(zope.interface.Interface)
-    grok.require(grok.Public)
-
-    def render(self):
-        return 'Everybody can see this.'

Modified: grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/view.py
===================================================================
--- grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/view.py	2011-03-18 10:54:00 UTC (rev 121026)
+++ grokcore.view/branches/zca-only/src/grokcore/view/ftests/view/view.py	2011-03-18 11:19:23 UTC (rev 121027)
@@ -1,8 +1,6 @@
 """
   >>> root = getRootFolder()
   >>> application = getApplication()
-
-  
   >>> root["manfred"] = Mammoth()
 
   >>> from infrae.testbrowser.browser import Browser



More information about the checkins mailing list