More tests, more bug fixes
authorEd Page <eopage@byu.net>
Sat, 18 Apr 2009 22:10:03 +0000 (17:10 -0500)
committerEd Page <eopage@byu.net>
Sat, 18 Apr 2009 22:10:03 +0000 (17:10 -0500)
src/cache_backend.py
src/file_backend.py
tests/test_backend.py
tests/test_cache_backend.py
tests/test_file_backend.py

index bc0d6be..c9968ff 100644 (file)
@@ -70,6 +70,7 @@ class LazyCacheBackend(object):
                taskId = self._backend.add_task(projId, taskName)
                self._invalidate_projects_tasks(projId)
                self._invalidate_metaprojects_tasks()
+               self._taskIdToProjId[taskId] = projId
                return taskId
 
        def set_project(self, taskId, newProjId):
index e846f98..78360c2 100644 (file)
@@ -71,7 +71,7 @@ class FileBackend(object):
                return self._locations.itervalues()
 
        def get_tasks_with_details(self, projId):
-               return self._items[projId]
+               return self._items[projId].itervalues()
 
        def get_task_details(self, taskId):
                projId, partialTaskId = self._unpack_ids(taskId)
index 504ae4d..f7f4a42 100644 (file)
@@ -1,7 +1,37 @@
+def assert_projects_same(backend1, backend2):
+       projects1 = list(backend1.get_projects())
+       projects1.sort()
+
+       projects2 = list(backend2.get_projects())
+       projects2.sort()
+
+       assert projects1 == projects2
+
+
+def assert_locations_same(backend1, backend2):
+       locations1 = list(backend1.get_locations())
+       locations1.sort()
+
+       locations2 = list(backend2.get_locations())
+       locations2.sort()
+
+       assert locations1 == locations2
+
+
+def assert_tasks_same(backend1, backend2, projId):
+       tasks1 = list(backend1.get_tasks_with_details(projId))
+       tasks1.sort()
+
+       tasks2 = list(backend2.get_tasks_with_details(projId))
+       tasks2.sort()
+
+       assert tasks1 == tasks2
+
+
 def exercise_projects(backend):
-       PROJECT_1_NAME = "1"
-       PROJECT_1_NEW_NAME = "1_1"
-       PROJECT_2_NAME = "2"
+       PROJECT_1_NAME = "p1"
+       PROJECT_1_NEW_NAME = "p1_1"
+       PROJECT_2_NAME = "p2"
 
        projects = list(backend.get_projects())
        assert len(projects) == 0
@@ -120,3 +150,19 @@ def exercise_projects(backend):
 def exercise_locations(backend):
        locations = list(backend.get_locations())
        assert len(locations) == 0
+
+
+def exercise_task(backend, proj1Id, proj2Id):
+       TASK_1_NAME = "t1"
+       TASK_2_NAME = "t1"
+
+       proj1Tasks = list(backend.get_tasks_with_details(proj1Id))
+       assert len(proj1Tasks) == 0
+       proj2Tasks = list(backend.get_tasks_with_details(proj2Id))
+       assert len(proj2Tasks) == 0
+
+       taskId = backend.add_task(proj1Id, TASK_1_NAME)
+       task = backend.get_task_details(taskId)
+       assert task["name"] == TASK_1_NAME
+       assert task["projId"] == proj1Id
+       assert task["id"] == taskId
index 6d163b9..bd2d35d 100644 (file)
@@ -14,23 +14,26 @@ class TestCacheBackend(object):
        def test_projects(self):
                fileBackend = file_backend.FileBackend(os.tmpnam())
                backend = cache_backend.LazyCacheBackend(fileBackend)
+
                test_backend.exercise_projects(backend)
 
-               # Confirm cache matches actual
-               fileProjects = list(fileBackend.get_projects())
-               fileProjects.sort()
-               cacheProjects = list(backend.get_projects())
-               cacheProjects.sort()
-               assert fileProjects == cacheProjects
+               test_backend.assert_projects_same(fileBackend, backend)
 
        def test_locations(self):
                fileBackend = file_backend.FileBackend(os.tmpnam())
                backend = cache_backend.LazyCacheBackend(fileBackend)
+
                test_backend.exercise_locations(backend)
 
-               # Confirm cache matches actual
-               fileLocations = list(fileBackend.get_locations())
-               fileLocations.sort()
-               cacheLocations = list(backend.get_locations())
-               cacheLocations.sort()
-               assert fileLocations == cacheLocations
+               test_backend.assert_locations_same(fileBackend, backend)
+
+       def test_task(self):
+               fileBackend = file_backend.FileBackend(os.tmpnam())
+               backend = cache_backend.LazyCacheBackend(fileBackend)
+               proj1Id = backend.add_project("p1")
+               proj2Id = backend.add_project("p2")
+
+               test_backend.exercise_task(backend, proj1Id, proj2Id)
+
+               test_backend.assert_tasks_same(fileBackend, backend, proj1Id)
+               test_backend.assert_tasks_same(fileBackend, backend, proj2Id)
index 8fefb83..da18980 100644 (file)
@@ -16,3 +16,9 @@ class TestFileBackend(object):
        def test_locations(self):
                backend = file_backend.FileBackend(os.tmpnam())
                test_backend.exercise_locations(backend)
+
+       def test_task(self):
+               backend = file_backend.FileBackend(os.tmpnam())
+               proj1Id = backend.add_project("p1")
+               proj2Id = backend.add_project("p2")
+               test_backend.exercise_task(backend, proj1Id, proj2Id)