Skip to content

Commit

Permalink
added __getitem__ handling of DesignDocs
Browse files Browse the repository at this point in the history
Change-Id: I9bc3ca759af425d65b5fa22713a469766ba4f043
Reviewed-on: http://review.couchbase.org/20125
Reviewed-by: Pavel Paulau <[email protected]>
Tested-by: Benjamin Young <[email protected]>
  • Loading branch information
BigBlueHat authored and Benjamin Young committed Aug 28, 2012
1 parent fad95e2 commit 6672975
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion couchbase/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion couchbase/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -259,6 +259,23 @@ def test_setitem(self):
for key in ['int', 'long', 'str', 'json']:
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":
Expand Down

0 comments on commit 6672975

Please sign in to comment.