Permalink
Browse files

deprecating Bucket.save() in favor of smarter set()

Change-Id: I0cbcd8ea78d77d79cc4a673f5bb310de39325a71
Reviewed-on: http://review.couchbase.org/20165
Reviewed-by: Pavel Paulau <pavel.paulau@gmail.com>
Tested-by: Benjamin Young <benjamin@couchbase.com>
  • Loading branch information...
1 parent 6672975 commit a9130a81e8097c4aa1cb01cae5b5721e6969e876 @BigBlueHat BigBlueHat committed with Benjamin Young Aug 25, 2012
Showing with 24 additions and 5 deletions.
  1. +3 −5 couchbase/client.py
  2. +21 −0 couchbase/tests/test_client.py
View
@@ -251,6 +251,8 @@ def delete(self, key, cas=0):
return self.mc_client.delete(key, cas)
def save(self, document):
+ warnings.warn("save is deprecated; use set instead",
+ DeprecationWarning)
value = deepcopy(document)
if '_id' in value:
key = value['_id']
@@ -269,11 +271,7 @@ def save(self, document):
expiration = 0
if key.startswith('_design/'):
- # this is a design doc, we need to handle it differently
- view = key.split('/')[1]
-
- rest = self.server._rest()
- rest.create_design_doc(self.name, view, json.dumps(value))
+ self[key] = value
else:
if '_rev' in value:
# couchbase works in clobber mode so for "set" _rev is useless
@@ -239,6 +239,27 @@ def test_gat(self):
self.assertTrue(self.client.get(key)[2] == value)
self.client.delete(key)
+ @attr(cbv="2.0.0")
+ def test_save(self):
+ """Test deprecated save() method"""
+ # test memcached key/value "saving"
+ key = self.client.save({'_id': 'testing_save', 'name': 'Couchbase'})
+ self.assertEqual(key, 'testing_save')
+ self.client.delete('testing_save')
+ # test ddoc handling
+ design_doc = {"_id": "_design/testing_save_ddoc",
+ "views":
+ {"testing":
+ {"map":
+ "function(doc) { emit(doc.name, doc.num); }"
+ }
+ }
+ }
+ key = self.client.save(design_doc)
+ self.assertEqual(key, '_design/testing_save_ddoc')
+ rest = self.client.server._rest()
+ rest.delete_design_doc(self.client.name, 'testing_save_ddoc')
+
@attr(cbv="1.0.0")
def test_setitem(self):
# test int

0 comments on commit a9130a8

Please sign in to comment.