changeset 3:8c35fbdf5f43

added to tests
author Atul Varma <varmaa@toolness.com>
date Thu, 31 Dec 2009 12:37:24 -0800
parents f9ee6f8f7021
children 78a2da337f9f
files test.py whoisi_cache.py
diffstat 2 files changed, 23 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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)