Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2012-07-23 07:18:26 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-07-23 07:18:26 (GMT)
commitac3fdc31224dd033f61a9b33a3fe5e91e7c316bc (patch)
tree9c8ba30591f201e88bf2b69a6ce76aef6a5eda68
parentcee841e7a6bdbdbe32365bf282b73926d1900185 (diff)
DS clients might send GUID while updating jobjects
-rw-r--r--sugar_network/local/dbus_datastore.py21
-rwxr-xr-xtests/units/dbus_datastore.py9
2 files changed, 22 insertions, 8 deletions
diff --git a/sugar_network/local/dbus_datastore.py b/sugar_network/local/dbus_datastore.py
index 8061fac..ed220fa 100644
--- a/sugar_network/local/dbus_datastore.py
+++ b/sugar_network/local/dbus_datastore.py
@@ -75,15 +75,15 @@ class Datastore(dbus_thread.Service):
@method(_INTERFACE, in_signature='a{sv}sb', out_signature='s',
async_callbacks=('reply_cb', 'error_cb'), byte_arrays=True)
def create(self, props, file_path, transfer_ownership, reply_cb, error_cb):
- self._update(props, file_path, transfer_ownership, reply_cb, error_cb,
- method='POST')
+ self._update('POST', props, file_path, transfer_ownership,
+ reply_cb, error_cb)
@method(_INTERFACE, in_signature='sa{sv}sb', out_signature='',
async_callbacks=('reply_cb', 'error_cb'), byte_arrays=True)
def update(self, uid, props, file_path, transfer_ownership,
reply_cb, error_cb):
- self._update(props, file_path, transfer_ownership, reply_cb, error_cb,
- method='PUT', guid=uid)
+ self._update('PUT', props, file_path, transfer_ownership,
+ reply_cb, error_cb, guid=uid)
@method(_INTERFACE, in_signature='a{sv}as', out_signature='aa{sv}u',
async_callbacks=('reply_cb', 'error_cb'))
@@ -195,8 +195,8 @@ class Datastore(dbus_thread.Service):
def unmount(self, mountpoint_id):
pass
- def _update(self, props, file_path, transfer_ownership, reply_cb, error_cb,
- **kwargs):
+ def _update(self, http_method, props, file_path, transfer_ownership,
+ reply_cb, error_cb, **kwargs):
blobs = []
if 'preview' in props:
preview = props.pop('preview')
@@ -216,8 +216,13 @@ class Datastore(dbus_thread.Service):
else:
props['filesize'] = '0'
- self.call(self._set_blob, error_cb, mountpoint='~',
- document='artifact', content=datastore.decode_props(props),
+ props = datastore.decode_props(props)
+ if http_method == 'PUT' and 'guid' in props:
+ # DataStore clients might send guid in updated props
+ props.pop('guid')
+
+ self.call(self._set_blob, error_cb, method=http_method, mountpoint='~',
+ document='artifact', content=props,
args=[kwargs.get('guid'), blobs, reply_cb, error_cb], **kwargs)
def _set_blob(self, reply, guid, blobs, reply_cb, error_cb):
diff --git a/tests/units/dbus_datastore.py b/tests/units/dbus_datastore.py
index 4b0e8f3..68bb08c 100755
--- a/tests/units/dbus_datastore.py
+++ b/tests/units/dbus_datastore.py
@@ -159,6 +159,15 @@ class DbusDatastoreTest(tests.Test):
self.assertEqual('value_3', props.get('prop_1'))
self.assertEqual('value_4', props.get('prop_2'))
+ def test_update_TryToUpdateGuid(self):
+ guid = self.ds.create({}, '', False, timeout=3)
+
+ self.ds.update(guid, {'uid': 'new', 'prop': 'value'}, '', False, timeout=3)
+
+ props = self.ds.get_properties(guid, timeout=3)
+ self.assertEqual(guid, props.get('uid'))
+ self.assertEqual('value', props.get('prop'))
+
def test_find(self):
entries, total = self.ds.find({}, ['uid', 'title', 'term'], timeout=3)
self.assertEqual(0, total)