Permalink
Browse files

added __getitem__ handling of DesignDocs

Change-Id: I9bc3ca759af425d65b5fa22713a469766ba4f043
Reviewed-on: http://review.couchbase.org/20125
Reviewed-by: Pavel Paulau <pavel.paulau@gmail.com>
Tested-by: Benjamin Young <benjamin@couchbase.com>
  • Loading branch information...
1 parent fad95e2 commit 6672975c5b8dcfacda230f6c4aba83486b8c8c5a @BigBlueHat BigBlueHat committed with Benjamin Young Aug 24, 2012
Showing with 24 additions and 2 deletions.
  1. +6 −1 couchbase/client.py
  2. +18 −1 couchbase/tests/test_client.py
View
@@ -301,7 +301,12 @@ def __setitem__(self, key, value):
self.set(key, 0, 0, value)
def __getitem__(self, key):
- return self.get(key)
+ if key.startswith("_design/"):
+ rest = self.server._rest()
+ doc = rest.get_design_doc(self.name, key[8:])
+ return DesignDoc(key[8:], doc, self)
+ else:
+ return self.get(key)
def view(self, view, **options):
params = deepcopy(options)
@@ -25,7 +25,7 @@
from nose.plugins.skip import SkipTest
from nose.tools import nottest
-from couchbase.client import Couchbase, Server, Bucket
+from couchbase.client import Couchbase, Server, Bucket, DesignDoc
from couchbase.couchbaseclient \
import CouchbaseClient, VBucketAwareCouchbaseClient
from couchbase.tests.base import Base
@@ -260,6 +260,23 @@ def test_setitem(self):
self.client.delete(key)
@attr(cbv="2.0.0")
+ def test_getitem(self):
+ """Test unique _design/doc handling in __getitem__"""
+ ddoc_name = 'test_ddoc'
+ design_doc = {"views":
+ {"testing":
+ {"map":
+ "function(doc) { emit(doc.name, doc.num); }"
+ }
+ }
+ }
+ rest = self.client.server._rest()
+ rest.create_design_doc(self.client.name, ddoc_name,
+ json.dumps(design_doc))
+ self.assertIsInstance(self.client['_design/' + ddoc_name], DesignDoc)
+ rest.delete_design_doc(self.client.name, ddoc_name)
+
+ @attr(cbv="2.0.0")
def test_view(self):
design_doc = {"views":
{"testing":

0 comments on commit 6672975

Please sign in to comment.