diff --git a/catalog/tests/test_views.py b/catalog/tests/test_views.py index d24e4085..72ce5aba 100644 --- a/catalog/tests/test_views.py +++ b/catalog/tests/test_views.py @@ -1,357 +1,357 @@ -from django.test import TestCase - -# Create your tests here. - - -from catalog.models import Author -from django.urls import reverse - - -class AuthorListViewTest(TestCase): - - @classmethod - def setUpTestData(cls): - # Create authors for pagination tests - number_of_authors = 13 - for author_id in range(number_of_authors): - Author.objects.create(first_name='Christian {0}'.format(author_id), - last_name='Surname {0}'.format(author_id)) - - def test_view_url_exists_at_desired_location(self): - response = self.client.get('/catalog/authors/') - self.assertEqual(response.status_code, 200) - - def test_view_url_accessible_by_name(self): - response = self.client.get(reverse('authors')) - self.assertEqual(response.status_code, 200) - - def test_view_uses_correct_template(self): - response = self.client.get(reverse('authors')) - self.assertEqual(response.status_code, 200) - self.assertTemplateUsed(response, 'catalog/author_list.html') - - def test_pagination_is_ten(self): - response = self.client.get(reverse('authors')) - self.assertEqual(response.status_code, 200) - self.assertTrue('is_paginated' in response.context) - self.assertTrue(response.context['is_paginated'] is True) - self.assertEqual(len(response.context['author_list']), 10) - - def test_lists_all_authors(self): - # Get second page and confirm it has (exactly) the remaining 3 items - response = self.client.get(reverse('authors')+'?page=2') - self.assertEqual(response.status_code, 200) - self.assertTrue('is_paginated' in response.context) - self.assertTrue(response.context['is_paginated'] is True) - self.assertEqual(len(response.context['author_list']), 3) - - -import datetime -from django.utils import timezone - -from catalog.models import BookInstance, Book, Genre, Language -from django.contrib.auth.models import User # Required to assign User as a borrower - - -class LoanedBookInstancesByUserListViewTest(TestCase): - - def setUp(self): - # Create two users - test_user1 = User.objects.create_user(username='testuser1', password='1X