From d65ca2dd221321055b993ed3f6774e94129e0aca Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Fri, 05 Oct 2012 18:20:33 +0000 Subject: Create local Artifact guids as sugar-datastore does to not break ds clients --- diff --git a/sugar_network/local/dbus_datastore.py b/sugar_network/local/dbus_datastore.py index 815af9c..00cfee9 100644 --- a/sugar_network/local/dbus_datastore.py +++ b/sugar_network/local/dbus_datastore.py @@ -15,6 +15,7 @@ import os import time +import uuid import tempfile from cStringIO import StringIO from os.path import exists @@ -77,9 +78,12 @@ 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): + # XXX sugar-datastore clients, like Scratch, might rely on having + # particular GUID size, so, do the same what sugar-datastore does + props['uid'] = str(uuid.uuid4()) props['timestamp'] = int(props.get('timestamp', 0) or time.time()) self._update('POST', props, file_path, transfer_ownership, - reply_cb, error_cb) + reply_cb, error_cb, cmd='create_with_guid') @method(_INTERFACE, in_signature='sa{sv}sb', out_signature='', async_callbacks=('reply_cb', 'error_cb'), byte_arrays=True) @@ -118,7 +122,8 @@ class Datastore(dbus_thread.Service): query = request.get('query') order_by = request.get('order_by') if order_by: - order_by = order_by[0] + if not isinstance(order_by, basestring): + order_by = order_by[0] if order_by[0] in ('+', '-'): # Revert sign for Journal sign = '+' if order_by[0] == '-' else '-' diff --git a/sugar_network/local/mounts.py b/sugar_network/local/mounts.py index cfe9a1e..f5fad31 100644 --- a/sugar_network/local/mounts.py +++ b/sugar_network/local/mounts.py @@ -144,6 +144,14 @@ class HomeMount(LocalMount): def name(self): return _('Home') + @ad.directory_command(method='POST', cmd='create_with_guid', + permissions=ad.ACCESS_AUTH, mime_type='application/json') + def create_with_guid(self, request): + with self._post(request, ad.ACCESS_CREATE) as (directory, doc): + enforce('guid' in doc.props, 'GUID should be specified') + self.before_create(request, doc.props) + return directory.create(doc.props) + @ad.property_command(method='GET', cmd='get_blob', mime_type='application/json') def get_blob(self, document, guid, prop, request=None): diff --git a/tests/units/dbus_datastore.py b/tests/units/dbus_datastore.py index 72398ad..bbf8bcc 100755 --- a/tests/units/dbus_datastore.py +++ b/tests/units/dbus_datastore.py @@ -45,7 +45,7 @@ class DbusDatastoreTest(tests.Test): def test_create_Empty(self): guid = self.ds.create({}, '', False, timeout=3) - + self.assertEqual(5, len(guid.split('-'))) self.assertEqual({ 'uid': guid, 'activity': '', @@ -192,21 +192,12 @@ class DbusDatastoreTest(tests.Test): sorted(entries)) # offset/limit - entries, total = self.ds.find({'offset': 0, 'limit':2}, ['uid', 'title', 'term'], timeout=3) + entries, total = self.ds.find({'offset': 0, 'limit': 2}, ['uid', 'title', 'term'], timeout=3) self.assertEqual(3, total) - self.assertEqual( - sorted([ - {'uid': guid_1, 'title': 'title-1', 'term': 'value-1'}, - {'uid': guid_2, 'title': 'title-2', 'term': 'value-2'}, - ]), - sorted(entries)) + self.assertEqual(2, len(entries)) entries, total = self.ds.find({'offset': 2, 'limit':2}, ['uid', 'title', 'term'], timeout=3) self.assertEqual(3, total) - self.assertEqual( - sorted([ - {'uid': guid_3, 'title': 'title-3', 'term': 'value-3'}, - ]), - sorted(entries)) + self.assertEqual(1, len(entries)) # fulltext search entries, total = self.ds.find({'query': 'title'}, ['uid', 'title', 'term'], timeout=3) @@ -257,11 +248,16 @@ class DbusDatastoreTest(tests.Test): entries) # order by not mapped property - entries, total = self.ds.find({'order_by': '+title'}, ['uid'], timeout=3) + entries, total = self.ds.find({'order_by': 'title'}, ['uid'], timeout=3) self.assertEqual(3, total) self.assertEqual( [{'uid': guid_1}, {'uid': guid_2}, {'uid': guid_3}], entries) + entries, total = self.ds.find({'order_by': ['+title']}, ['uid'], timeout=3) + self.assertEqual(3, total) + self.assertEqual( + [{'uid': guid_3}, {'uid': guid_2}, {'uid': guid_1}], + entries) entries, total = self.ds.find({'order_by': '-title'}, ['uid'], timeout=3) self.assertEqual(3, total) self.assertEqual( -- cgit v0.9.1