def test_append_object(self): self.json_db.set([self.task1]) task_list = self.json_db.to_object_list(self.json_db.get(), Task()) self.assertTrue(len(task_list) == 1) self.json_db.append(self.task2) task_list = self.json_db.to_object_list(self.json_db.get(), Task()) self.assertTrue(len(task_list) == 2) self.assertEqual(task_list[0].index, 1) self.assertEqual(task_list[1].index, 2)
def test_replace_object(self): self.json_db.set([self.task1]) task_list = self.json_db.to_object_list(self.json_db.get(), Task()) self.assertTrue(len(task_list) == 1) self.task1.text = "testtask1" self.json_db.replace(self.task1) task_list = self.json_db.to_object_list(self.json_db.get(), Task()) self.assertTrue(len(task_list) == 1) self.assertEqual(self.task1.index, 1) self.assertEqual(self.task1.text, "testtask1")
def replace(self, local_task: Task, remote_task: Task) -> Task: assert isinstance(remote_task, Task) assert isinstance(local_task, Task) remote_task.index = local_task.index remote_task.unique_id = local_task.unique_id remote_task.due_date = local_task.due_date self.replace_object(local_task.index, remote_task) self.logger.debug( f"Replaced local_task: {dict(local_task)} with remote_task: {dict(remote_task)}" ) return remote_task
def test_multiple_insert_using_should_not_create_duplicates(self): self.redis_db.initialize(Task()) self.redis_db.clear() self.redis_db.set([ self.task1, self.task2, self.task3, self.task4, self.task5, self.task6, self.task7, self.task8, self.task9, self.task10 ]) self.redis_db.set([ self.task1, self.task2, self.task3, self.task4, self.task5, self.task6, self.task7, self.task8, self.task9, self.task10 ]) task_list = self.redis_db.to_object_list(self.redis_db.get(), Task()) self.assertTrue(len(task_list) == 10)
def test_object_serialization(self): self.redis_db.initialize(Task()) self.redis_db.clear() self.redis_db.set([self.task1]) task_list = self.redis_db.to_object_list(self.redis_db.get(), Task()) self.assertTrue(len(task_list) == 1) task = task_list[0] self.assertEqual(self.task1.text, task.text) self.assertEqual(self.task1.index, task.index) self.assertEqual(self.task1.unique_id, task.unique_id) self.assertEqual(self.task1.project, task.project) self.assertEqual(self.task1.date_expression, task.date_expression) self.assertEqual(self.task1.priority, task.priority) self.assertEqual(self.task1.label, task.label)
def convert(obj_list: list) -> List[Task]: task_list = list() for obj_dict in obj_list: task = Task(obj_dict["text"]) for key, value in obj_dict.items(): if key == "deleted": value = ast.literal_eval(value) task.deleted = value elif key == "due_date": task.due_date.date_string = value elif key == "done": value = ast.literal_eval(value) task.due_date.completed = value else: setattr(task, key, value) task_list.append(task) return task_list
def test_import_action_can_delete(self): remote_task = Task("Task1") remote_task.external_id = "100" remote_task.deleted = True local_task = Task("Task1") local_task.external_id = "100" local_task.deleted = False action = ImportAction(local_task, remote_task) self.assertTrue(action.can_delete()) self.assertFalse(action.can_update()) self.assertFalse(action.can_insert())
def setUp(self) -> None: self.redis_db = RedisDatabase("localhost", 6379) self.redis_db.clear() self.task1 = Task("task1") self.task1.index = 1 self.task2 = Task("task2") self.task2.index = 2 self.task3 = Task("task3") self.task3.index = 3 self.task4 = Task("task4") self.task4.index = 4 self.task5 = Task("task5") self.task5.index = 5 self.task6 = Task("task6") self.task6.index = 6 self.task7 = Task("task7") self.task7.index = 7 self.task8 = Task("task8") self.task8.index = 8 self.task9 = Task("task9") self.task9.index = 9 self.task10 = Task("task10") self.task10.index = 10
def test_save_object(self): self.redis_db.initialize(Snapshot()) self.assertIsNotNone(self.redis_db.db) snapshot = Snapshot() snapshot.count = 22 self.redis_db.set([snapshot]) snapshot_list = self.redis_db.get() self.assertTrue(len(snapshot_list) == 1) snapshot_dict = snapshot_list[0] self.assertTrue(snapshot_dict["count"] == 22) self.redis_db.initialize(Task()) self.assertIsNotNone(self.redis_db.db) task = Task() task.project = "work" self.redis_db.set([task]) task_list = self.redis_db.get() self.assertTrue(len(task_list) == 1) task_dict = task_list[0] self.assertTrue(task_dict["project"] == "work")
def add(self, text, label, project, date_expression) -> List[Task]: assert type(text) and type(label) and type(project)\ and type(date_expression) is str task_list = list() if self.__date_generator.validate_input(date_expression): for due_date in self.__date_generator.get_due_dates( date_expression): task = Task(text) task.label = label task.project = project task.date_expression = date_expression task.due_date = due_date self.append(task) task_list.append(task) else: raise AttributeError( f"Provided date expression {date_expression} is invalid") return task_list
def setUp(self): self.db = JsonFileDatabase() self.db.initialize(Task()) self.tasks = Tasks(self.db) self.importer = CsvFileImporter(self.tasks)
def test_import_tasks(self): task100 = Task('Task100') task100.label = "added" task100.unique_id = "1" task101 = Task('Task100') task101.label = "updated" task101.deleted = False task101.unique_id = "1" task102 = Task('Task100') task102.deleted = True task102.label = "deleted" task102.unique_id = "1" tasks_list = [task100, task101, task102] sync_results = self.importer.import_tasks(tasks_list) sync_results_list = sync_results.get_list() self.assertTrue(len(sync_results_list) == 3) print(sync_results_list) self.assertTrue(sync_results_list[0] == SyncAction.ADDED) self.assertTrue(sync_results_list[1] == SyncAction.UPDATED) self.assertTrue(sync_results_list[2] == SyncAction.DELETED)
def setUp(self) -> None: self.json_db = JsonFileDatabase() self.json_db.initialize(Task()) self.task1 = Task("task1") self.task1.index = 1 self.task2 = Task("task2") self.task2.index = 2 self.task3 = Task("task3") self.task3.index = 3 self.task4 = Task("task4") self.task4.index = 4 self.task5 = Task("task5") self.task5.index = 5 self.task6 = Task("task6") self.task6.index = 6 self.task7 = Task("task7") self.task7.index = 7 self.task8 = Task("task8") self.task8.index = 8 self.task9 = Task("task9") self.task9.index = 9 self.task10 = Task("task10") self.task10.index = 10
def test_import_action_can_insert(self): action = ImportAction(None, Task("Task1")) self.assertTrue(action.can_insert()) self.assertFalse(action.can_update()) self.assertFalse(action.can_delete())
def test_object_must_contain_iter_method(self): self.redis_db.initialize(Task()) with self.assertRaises(TypeError): self.redis_db.set([MissingIterMethod()])
def test_object_must_be_subclass_of_DatabaseObject(self): self.redis_db.initialize(Task()) with self.assertRaises(ValueError): self.redis_db.set([MissingSubclass])
def __init__(self, database): super().__init__(database, Task()) self.__calendar = Calendar() self.__vars = CommonVariables() self.__date_generator = DateGenerator()
def setUp(self): self.vars = CommonVariables() self.db = JsonFileDatabase() self.db.initialize(Task()) self.tasks = Tasks(self.db) self.task1 = Task("Task1") self.task1.label = "waiting" self.task1.date_expression = "may 2" self.task1.external_id = 1 self.tasks.append(self.task1) self.task2 = Task("Task2") self.task2.label = "computer" self.task2.date_expression = "may 3" self.tasks.append(self.task2) self.task3 = Task("Task3") self.task3.label = "office" self.task3.date_expression = "may 4" self.tasks.append(self.task3) self.task4 = Task("Task4") self.task4.label = "waiting" self.task4.date_expression = "may 5" self.tasks.append(self.task4) self.task5 = Task("Task5") self.task5.label = "office" self.task5.date_expression = "may 6" self.tasks.append(self.task5) self.task6 = Task("Task6") self.task6.label = "call" self.task6.date_expression = "may 7" self.tasks.append(self.task6) self.task7 = Task("Task7") self.task7.label = "computer" self.task7.date_expression = "may 8" self.tasks.append(self.task7) self.task8 = Task("Task8") self.task8.label = "call" self.task8.date_expression = "may 9" self.tasks.append(self.task8) self.task9 = Task("Task9") self.task9.label = "office" self.task9.date_expression = "may 10" self.tasks.append(self.task9) self.task10 = Task("Task10") self.task10.label = "waiting" self.task10.date_expression = "may 11" self.tasks.append(self.task10) self.future_task = Task("Future Task") future_datetime = datetime.now() + timedelta(days=1) date_string = future_datetime.strftime(self.vars.date_format) self.future_task.due_date = DueDate(date_string) self.tasks.append(self.future_task)
def setUp(self) -> None: self.db = JsonFileDatabase() self.db.initialize(Task()) self.db.clear() self.tasks = Tasks(self.db)
def test_add_task(self): task = Task("Task11") self.tasks.append(task) task_list = self.tasks.get_object_list() print(f"test_add_task: len {len(task_list)}") self.assertTrue(len(task_list) == 12)