def test_remove_from_completed_category_not_exist(self): data = {'new_task': 'new task text'} response = self.client.post(self.add_new_task, data=data, follow=True) tasks = todo_task.get_all_tasks(self.user.id) finish_task_url = reverse('finish_task', args=[ 'all', tasks[0].id, ]) response = self.client.get(finish_task_url, follow=True) tasks = todo_task.get_all_tasks(self.user.id) remove_from_completed_task_url = reverse('remove_from_completed', args=[ 'not_exist', tasks[0].id, ]) try: response = self.client.get(remove_from_completed_task_url, follow=True) except ObjectDoesNotExist: pass tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 1) self.assertFalse(tasks[0].is_completed) self.assertRedirects(response, self.category_all_url, status_code=302, target_status_code=200)
def test_set_task_not_important(self): data = {'new_task': 'new task text'} response = self.client.post(self.add_new_task, data=data, follow=True) tasks = todo_task.get_all_tasks(self.user.id) set_task_important_url = reverse('set_task_important', args=[ 'all', tasks[0].id, ]) response = self.client.get(set_task_important_url, follow=True) tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 1) self.assertTrue(tasks[0].is_important) self.assertRedirects(response, self.category_all_url, status_code=302, target_status_code=200) set_task_not_important_url = reverse('set_task_not_important', args=[ 'all', tasks[0].id, ]) response = self.client.get(set_task_not_important_url, follow=True) tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 1) self.assertFalse(tasks[0].is_important) self.assertRedirects(response, self.category_all_url, status_code=302, target_status_code=200)
def test_delete_task(self): data = {'new_task': 'new task text'} response = self.client.post(self.add_new_task, data=data, follow=True) response = self.client.post(self.add_new_task, data=data, follow=True) response = self.client.post(self.add_new_task, data=data, follow=True) tasks = todo_task.get_all_tasks(self.user.id) delete_task_url = reverse('delete_task', args=[ 'all', tasks[0].id, ]) response = self.client.get(delete_task_url, follow=True) tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 2) self.assertRedirects(response, self.category_all_url, status_code=302, target_status_code=200)
def test_add_empty_task(self): data = {'new_task': ''} response = self.client.post(self.add_new_task, data=data, follow=True) tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 0) self.assertRedirects(response, self.category_all_url, status_code=302, target_status_code=200)
def test_add_task_more_than_400_characters(self): data = {'new_task': 'i' * 401} response = self.client.post(self.add_new_task, data=data, follow=True) tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 1) self.assertEquals(len(tasks[0].task), 400) self.assertRedirects(response, self.category_all_url, status_code=302, target_status_code=200)
def test_category_all_add_task(self): data = {'new_task': 'some text about the task'} response = self.client.post(self.add_new_task, data=data, follow=True) tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 1) self.assertEquals(tasks[0].task, 'some text about the task') self.assertRedirects(response, self.category_all_url, status_code=302, target_status_code=200)
def test_finish_task_when_task_not_exist(self): finish_task_url = reverse('finish_task', args=[ 'all', 777, ]) response = self.client.get(finish_task_url, follow=True) tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 0) self.assertRedirects(response, self.category_all_url, status_code=302, target_status_code=200)
def test_remove_from_completed_task_not_exist(self): remove_from_completed_task_url = reverse('remove_from_completed', args=[ 'all', 777, ]) response = self.client.get(remove_from_completed_task_url, follow=True) tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 0) self.assertRedirects(response, self.category_all_url, status_code=302, target_status_code=200)
def test_category_important_add_task(self): data = {'new_task': 'some text about the task'} add_important_task = reverse('add_new_task', args=['important']) response = self.client.post(add_important_task, data=data, follow=True) tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 1) self.assertTrue(tasks[0].is_important) self.assertEquals(tasks[0].task, 'some text about the task') important_url = reverse('category', args=['important']) self.assertRedirects(response, important_url, status_code=302, target_status_code=200)
def test_custom_category_add_task(self): custom_category = todo_category.create_category('custom_category', user=self.user) data = {'new_task': 'custom category task'} add_custom_task = reverse('add_new_task', args=[custom_category.slug]) response = self.client.post(add_custom_task, data=data, follow=True) tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 1) self.assertEquals(tasks[0].task, 'custom category task') custom_category_url = reverse('category', args=[custom_category.slug]) self.assertRedirects(response, custom_category_url, status_code=302, target_status_code=200)
def test_finish_task_pass_already_completed_task(self): data = {'new_task': 'new task text'} response = self.client.post(self.add_new_task, data=data, follow=True) tasks = todo_task.get_all_tasks(self.user.id) finish_task_url = reverse('finish_task', args=[ 'all', tasks[0].id, ]) response = self.client.get(finish_task_url, follow=True) tasks = todo_task.get_all_tasks(self.user.id) self.assertEquals(tasks.count(), 1) self.assertTrue(tasks[0].is_completed) self.assertRedirects(response, self.category_all_url, status_code=302, target_status_code=200) response = self.client.get(finish_task_url, follow=True) self.assertEquals(tasks.count(), 1) self.assertTrue(tasks[0].is_completed) self.assertRedirects(response, self.category_all_url, status_code=302, target_status_code=200)