diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2012-10-03 17:22:53 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2012-10-03 17:22:53 (GMT) |
commit | 7d254fa3bfb796543092b1cec9ca35c2838110e0 (patch) | |
tree | ab5e64ae213480ec009b432ed0516f34aca91d13 | |
parent | cd748b46fbf50818a552d161ace57e26848e6de2 (diff) |
Do not include "guid" to find() reply to make group_by useful
-rw-r--r-- | active_document/volume.py | 7 | ||||
-rwxr-xr-x | tests/units/volume.py | 30 |
2 files changed, 27 insertions, 10 deletions
diff --git a/active_document/volume.py b/active_document/volume.py index c5db936..7e9e166 100644 --- a/active_document/volume.py +++ b/active_document/volume.py @@ -143,10 +143,9 @@ class VolumeCommands(CommandsProcessor): @directory_command(method='GET', arguments={'offset': to_int, 'limit': to_int, 'reply': to_list}, mime_type='application/json') - def find(self, document, request): - reply = request.setdefault('reply', ['guid']) - if 'guid' not in reply: - reply.append('guid') + def find(self, document, reply, request): + if not reply: + request['reply'] = ['guid'] self._preget(request) documents, total = self.volume[document].find(**request) result = [self._get_props(i, request) for i in documents] diff --git a/tests/units/volume.py b/tests/units/volume.py index feb616a..e9577b0 100755 --- a/tests/units/volume.py +++ b/tests/units/volume.py @@ -284,7 +284,7 @@ class VolumeTest(tests.Test): sorted(self.call('GET', document='testdocument', reply=['prop', 'guid'])['result'][0].keys())) self.assertEqual( - sorted(['guid', 'prop']), + sorted(['prop']), sorted(self.call('GET', document='testdocument', reply=['prop'])['result'][0].keys())) def test_Command_NotModifiedGet(self): @@ -407,7 +407,7 @@ class VolumeTest(tests.Test): 'value_ru', self.call('GET', document='testdocument', guid=guid, accept_language=['ru', 'es'], prop='localized_prop')) self.assertEqual( - [{'guid': guid, 'localized_prop': 'value_ru'}], + [{'localized_prop': 'value_ru'}], self.call('GET', document='testdocument', accept_language=['foo', 'ru', 'es'], reply=['localized_prop'])['result']) self.assertEqual( @@ -417,7 +417,7 @@ class VolumeTest(tests.Test): 'value_ru', self.call('GET', document='testdocument', guid=guid, accept_language=['ru-RU', 'es'], prop='localized_prop')) self.assertEqual( - [{'guid': guid, 'localized_prop': 'value_ru'}], + [{'localized_prop': 'value_ru'}], self.call('GET', document='testdocument', accept_language=['foo', 'ru-RU', 'es'], reply=['localized_prop'])['result']) self.assertEqual( @@ -427,7 +427,7 @@ class VolumeTest(tests.Test): 'value_es', self.call('GET', document='testdocument', guid=guid, accept_language=['es', 'ru'], prop='localized_prop')) self.assertEqual( - [{'guid': guid, 'localized_prop': 'value_es'}], + [{'localized_prop': 'value_es'}], self.call('GET', document='testdocument', accept_language=['foo', 'es', 'ru'], reply=['localized_prop'])['result']) self.assertEqual( @@ -437,7 +437,7 @@ class VolumeTest(tests.Test): 'value_en', self.call('GET', document='testdocument', guid=guid, accept_language=['fr', 'za'], prop='localized_prop')) self.assertEqual( - [{'guid': guid, 'localized_prop': 'value_en'}], + [{'localized_prop': 'value_en'}], self.call('GET', document='testdocument', accept_language=['foo', 'fr', 'za'], reply=['localized_prop'])['result']) env.DEFAULT_LANG = 'foo' @@ -450,7 +450,7 @@ class VolumeTest(tests.Test): 'value_%s' % fallback_lang, self.call('GET', document='testdocument', guid=guid, accept_language=['fr', 'za'], prop='localized_prop')) self.assertEqual( - [{'guid': guid, 'localized_prop': 'value_%s' % fallback_lang}], + [{'localized_prop': 'value_%s' % fallback_lang}], self.call('GET', document='testdocument', accept_language=['foo', 'fr', 'za'], reply=['localized_prop'])['result']) def test_LazyOpen(self): @@ -956,6 +956,24 @@ class VolumeTest(tests.Test): coroutine.dispatch() self.assertEqual('0!1!', ''.join(self.call('GET', document='testdocument', guid=guid, prop='blob'))) + def test_Group(self): + + class TestDocument(Document): + + @active_property(slot=1) + def prop(self, value): + return value + + self.volume = SingleVolume(tests.tmpdir, [TestDocument]) + + self.call('POST', document='testdocument', content={'prop': 1}) + self.call('POST', document='testdocument', content={'prop': 2}) + self.call('POST', document='testdocument', content={'prop': 1}) + + self.assertEqual( + sorted([{'prop': '1'}, {'prop': '2'}]), + sorted(self.call('GET', document='testdocument', reply='prop', group_by='prop')['result'])) + def call(self, method, document=None, guid=None, prop=None, accept_language=None, content=None, content_stream=None, if_modified_since=None, **kwargs): |