def test_returns_inner_tasks_recursive(self): task_id = self.task_storage.create(self.task).id inner_task = TaskFactory() inner_task.parent_task_id = task_id inner_task_id = self.task_storage.create(inner_task).id second_level_inner_task = TaskFactory() second_level_inner_task.parent_task_id = inner_task_id self.task_storage.create(second_level_inner_task) inner_tasks = self.task_storage.inner(task_id, True) self.assertEqual(len(inner_tasks), 2)
def test_returns_user_tasks(self): first_task = TaskFactory() second_task = TaskFactory() user_id = 10 first_task.user_id = user_id second_task.user_id = user_id self.task_storage.create(first_task) self.task_storage.create(second_task) tasks = self.task_storage.user_tasks(user_id) self.assertEqual(len(tasks), 2)
def test_returns_inner_tasks(self): task_id = self.task_storage.create(self.task).id inner_task = TaskFactory() inner_task.parent_task_id = task_id self.task_storage.create(inner_task) inner_tasks = self.task_storage.inner(task_id) self.assertEqual(len(inner_tasks), 1)
def test_processes_task_plans(self): user_id = 10 repeated_task = TaskFactory() repeated_task.status = Status.TEMPLATE.value repeated_task.user_id = user_id task_id = self.task_storage.create(repeated_task).id before_tasks_count = len(self.task_storage.user_tasks(user_id)) interval = 300 big_interval = interval * 10 last_created_at = datetime.datetime.now() - datetime.timedelta( seconds=interval + 5) """ repeated_task_plan after processing should create new task repeated_task_plan_big_interval should not create new task because of bit interval """ repeated_task_plan = TaskPlan(user_id=user_id, task_id=task_id, last_created_at=last_created_at, interval=interval) repeated_task_plan_big_interval = TaskPlan( user_id=user_id, task_id=task_id, last_created_at=last_created_at, interval=big_interval) self.task_plan_storage.create(repeated_task_plan) self.task_plan_storage.create(repeated_task_plan_big_interval) self.task_plan_storage.process_plans(self.task_storage) self.assertEqual(len(self.task_storage.user_tasks(user_id)), before_tasks_count + 1)
def test_task_delete(client, user_credentials): client.login(**user_credentials) task = TaskFactory() assert Task.objects.filter(id=task.id).exists() response = client.post('/tasks/{id}/delete/'.format(id=task.id)) assert response.status_code == HTTPStatus.FOUND assert not Task.objects.filter(id=task.id).exists()
def test_task_detail(client, user_credentials): client.login(**user_credentials) task = TaskFactory() response = client.get('/tasks/{id}/'.format(id=task.id)) response_body = response.content.decode() assert response.status_code == HTTPStatus.OK assert task.name in response_body
def test_task_update_page(client, user_credentials): client.login(**user_credentials) task = TaskFactory() response = client.get('/tasks/{id}/edit/'.format(id=task.id)) response_body = response.content.decode() assert response.status_code == HTTPStatus.OK assert 'Update task' in response_body
def setUp(self): self.database = ':memory:' self.category_storage = CategoryStorage(self.database) self.task_storage = TaskStorage(self.database) self.task_plan_storage = TaskPlanStorage(self.database) self.notification_storage = NotificationStorage(self.database) self.category = CategoryFactory(user_id=10) self.task = TaskFactory() self.task_plan = TaskPlanFactory() self.notification = NotificationFactory() DatabaseConnector(self.database).create_tables()
def test_task_update(client, user_credentials): client.login(**user_credentials) task = TaskFactory() task_new_name = 'new_test_task' task_from_db = Task.objects.get(id=task.id) assert task_from_db.name != task_new_name response = client.post('/tasks/{id}/edit/'.format(id=task.id), { 'name': task_new_name, 'status': task_from_db.status.id, }) updated_task_from_db = Task.objects.get(id=task.id) assert response.status_code == HTTPStatus.FOUND assert updated_task_from_db.name == task_new_name
def setUp(self): self.database = ':memory:' self.user_id = 10 self.categories_controller = CategoriesController( self.user_id, CategoryStorage(self.database)) self.tasks_controller = TasksController(self.user_id, TaskStorage(self.database)) self.task_plans_controller = TaskPlansController( self.user_id, TaskPlanStorage(self.database)) self.notifications_controller = NotificationsController( self.user_id, NotificationStorage(self.database)) self.category = CategoryFactory() self.task = TaskFactory() self.task_plan = TaskPlanFactory() self.notification = NotificationFactory() DatabaseConnector(self.database).create_tables()