[z3-checkins] r41943 - in z3/deliverance/DeliveranceVHoster/trunk: docs dvhoster tests

ianb at codespeak.net ianb at codespeak.net
Fri Apr 6 19:37:59 CEST 2007


Author: ianb
Date: Fri Apr  6 19:37:59 2007
New Revision: 41943

Modified:
   z3/deliverance/DeliveranceVHoster/trunk/docs/rest-api.txt
   z3/deliverance/DeliveranceVHoster/trunk/dvhoster/model.py
   z3/deliverance/DeliveranceVHoster/trunk/tests/test_functional_api.py
Log:
Added POST methods for remote_uris setting

Modified: z3/deliverance/DeliveranceVHoster/trunk/docs/rest-api.txt
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/docs/rest-api.txt	(original)
+++ z3/deliverance/DeliveranceVHoster/trunk/docs/rest-api.txt	Fri Apr  6 19:37:59 2007
@@ -88,6 +88,12 @@
   can do this with a `hook <hook.html>`_, or otherwise all requests
   (except to this configuration API) will fail.
 
+``/.deliverance/remote_uris?{add or remove}``
+
+  You can post to one of these resources to add or remove items from
+  the list, without effecting other parts of the list.  Each takes a
+  JSON list.  With ``?add`` the list extends the current items.
+
 ``/.deliverance/addition_request_headers``
 
   A JSON structure looking like::

Modified: z3/deliverance/DeliveranceVHoster/trunk/dvhoster/model.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/dvhoster/model.py	(original)
+++ z3/deliverance/DeliveranceVHoster/trunk/dvhoster/model.py	Fri Apr  6 19:37:59 2007
@@ -4,7 +4,7 @@
 from ohm import server
 from ohm import descriptors
 from ohm import lildav
-from ohm.validators import LineConverter
+from ohm.validators import LineConverter, JSONConverter
 from formencode import validators
 from formencode.foreach import ForEach
 from formencode.compound import All
@@ -338,6 +338,34 @@
     DomainInfo object.
     """
 
+    def add_remote_uris(self, body):
+        validator = RemoteURIValidator()
+        body = validator.to_python(body)
+        self.remote_uris = validator.to_python(self.remote_uris + body)
+
+    def remove_remote_uris(self, body):
+        cur = self.remote_uris
+        for item in body:
+            path = item['path']
+            # Normalization that normally RemoteURIValidator does:
+            if not path.endswith('/'):
+                item['path'] = path = path + '/'
+            for existing in cur:
+                if existing['path'] == path:
+                    # Found a match
+                    break
+            else:
+                raise ValueError(
+                    "There's no current remote_uri matching %r "
+                    "(of paths: %s)" %
+                    (path, ', '.join([repr(e['path']) for e in cur])))
+        for item in body:
+            path = item['path']
+            for existing in cur[:]:
+                if existing['path'] == path:
+                    cur.remove(existing)
+        self.remote_uris = cur
+
     theme_uri = server.Setter(
         validator=validators.URL())
     domain = server.Setter(
@@ -345,7 +373,9 @@
     aliases = server.Setter(
         validator=All(ForEach(DomainValidator()), LineConverter()))
     remote_uris = server.JSONSetter(
-        validator=RemoteURIValidator())
+        validator=RemoteURIValidator(),
+        POST={'add': (JSONConverter(), add_remote_uris),
+              'remove': (JSONConverter(), remove_remote_uris)})
     redirects = server.JSONSetter(
         validator=RewriteValidator())
     additional_request_headers = server.JSONSetter(

Modified: z3/deliverance/DeliveranceVHoster/trunk/tests/test_functional_api.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/tests/test_functional_api.py	(original)
+++ z3/deliverance/DeliveranceVHoster/trunk/tests/test_functional_api.py	Fri Apr  6 19:37:59 2007
@@ -9,6 +9,7 @@
     setattr(httplib.HTTPConnection, attr,
             getattr(wsgi_intercept.WSGI_HTTPConnection, attr).im_func)
 from wsgifilter.proxyapp import DebugHeaders
+from simplejson import loads as json_loads
 
 data_filename = os.path.join(os.path.dirname(__file__), 'test-data')
 wsgi_app = make_app({}, data_dir=data_filename)
@@ -90,6 +91,20 @@
     res = app.get('/testme/', status=200)
     res.mustcontain("HTTP_X_TEST_ME: 'testme'")
 
+    # Now lets try adding and removing via POST
+    app.post('/.deliverance/remote_uris?add',
+             '[{"path": "/testpost", "remote_uri": "http://blah.com"}]',
+             status=204)
+    res = app.get('/.deliverance/remote_uris')
+    res.mustcontain('testpost')
+    app.post('/.deliverance/remote_uris?remove',
+             '[{"path": "/testpost"}]',
+             status=204)
+    res = app.get('/.deliverance/remote_uris')
+    data = json_loads(res.body)
+    for item in data:
+        assert not item['path'].startswith('/testpost')
+
     data = '''
     [{"path": "/test1.html", "rewrite": "/test1"},
      {"prefix": "/test2", "rewrite": "/test3", "comment": "rename"},


More information about the z3-checkins mailing list