Permalink
Browse files

improved reduced results handling; PYCBC-7 tests

One TODO was added for binary protocal handing of
include_docs (currently that is done over HTTP).

Change-Id: I8d85c4b619ba21d135e72c5527852ea522da877a
Reviewed-on: http://review.couchbase.org/20275
Tested-by: Benjamin Young <benjamin@couchbase.com>
Reviewed-by: Benjamin Young <benjamin@couchbase.com>
  • Loading branch information...
1 parent bc33db3 commit c85e90d71bfe4ce8eb2f148c53aa3b5eadaca3a6 @BigBlueHat BigBlueHat committed with Benjamin Young Aug 28, 2012
Showing with 28 additions and 5 deletions.
  1. +8 −2 couchbase/client.py
  2. +20 −3 couchbase/tests/test_client.py
View
@@ -440,5 +440,11 @@ def results(self, params={}):
" results"
rest = self.ddoc.bucket.server._rest()
- return rest.view_results(self.ddoc.bucket.name, self.ddoc.name,
- self.name, params)['rows']
+ results = rest.view_results(self.ddoc.bucket.name, self.ddoc.name,
+ self.name, params)['rows']
+
+ # results were reduced, so return just the reduced value
+ if len(results) == 1 and results[0]['key'] is None:
+ return results[0]['value']
+ else:
+ return results
@@ -384,7 +384,12 @@ def setUp(self):
self.ddoc = {"views":
{"testing":
{"map":
- "function(doc) { emit(doc.name, doc.num); }"
+ """function(doc, meta) {
+ if (meta.type === 'json' && doc.name) {
+ emit(doc.name, doc.num);
+ }
+ }""",
+ "reduce": "_count"
}
}
}
@@ -396,14 +401,15 @@ def tearDown(self):
self.rest.delete_design_doc(self.client.name, 'test_ddoc')
def test_views(self):
+ """List views from a given cluster. PYCBC-7"""
views = self.design_docs[0].views()
self.assertIsInstance(views, types.ListType)
self.assertIn('testing', views)
self.assertIn(self.ddoc['views'], views)
@attr(cbv="2.0.0")
def test_getitem(self):
-
+ """Instantiate an Object that represents a view. PYCBC-7"""
view = self.design_docs[0]['testing']
self.assertIsInstance(view, View)
@@ -423,16 +429,27 @@ def teardown_sample_docs(self):
@attr(cbv="2.0.0")
def test_results(self):
+ """Test retrieval of view results"""
self.setup_sample_docs()
view = self.design_docs[0]['testing']
+ # Retrieve reduced results from a View. PYCBC-7
+ # (the format is the same, but there is no associated docid)
results = view.results({'stale': False})
+ self.assertIs(results, 10)
+ # Assemble query parameters for a View. PYCBC-7
+ results = view.results({'stale': False, 'reduce': False})
if "error" in results:
self.fail(results)
else:
self.assertIsInstance(results, types.ListType)
self.assertIs(len(results), 10)
# test again with include_docs=true
- results = view.results({'stale': False, 'include_docs': True})
+ # Retrieve non-reduced results from a View. PYCBC-7
+ # Be able to get the underlying document from the non-reduced results
+ # (this request should flow over binprot)
+ # TODO: upgrade to use binary protocol rather than HTTP-based one
+ results = view.results({'stale': False, 'include_docs': True,
+ 'reduce': False})
if "error" in results:
self.fail(results)
else:

0 comments on commit c85e90d

Please sign in to comment.