Permalink
Browse files

added subscript View access

Change-Id: I31ca45e4168bf9c56d013cc0647c262f60ab00ec
Reviewed-on: http://review.couchbase.org/20345
Reviewed-by: Pavel Paulau <pavel.paulau@gmail.com>
Tested-by: Benjamin Young <benjamin@couchbase.com>
  • Loading branch information...
BigBlueHat authored and Benjamin Young committed Aug 29, 2012
1 parent 47a01a5 commit f4a1e71ac9a11f068b141f2de1ccad5eddc0b338
Showing with 12 additions and 3 deletions.
  1. +3 −0 couchbase/client.py
  2. +8 −2 couchbase/tests/test_client.py
  3. +1 −1 couchbase/tests/test_readme_examples.py
View
@@ -388,6 +388,9 @@ def __eq__(self, other):
def __neq__(self, other):
return not self.__eq__(other)
+ def __getitem__(self, name):
+ return View(name, self.ddoc['views'][name], self)
+
def views(self):
return [View(view, self.ddoc['views'][view], self)
for view in self.ddoc['views']]
@@ -25,7 +25,7 @@
from nose.plugins.skip import SkipTest
from nose.tools import nottest
-from couchbase.client import Couchbase, Server, Bucket, DesignDoc
+from couchbase.client import Couchbase, Server, Bucket, DesignDoc, View
from couchbase.couchbaseclient \
import CouchbaseClient, VBucketAwareCouchbaseClient
from couchbase.tests.base import Base
@@ -401,6 +401,12 @@ def test_views(self):
self.assertIn('testing', views)
self.assertIn(self.ddoc['views'], views)
+ @attr(cbv="2.0.0")
+ def test_getitem(self):
+ map = {"map": "function(doc) { emit(doc.name, doc.num); }"}
+ view = self.design_docs[0]['testing']
+ self.assertIsInstance(view, View)
+
class ViewTest(DesignDocTest):
@nottest
@@ -418,7 +424,7 @@ def teardown_sample_docs(self):
@attr(cbv="2.0.0")
def test_results(self):
self.setup_sample_docs()
- view = self.design_docs[0].views()[0]
+ view = self.design_docs[0]['testing']
results = view.results({'stale': False})
if "error" in results:
self.fail(results)
@@ -93,7 +93,7 @@ def test_old_unified_client_example(self):
# save a design document
newbucket['_design/testing'] = design_doc
- all_by_types_view = newbucket['_design/testing'].views()[0]
+ all_by_types_view = newbucket['_design/testing']['all_by_types']
rows = all_by_types_view.results({'stale': False})
for row in rows:
self.assertTrue(row is not None)

0 comments on commit f4a1e71

Please sign in to comment.