-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
27 lines (23 loc) · 933 Bytes
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from django.test import TestCase
from django.urls import reverse
from .models import Book
# Create your tests here.
class BookTests(TestCase):
@classmethod
def setUpTestData(cls):
cls.book = Book.objects.create(
title="A good title",
subtitle="An excellent subtitle",
author="Tom Christie",
isbn="1234567890123",
)
def test_book_content(self):
self.assertEqual(self.book.title, "A good title")
self.assertEqual(self.book.subtitle, "An excellent subtitle")
self.assertEqual(self.book.author, "Tom Christie")
self.assertEqual(self.book.isbn, "1234567890123")
def test_book_listview(self):
response = self.client.get(reverse("home"))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "excellent subtitle")
self.assertTemplateUsed(response, "books/book_list.html")