def test_pagination(self): PostFactory.create_batch(20) PostFactory(status=0) response = api_client.get('/api/post/all/', format='json') self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data['results']), 10) self.assertEqual(response.data['count'], 25) self.assertEqual(response.data['next'], 'https://testserver:80/api/post/all/?page=2') response = api_client.get('/api/post/all/?page=2', format='json') self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data['results']), 10)
class PostDetailTests(HtmlTestCaseMixin, TestCase): def setUp(self): self.parent = CategoryFactory() child = CategoryFactory(parent=self.parent) self.category = CategoryFactory(parent=child) self.post = PostFactory(rubric=self.category) def test_detail(self): response = client.get(self.post.get_absolute_url()) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'posts/detail.html') self.assertIn('object', response.context) self.assertEqual(len(response.context['menu_items']), 1) def test_meta_data(self): response = client.get(self.post.get_absolute_url()) self.assertEqual(response.status_code, 200) self.assertMetaDataIn(response.content) self.assertH1(response.content)
def setUp(self): PostFactory.create_batch(7)
def setUp(self): self.parent = CategoryFactory() child = CategoryFactory(parent=self.parent) self.category = CategoryFactory(parent=child) self.post = PostFactory(rubric=self.category)
def test_get_absolute_url(self): parent = CategoryFactory(slug='aaa') child = CategoryFactory(parent=parent, slug='bbb') child2 = CategoryFactory(parent=child, slug='ccc') post = PostFactory(rubric=child2, slug='ddd', id='12') self.assertEqual(post.get_absolute_url(), '/bbb/ccc/ddd-12.html')
def test_posts_list(self): PostFactory.create_batch(size=11) self.assertEqual(len(posts_list(10)['posts']), 10) self.assertEqual(len(posts_list(5)['posts']), 5)