Coverage for todos/tests/test_models.py: 100.00%

22 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-04 19:48 -0700

1from django.urls import reverse 1a

2from rest_framework import status 1a

3from rest_framework.test import APITestCase 1a

4 

5from ..models import Todo 1a

6 

7 

8class TodoModelTest(APITestCase): 1a

9 @classmethod 1a

10 def setUpTestData(cls): 1a

11 cls.todo = Todo.objects.create(title="First Todo", body="A body of text here") 1a

12 

13 def test_model_content(self): 1a

14 self.assertEqual(self.todo.title, "First Todo") 1a

15 self.assertEqual(self.todo.body, "A body of text here") 1a

16 self.assertEqual(str(self.todo), "First Todo") 1a

17 

18 def test_api_listview(self): 1a

19 response = self.client.get(reverse("todo_list")) 1a

20 self.assertEqual(response.status_code, status.HTTP_200_OK) 1a

21 self.assertEqual(Todo.objects.count(), 1) 1a

22 self.assertContains(response, self.todo) 1a

23 

24 def test_api_detailview(self): 1a

25 response = self.client.get( 1a

26 reverse("todo_detail", kwargs={"pk": self.todo.id}), format="json" 

27 ) 

28 self.assertEqual(response.status_code, status.HTTP_200_OK) 1a

29 self.assertEqual(Todo.objects.count(), 1) 1a

30 self.assertContains(response, "First Todo") 1a