[Checkins] SVN: z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/ moved sample content from doctest to py class

Roger Ineichen roger at projekt01.ch
Thu Jan 31 12:22:21 EST 2008


Log message for revision 83339:
  moved sample content from doctest to py class
  still no progress....

Changed:
  U   z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/publisher.py
  U   z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/testing.py
  U   z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/tests/retry.txt
  U   z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/tests/test_retry.py

-=-
Modified: z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/publisher.py
===================================================================
--- z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/publisher.py	2008-01-31 16:29:18 UTC (rev 83338)
+++ z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/publisher.py	2008-01-31 17:22:21 UTC (rev 83339)
@@ -76,6 +76,7 @@
     def publishTraverse(self, request, name):
         return getattr(self.context, name)
 
+
 class JSONInputStream(HTTPInputStream):
     def __init__(self, stream, environment):
         self.stream = stream
@@ -89,6 +90,7 @@
         else:
             self.cacheStream = TemporaryFile()
 
+
 class JSONRPCRequest(HTTPRequest):
     """JSON-RPC request implementation based on IHTTPRequest."""
 

Modified: z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/testing.py
===================================================================
--- z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/testing.py	2008-01-31 16:29:18 UTC (rev 83338)
+++ z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/testing.py	2008-01-31 17:22:21 UTC (rev 83339)
@@ -67,6 +67,7 @@
 
         errcode = response.getStatus()
         errmsg = response.getStatusString()
+        
         # This is not the same way that the normal transport deals with the
         # headers.
         headers = response.getHeaders()

Modified: z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/tests/retry.txt
===================================================================
--- z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/tests/retry.txt	2008-01-31 16:29:18 UTC (rev 83338)
+++ z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/tests/retry.txt	2008-01-31 17:22:21 UTC (rev 83339)
@@ -10,42 +10,10 @@
 requests as JSON-RPC. The official mime-type for JSON is "application/json"
 The old content type ``application/json-rpc`` is supported too.
 
-Let's define a content object:
+  >>> from z3c.jsonrpc.tests.test_retry import IDemoContent
+  >>> from z3c.jsonrpc.tests.test_retry import DemoContent
+  >>> from z3c.jsonrpc.tests.test_retry import DemoView
 
-  >>> import zope.interface
-  >>> class IDemoContent(zope.interface.Interface):
-  ...     """Demo content interface."""
-
-  >>> import persistent
-  >>> class DemoContent(persistent.Persistent):
-  ...     """Demo content."""
-  ...     zope.interface.implements(IDemoContent)
-
-And define a JSONRPC method view:
-
-  >>> class Conflict(Exception):
-  ...     pass
-  >>> from zope.publisher.interfaces import Retry
-
-  >>> from z3c.jsonrpc import publisher
-  >>> import sys
-  >>> class DemoView(publisher.MethodPublisher):
-  ...     """Sample JSON view."""
-  ...
-  ...     def fail(self):
-  ...         try:
-  ...             raise Conflict
-  ...         except:
-  ...             raise Retry(sys.exc_info())
-
-Make them available under the fake package ``jsonsamples``:
-
-  >>> import sys
-  >>> sys.modules['custom'] = type('Module', (), {})()
-  >>> sys.modules['custom'].IDemoContent = IDemoContent
-  >>> sys.modules['custom'].DemoContent = DemoContent
-  >>> sys.modules['custom'].DemoView = DemoView
-
 Let's show how we can register a jsonrpc view:
 
   >>> from zope.configuration import xmlconfig
@@ -55,10 +23,10 @@
   ... <configure
   ...     xmlns:z3c="http://namespaces.zope.org/z3c">
   ...   <z3c:jsonrpc
-  ...       for="custom.IDemoContent"
-  ...       class="custom.DemoView"
+  ...       for="z3c.jsonrpc.tests.test_retry.IDemoContent"
+  ...       class="z3c.jsonrpc.tests.test_retry.DemoView"
   ...       permission="zope.Public"
-  ...       methods="fail"
+  ...       methods="goodResult badResult"
   ...       layer="z3c.jsonrpc.testing.IJSONRPCTestSkin"
   ...       />
   ... </configure>
@@ -72,36 +40,37 @@
 
   >>> siteURL = 'http://localhost/++skin++JSONRPCTestSkin'
 
-Now we can call the method from our JSONRPC view:
+Now we can call the method goodResult from our JSONRPC view:
 
   >>> from z3c.jsonrpc import testing
   >>> request = testing.TestRequest()
   >>> demoView = DemoView(content, request)
-  >>> demoView.fail()
+  >>> demoView.goodResult()
+  u'good'
+
+  >>> demoView.badResult()
   Traceback (most recent call last):
   ...
-  Retry: None
+  ConflictError: database conflict error
 
 
-JSON-RPC proxy
---------------
+Raise Retry (handleErrors=False)
+--------------------------------
 
-The jsonrpc package provides also a JSON-RPC proxy implementation. This
-implementation is similar to the one known from xmlrpclib except that it can
-handle JSON instead of XML.
+Now we force to run into Retry error. As you can see the ConflictError is the
+original error of Retry. Note we use handleErrors=False here:
 
-Let's try to call our method called ``hello`` we defined before:
-
   >>> from z3c.jsonrpc.testing import JSONRPCTestProxy
-  >>> proxy = JSONRPCTestProxy(siteURL + '/content')
-  >>> proxy.fail()
-  u'Hello World'
+  >>> proxy = JSONRPCTestProxy(siteURL + '/content', handleErrors=False)
+  >>> proxy.badResult()
+  Traceback (most recent call last):
+  ...
+  Retry: database conflict error
 
 
+TODO: fix this missing 599 status
+---------------------------------
 
-cleanup
--------
-
-Now we need to clean up the custom module.
-
-  >>> del sys.modules['custom']
+  >>> from z3c.jsonrpc.testing import JSONRPCTestProxy
+  >>> proxy = JSONRPCTestProxy(siteURL + '/content')
+  >>> proxy.badResult()

Modified: z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/tests/test_retry.py
===================================================================
--- z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/tests/test_retry.py	2008-01-31 16:29:18 UTC (rev 83338)
+++ z3c.jsonrpc/branches/adamg-retryfix/src/z3c/jsonrpc/tests/test_retry.py	2008-01-31 17:22:21 UTC (rev 83339)
@@ -12,15 +12,40 @@
 #
 ##############################################################################
 """
-$Id:$
+$Id$
 """
 __docformat__ = "reStructuredText"
 
+import sys
 import unittest
+import persistent
+import zope.interface
+from zope.publisher.interfaces import Retry
 from zope.testing import doctest
 from z3c.jsonrpc import testing
+from z3c.jsonrpc import publisher
+from ZODB.POSException import ConflictError
 
 
+class IDemoContent(zope.interface.Interface):
+    """Demo content interface."""
+
+
+class DemoContent(persistent.Persistent):
+    """Demo content."""
+    zope.interface.implements(IDemoContent)
+
+
+class DemoView(publisher.MethodPublisher):
+    """Sample JSON view."""
+
+    def goodResult(self):
+        return u'good'
+
+    def badResult(self):
+        raise ConflictError
+
+
 def test_suite():
     return unittest.TestSuite((
         testing.FunctionalDocFileSuite('retry.txt',



More information about the Checkins mailing list