def test_post_api_delete(self): '''It should delete a post from the API''' post = PostFactory() with self.api_user(AdminFactory()): response = self.delete(url_for('api.post', post=post)) self.assertStatus(response, 204) self.assertEqual(Post.objects.count(), 0)
def test_post_api_delete(self, api): '''It should delete a post from the API''' post = PostFactory() with api.user(AdminFactory()): response = api.delete(url_for('api.post', post=post)) assert204(response) assert Post.objects.count() == 0
def test_render_display_with_discussions(self): '''It should render the post page with discussions''' self.app.config['POST_DISCUSSIONS_ENABLED'] = True post = PostFactory() response = self.get(url_for('posts.show', post=post)) self.assert200(response) self.assertIn('discussions-section', response.data.decode('utf-8'))
def test_post_api_list(self, api): '''It should fetch a post list from the API''' posts = PostFactory.create_batch(3) posts.append(PostFactory(published=None)) response = api.get(url_for('api.posts')) assert200(response) # Response should not contain the unpublished post assert len(response.json['data']) == 3
def test_render_display_with_siblings(self, client, templates): '''It should render the post page with sibling links''' previous_date = faker.date_time_between(start_date='-3d', end_date='-2d') date = faker.date_time_between(start_date='-2d', end_date='-1d') next_date = faker.date_time_between(start_date='-1d', end_date='now') other_date = faker.date_time_between(start_date='-1y', end_date='-3d') previous_post = PostFactory(published=previous_date) post = PostFactory(published=date) next_post = PostFactory(published=next_date) PostFactory.create_batch(3, published=other_date) response = client.get(url_for('posts.show', post=post)) assert200(response) assert templates.get_context_variable('previous_post') == previous_post assert templates.get_context_variable('next_post') == next_post
def test_render_list(self): '''It should render the post list page''' # with self.autoindex(): posts = [PostFactory() for i in range(3)] response = self.get(url_for('posts.list')) self.assert200(response) rendered_posts = self.get_context_variable('posts') self.assertEqual(len(rendered_posts), len(posts))
def test_render_display_with_siblings(self): '''It should render the post page with sibling links''' previous_date = faker.date_time_between(start_date='-3d', end_date='-2d') date = faker.date_time_between(start_date='-2d', end_date='-1d') next_date = faker.date_time_between(start_date='-1d', end_date='now') other_date = faker.date_time_between(start_date='-1y', end_date='-3d') previous_post = PostFactory(created_at=previous_date) post = PostFactory(created_at=date) next_post = PostFactory(created_at=next_date) PostFactory.create_batch(3, created_at=other_date) response = self.get(url_for('posts.show', post=post)) self.assert200(response) self.assertEqual(self.get_context_variable('previous_post'), previous_post) self.assertEqual(self.get_context_variable('next_post'), next_post)
def test_post_api_unpublish(self, api): '''It should update a post from the API''' post = PostFactory() api.login(AdminFactory()) response = api.delete(url_for('api.publish_post', post=post)) assert200(response) assert Post.objects.count() == 1 post.reload() assert post.published is None
def test_post_api_update(self, api): '''It should update a post from the API''' post = PostFactory() data = post.to_dict() data['content'] = 'new content' api.login(AdminFactory()) response = api.put(url_for('api.post', post=post), data) assert200(response) assert Post.objects.count() == 1 assert Post.objects.first().content == 'new content'
def test_post_api_update(self): '''It should update a post from the API''' post = PostFactory() data = post.to_dict() data['content'] = 'new content' self.login(AdminFactory()) response = self.put(url_for('api.post', post=post), data) self.assert200(response) self.assertEqual(Post.objects.count(), 1) self.assertEqual(Post.objects.first().content, 'new content')
def test_post_api_update_with_related_dataset_and_reuse(self, api): '''It should update a post from the API with related dataset and reuse''' api.login(AdminFactory()) post = PostFactory() data = post.to_dict() data['content'] = 'new content' # Add datasets data['datasets'] = [DatasetFactory().to_dict()] response = api.put(url_for('api.post', post=post), data) assert200(response) # Add reuses to the post value returned by the previous api call data = response.json data['reuses'] = [ReuseFactory().to_dict()] response = api.put(url_for('api.post', post=post), data) assert200(response) assert len(response.json['datasets']) == 1 assert len(response.json['reuses']) == 1
def post(app): post = PostFactory() visit(post) return post
def test_render_display(self): '''It should render the post page''' post = PostFactory() response = self.get(url_for('posts.show', post=post)) self.assert200(response)
def test_render_display_with_discussions(self, client): '''It should render the post page with discussions''' post = PostFactory() response = client.get(url_for('posts.show', post=post)) assert200(response) assert 'discussions-section' in response.data.decode('utf-8')
def test_render_display_without_navigation(self, client): '''It should not render post navigation if not necessary''' post = PostFactory() response = client.get(url_for('posts.show', post=post)) assert200(response) assert 'nav-section' not in response.data.decode('utf-8')
def test_post_api_get(self): '''It should fetch a post from the API''' post = PostFactory() response = self.get(url_for('api.post', post=post)) self.assert200(response)
def test_render_display_without_navigation(self): '''It should not render post navigation if not necessary''' post = PostFactory() response = self.get(url_for('posts.show', post=post)) self.assert200(response) self.assertNotIn('nav-section', response.data.decode('utf-8'))