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):
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)
+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
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
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)
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)