Exemplo n.º 1
0
class ListModelTests(TestCase):
    def setUp(self):
        self.user = User.objects.create_user('test', '*****@*****.**',
                                             'test')
        self.todolist = TodoList(title='title', create_user=self.user)
        self.todolist.save()
        self.todo = Todo(description='description',
                         todolist_id=self.todolist.id,
                         create_user=self.user)
        self.todo.save()

    def tearDown(self):
        self.todo.delete()
        self.todolist.delete()
        self.user.delete()

    def test_count_todos(self):
        self.assertEqual(self.todolist.count(), 1)
        new_todo = Todo(description='test',
                        todolist_id=self.todolist.id,
                        create_user=self.user)
        new_todo.save()
        self.assertEqual(self.todolist.count(), 2)

    def test_count_open_todos(self):
        self.assertEqual(self.todolist.count_open(), 1)
        new_todo = Todo(description='test',
                        todolist_id=self.todolist.id,
                        create_user=self.user)
        new_todo.save()
        self.assertEqual(self.todolist.count_open(), 2)
        new_todo.close()
        self.assertEqual(self.todolist.count_open(), 1)

    def test_count_closed_todos(self):
        self.assertEqual(self.todolist.count_finished(), 0)
        new_todo = Todo(description='test',
                        todolist_id=self.todolist.id,
                        create_user=self.user)
        new_todo.close()
        self.todo.close()
        self.assertEqual(self.todolist.count_finished(), 2)
        self.assertIsNotNone(new_todo.deadline)
        self.todo.reopen()
        self.assertEqual(self.todolist.count_finished(), 1)
        self.assertIsNone(self.todo.deadline)
Exemplo n.º 2
0
class ListTests(TestCase):
    def setUp(self):
        self.user = User.objects.create_user('test', '*****@*****.**',
                                             'test')
        self.todolist = TodoList(title='test title', create_user=self.user)
        self.todolist.save()
        self.todo = Todo(description='save todo',
                         todolist_id=self.todolist.id,
                         create_user=self.user)
        self.todo.save()
        self.client.login(username='******', password='******')

    def tearDown(self):
        self.client.logout()
        self.user.delete()
        self.todolist.delete()
        self.todo.delete()

    def test_get_index_page(self):
        response = self.client.get(reverse('lists:index'))
        self.assertTemplateUsed(response, 'todolist/index.html')
        self.assertIsInstance(response.context['form'], TodoForm)

    def test_add_todo_to_index_page(self):
        response = self.client.post(reverse('lists:index'),
                                    {'description': 'test'})
        self.assertTemplateUsed(response, 'todolist/index.html')
        self.assertIsInstance(response.context['form'], TodoForm)

    def test_get_todolist_view(self):
        response = self.client.get(
            reverse('lists:todolist', kwargs={'todolist_id':
                                              self.todolist.id}))
        self.assertTemplateUsed(response, 'todolist/todolist.html')
        self.assertIsInstance(response.context['form'], TodoForm)

    def test_add_todo_to_todolist_view(self):
        response = self.client.post(
            reverse('lists:todolist', kwargs={'todolist_id':
                                              self.todolist.id}),
            {'description': 'test'})
        self.assertTemplateUsed(response, 'todolist/todolist.html')
        self.assertIsInstance(response.context['form'], TodoForm)
        self.assertContains(response, 'test')

    def test_get_todolist_overview(self):
        response = self.client.get(reverse('lists:overview'))
        self.assertTemplateUsed(response, 'todolist/overview.html')
        self.assertIsInstance(response.context['form'], TodoListForm)

    def test_get_todolist_overview_redirect_when_not_logged_in(self):
        self.client.logout()
        response = self.client.get(reverse('lists:overview'))
        self.assertRedirects(response, '/auth/login/?next=/todolists/')

    def test_add_todolist_to_todolist_overview(self):
        response = self.client.post(reverse('lists:overview'),
                                    {'title': 'some title'})
        self.assertRedirects(response,
                             '/todolist/add/',
                             target_status_code=302,
                             fetch_redirect_response=False)