Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added design_docs listing to Bucket

This function uses the /ddocs API introduced around
build 1554 (which introduces the doc/meta combination
in MapReduce and document responses (in Views & CRUD)

Change-Id: Ic4aa183842bbcaa188507cad92265b0a064731f1
Reviewed-on: http://review.couchbase.org/19883
Reviewed-by: Pavel Paulau <pavel.paulau@gmail.com>
Tested-by: Benjamin Young <benjamin@couchbase.com>
  • Loading branch information...
commit dd1ab7d7f2a72fd32dc02ab6c31da8fab4eeab02 1 parent d7049ed
@BigBlueHat BigBlueHat authored BigBlueHat committed
View
13 couchbase/client.py
@@ -321,3 +321,16 @@ def view(self, view, **options):
return results['rows']
else:
return None
+
+ def design_docs(self):
+ """List all design documents and return DesignDoc objects for each"""
+ (ip, port, _, _) = self.server._rest_info()
+ api = ''.join(['http://{0}:{1}/pools/default/buckets/{2}/ddocs' \
+ .format(ip, port, self.name)])
+ r = requests.get(api, auth=(self.server.rest_username,
+ self.server.rest_password))
+ ddocs = []
+ for ddoc in r.json.get('rows'):
+ ddocs.append({ddoc['doc']['meta']['id']: ddoc['doc']['json']})
+
+ return ddocs
View
4 couchbase/rest_client.py
@@ -219,10 +219,6 @@ def delete_design_doc(self, bucket, design_doc):
raise Exception(design_doc["error"] + " because "
+ design_doc["reason"])
else:
- rev = design_doc["_rev"]
- #pass in the rev
- api = api + "?rev=%s" % (rev)
-
headers = self._create_capi_headers()
status, content = self._http_request(api, 'DELETE',
headers=headers,
View
21 couchbase/tests/test_client.py
@@ -242,5 +242,26 @@ def test_setitem(self):
# but come out as strings for now
self.assertEqual(self.client['json'][2], json.dumps({'json':'obj'}))
+ @attr(cbv="2.0.0")
+ def test_design_docs(self):
+ # set up some docs we can find
+ for i in range(0, 10):
+ self.client['doc' + str(i)] = {'name': 'doc' + str(i), 'num': i}
+
+ design_doc = json.dumps({"views":
+ {"testing":
+ {"map":
+ "function(doc) { emit(doc.name, doc.num); }"
+ }
+ }
+ })
+ rest = self.client.server._rest()
+ if rest.couch_api_base is None:
+ raise SkipTest
+ rest.create_design_doc(self.client.name, 'test_ddoc', design_doc)
+ ddocs = self.client.design_docs()
+ self.assertIsInstance(ddocs, types.ListType)
+ self.assertEqual(ddocs[0].keys()[0], '_design/test_ddoc')
+
if __name__ == "__main__":
unittest.main()
Please sign in to comment.
Something went wrong with that request. Please try again.