Example #1
0
 def test_count_todos(self):
     self.assertEqual(self.todolist.count(), 1)
     new_todo = Todo(
         description='test',
         todolist_id=self.todolist.id,
         creator=self.user
     )
     new_todo.save()
     self.assertEqual(self.todolist.count(), 2)
Example #2
0
 def setUp(self):
     self.user = User.objects.create_user(
         'test', '*****@*****.**', 'test'
     )
     self.todolist = TodoList(title='title', creator=self.user)
     self.todolist.save()
     self.todo = Todo(
         description='description',
         todolist_id=self.todolist.id,
         creator=self.user
     )
     self.todo.save()
Example #3
0
 def setUp(self):
     self.user = User.objects.create_user(
         'test', '*****@*****.**', 'test'
     )
     self.todolist = TodoList(title='test title', creator=self.user)
     self.todolist.save()
     self.todo = Todo(
         description='save todo',
         todolist_id=self.todolist.id,
         creator=self.user
     )
     self.todo.save()
     self.client.login(username='******', password='******')
Example #4
0
 def test_count_closed_todos(self):
     self.assertEqual(self.todolist.count_finished(), 0)
     new_todo = Todo(
         description='test',
         todolist_id=self.todolist.id,
         creator=self.user
     )
     new_todo.close()
     self.todo.close()
     self.assertEqual(self.todolist.count_finished(), 2)
     self.assertIsNotNone(new_todo.finished_at)
     self.todo.reopen()
     self.assertEqual(self.todolist.count_finished(), 1)
     self.assertIsNone(self.todo.finished_at)
Example #5
0
def add_todo(request, todolist_id):
    if request.method == 'POST':
        form = TodoForm(request.POST)
        if form.is_valid():
            user = request.user if request.user.is_authenticated else None
            todo = Todo(
                description=request.POST['description'],
                todolist_id=todolist_id,
                creator=user
            )
            todo.save()
            return redirect('home:todolist', todolist_id=todolist_id)
        else: 
            return render(request, 'home/todolist.html', {'form': form})

    return redirect('home:index')
Example #6
0
class ListModelTests(TestCase):

    def setUp(self):
        self.user = User.objects.create_user(
            'test', '*****@*****.**', 'test'
        )
        self.todolist = TodoList(title='title', creator=self.user)
        self.todolist.save()
        self.todo = Todo(
            description='description',
            todolist_id=self.todolist.id,
            creator=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,
            creator=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,
            creator=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,
            creator=self.user
        )
        new_todo.close()
        self.todo.close()
        self.assertEqual(self.todolist.count_finished(), 2)
        self.assertIsNotNone(new_todo.finished_at)
        self.todo.reopen()
        self.assertEqual(self.todolist.count_finished(), 1)
        self.assertIsNone(self.todo.finished_at)
Example #7
0
class ListTests(TestCase):

    def setUp(self):
        self.user = User.objects.create_user(
            'test', '*****@*****.**', 'test'
        )
        self.todolist = TodoList(title='test title', creator=self.user)
        self.todolist.save()
        self.todo = Todo(
            description='save todo',
            todolist_id=self.todolist.id,
            creator=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('home:index'))
        self.assertTemplateUsed(response, 'home/index.html')
        self.assertIsInstance(response.context['form'], TodoForm)

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

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

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

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

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