[Checkins] SVN: grok/branches/timte-json/src/grok/tests/ Added tests for json support.

Tim Terlegård tim.terlegard at lovelysystems.com
Sun Apr 1 05:19:51 EDT 2007


Log message for revision 73961:
  Added tests for json support.
  

Changed:
  A   grok/branches/timte-json/src/grok/tests/json/
  A   grok/branches/timte-json/src/grok/tests/json/__init__.py
  A   grok/branches/timte-json/src/grok/tests/json/nocontext.py
  A   grok/branches/timte-json/src/grok/tests/json/view_lookup.py
  A   grok/branches/timte-json/src/grok/tests/security/multiple_require_json.py
  U   grok/branches/timte-json/src/grok/tests/test_grok.py

-=-
Added: grok/branches/timte-json/src/grok/tests/json/__init__.py
===================================================================
--- grok/branches/timte-json/src/grok/tests/json/__init__.py	2007-04-01 08:26:57 UTC (rev 73960)
+++ grok/branches/timte-json/src/grok/tests/json/__init__.py	2007-04-01 09:19:50 UTC (rev 73961)
@@ -0,0 +1 @@
+# this is a package

Added: grok/branches/timte-json/src/grok/tests/json/nocontext.py
===================================================================
--- grok/branches/timte-json/src/grok/tests/json/nocontext.py	2007-04-01 08:26:57 UTC (rev 73960)
+++ grok/branches/timte-json/src/grok/tests/json/nocontext.py	2007-04-01 09:19:50 UTC (rev 73961)
@@ -0,0 +1,16 @@
+"""
+
+Context-determination follows the same rules as for adapters. We just check
+whether it's hooked up at all:
+
+  >>> grok.grok(__name__)
+  Traceback (most recent call last):
+    ...
+  GrokError: No module-level context for
+  <class 'grok.tests.json.nocontext.TestJSON'>, please use grok.context.
+
+"""
+import grok
+
+class TestJSON(grok.JSON):
+    pass

Added: grok/branches/timte-json/src/grok/tests/json/view_lookup.py
===================================================================
--- grok/branches/timte-json/src/grok/tests/json/view_lookup.py	2007-04-01 08:26:57 UTC (rev 73960)
+++ grok/branches/timte-json/src/grok/tests/json/view_lookup.py	2007-04-01 09:19:50 UTC (rev 73961)
@@ -0,0 +1,28 @@
+"""
+
+The JSON grokker registers a view for each method of the JSON class.
+So we should be able to search for view by method name.
+
+  >>> grok.grok(__name__)
+  >>> mammoth = Mammoth()
+  >>> from zope.publisher.browser import TestRequest
+  >>> request = TestRequest()
+  >>> from zope.component import getMultiAdapter
+  >>> view = getMultiAdapter((mammoth, request), name='run')
+
+The 'run' method/view returns json data, but it looks just like python.
+
+  >>> view()
+  '{"me": "grok"}'
+
+"""
+import grok
+
+class Mammoth(grok.Model):
+    pass
+
+class MammothView(grok.JSON):
+    grok.context(Mammoth)
+
+    def run(self):
+        return { 'me': 'grok' }

Added: grok/branches/timte-json/src/grok/tests/security/multiple_require_json.py
===================================================================
--- grok/branches/timte-json/src/grok/tests/security/multiple_require_json.py	2007-04-01 08:26:57 UTC (rev 73960)
+++ grok/branches/timte-json/src/grok/tests/security/multiple_require_json.py	2007-04-01 09:19:50 UTC (rev 73961)
@@ -0,0 +1,21 @@
+"""
+Multiple calls of grok.require in one class are not allowed.
+
+  >>> grok.grok(__name__)
+  Traceback (most recent call last):
+  GrokError: grok.require was called multiple times in <class 'grok.tests.security.multiple_require_json.MultipleJSON'>. It may only be called once on class level.
+
+"""
+import grok
+import zope.interface
+
+grok.define_permission('permission.1')
+grok.define_permission('permission.2')
+
+class MultipleJSON(grok.JSON):
+    grok.context(zope.interface.Interface)
+    grok.require('permission.1')
+    grok.require('permission.2')
+
+    def render(self):
+        pass

Modified: grok/branches/timte-json/src/grok/tests/test_grok.py
===================================================================
--- grok/branches/timte-json/src/grok/tests/test_grok.py	2007-04-01 08:26:57 UTC (rev 73960)
+++ grok/branches/timte-json/src/grok/tests/test_grok.py	2007-04-01 09:19:50 UTC (rev 73961)
@@ -33,7 +33,7 @@
 def test_suite():
     suite = unittest.TestSuite()
     for name in ['adapter', 'error', 'view', 'scan', 'event', 'security',
-                 'zcml', 'static', 'utility', 'xmlrpc', 'container',
+                 'zcml', 'static', 'utility', 'xmlrpc', 'json', 'container',
                  'traversal', 'form', 'site', 'grokker', 'directive', 'util',
                  'baseclass', 'annotation', 'application']:
         suite.addTest(suiteFromPackage(name))



More information about the Checkins mailing list