# HG changeset patch # User Atul Varma # Date 1262291844 28800 # Node ID 8c35fbdf5f43654213b3c04dff48eac65b3aa8f4 # Parent f9ee6f8f7021dd34f4b7fb454708cd7cc15ac812 added to tests diff -r f9ee6f8f7021 -r 8c35fbdf5f43 test.py --- a/test.py Thu Dec 31 12:30:18 2009 -0800 +++ b/test.py Thu Dec 31 12:37:24 2009 -0800 @@ -4,23 +4,37 @@ class FakeWhoisiServer(object): def __init__(self, people): - self._people = [None] - self._people.extend(people) + self._people = people def get_max_person_id(self, app): - return len(self._people) - 1 + return len(self._people) def get_people(self, app, first, last): if first == 0: raise ValueError('do not ask for person id 0') if last > self.get_max_person_id(app): raise ValueError('bad last id') - return tuple(self._people[first:last+1]) + return tuple(self._people[first-1:last]) class WhoisiCacheTests(unittest.TestCase): def testUpdateWorks(self): - people = ["a", "b", "c"] + people = [] server = FakeWhoisiServer(people) - cache = whoisi_cache.WhoisiCache(server, batch_size=2) + cache_storage = [] + cache = whoisi_cache.WhoisiCache(server=server, + storage=cache_storage, + batch_size=2) cache.update() - self.assertEqual(people, cache.people) + self.assertEqual(people, cache_storage) + + people.extend(["a", "b", "c"]) + + self.assertNotEqual(people, cache_storage) + cache.update() + self.assertEqual(people, cache_storage) + + people.extend(["d"]) + + self.assertNotEqual(people, cache_storage) + cache.update() + self.assertEqual(people, cache_storage) diff -r f9ee6f8f7021 -r 8c35fbdf5f43 whoisi_cache.py --- a/whoisi_cache.py Thu Dec 31 12:30:18 2009 -0800 +++ b/whoisi_cache.py Thu Dec 31 12:37:24 2009 -0800 @@ -12,10 +12,10 @@ class WhoisiCache(object): APP_NAME = "whoisi-cache" - def __init__(self, server, batch_size=MAX_PEOPLE_REQ_SIZE): + def __init__(self, server, storage, batch_size=MAX_PEOPLE_REQ_SIZE): self.server = server self.batch_size = batch_size - self.people = [] + self.people = storage def update(self): pid = self.server.get_max_person_id(app=self.APP_NAME)