Untitled
2 years ago in Plain Text
class PaginatorViewsTest(TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.user = User.objects.create_user(username='TestUser')
cls.group = Group.objects.create(
title='test group',
slug='test_slug',
description='test description',
)
cls.post_list = []
for i in range(0, 13):
cls.post_list.append(
Post.objects.create(
text=f'#{i} Текст тестового поста #{i}',
author=cls.user,
group=cls.group,
)
)
def setUp(self):
self.guest_client = Client()
self.authorized_client = Client()
self.authorized_client.force_login(self.user)
def test_first_page_contains_ten_records(self):
DES_POSTS = 10
THREE = 3
first_page = {
reverse('posts:index'): DES_POSTS,
reverse('posts:group_list',
kwargs={'slug': self.group.slug}): DES_POSTS,
reverse('posts:profile',
kwargs={'username': self.user}): DES_POSTS,
reverse('posts:index') + '?page=2': THREE,
reverse('posts:group_list', kwargs={'slug': self.group.slug}
) + '?page=2': THREE,
reverse('posts:profile', kwargs={'username': self.user}
) + '?page=2': THREE,
}
for value, expected in first_page.items():
with self.subTest(value=value):
response = self.authorized_client.get(value)
self.assertEqual(
len(response.context['page_obj']), expected)