diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2012-03-30 15:52:15 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2012-03-30 15:52:15 (GMT) |
commit | 7affd574eb36099f0fbd7baa4c5fe60f42350aa4 (patch) | |
tree | 2e31f455b521fbfc85653671ad1a103d7f4a829d | |
parent | 3dc7789c7daef4a19a21ee8e84992f6b0979a664 (diff) |
Restoring vote property from memory cache should not mark object as fetched from the server
-rwxr-xr-x | examples/client.py | 2 | ||||
-rw-r--r-- | sugar_network/client.py | 6 | ||||
-rwxr-xr-x | tests/units/client.py | 15 |
3 files changed, 19 insertions, 4 deletions
diff --git a/examples/client.py b/examples/client.py index 9a7c337..63f5ebe 100755 --- a/examples/client.py +++ b/examples/client.py @@ -81,7 +81,7 @@ def main(): context = Context(guids[0]) context['vote'] = True context.post() - assert Context(guids[0])['vote'] is True + assert Context(guids[0])['vote'] # Wait until server will update index, # fulltext search does not work for cahced changes diff --git a/sugar_network/client.py b/sugar_network/client.py index 932c677..85b411c 100644 --- a/sugar_network/client.py +++ b/sugar_network/client.py @@ -276,10 +276,8 @@ class Object(dict): if self._path and not self._got: properties = self._fetch(prop) - print '>', prop, properties properties.update(self) self.update(properties) - self._got = True result = self.get(prop) enforce(result is not None, KeyError, @@ -309,7 +307,9 @@ class Object(dict): if self._reply and prop in self._reply: params = {'reply': ','.join(self._reply)} - return http.request('GET', self._path, params=params) + result = http.request('GET', self._path, params=params) + self._got = True + return result def _update_cache(self): cached = self._cache.get(self['guid']) diff --git a/tests/units/client.py b/tests/units/client.py index 2729903..ab30ead 100755 --- a/tests/units/client.py +++ b/tests/units/client.py @@ -288,6 +288,21 @@ class ClientTest(tests.Test): self.assertEqual(True, client.Object('resource', {'guid': 'guid'})['vote']) self.assertEqual([], self.requests[1:]) + def test_Object_MemoryCache_DoNotMarkObjectAsFetched(self): + client.Object.memory_cache['resource'] = {'vote': (1, None)} + self.responses.append({'prop': 'value'}) + + obj = client.Object('resource', {'guid': 'guid'}) + self.assertEqual(1, obj['vote']) + self.assertEqual([], self.requests) + + self.assertEqual('value', obj['prop']) + self.assertEqual( + [ + ('GET', '/resource/guid', None), + ], + self.requests) + if __name__ == '__main__': tests.main() |