Example #1
0
    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
Example #2
0
 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'
Example #3
0
    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
Example #4
0
 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')
Example #5
0
    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
Example #6
0
 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'
Example #7
0
    def test_post_api_list(self, api):
        '''It should fetch a post list from the API'''
        posts = PostFactory.create_batch(3)

        response = api.get(url_for('api.posts'))
        assert200(response)
        assert len(response.json['data']) == len(posts)
Example #8
0
    def test_post_api_list(self):
        '''It should fetch a post list from the API'''
        posts = PostFactory.create_batch(3)

        response = self.get(url_for('api.posts'))
        self.assert200(response)
        self.assertEqual(len(response.json['data']), len(posts))
Example #9
0
 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)
Example #10
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
Example #11
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'))
Example #12
0
    def test_render_list(self):
        '''It should render the post list page'''
        posts = PostFactory.create_batch(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))
Example #13
0
    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
Example #14
0
    def test_render_list(self, client, templates):
        '''It should render the post list page'''
        posts = PostFactory.create_batch(3)

        response = client.get(url_for('posts.list'))

        assert200(response)
        rendered_posts = templates.get_context_variable('posts')
        assert len(rendered_posts) == len(posts)
Example #15
0
    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
Example #16
0
    def test_render_list(self, client, templates):
        '''It should render the post list page'''
        posts = PostFactory.create_batch(3)

        response = client.get(url_for('posts.list'))

        assert200(response)
        rendered_posts = templates.get_context_variable('posts')
        assert len(rendered_posts) == len(posts)
Example #17
0
    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)
Example #18
0
    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))
Example #19
0
    def test_posts_within_sitemap(self, sitemap):
        '''It should return a post list from the sitemap.'''
        posts = PostFactory.create_batch(3)

        sitemap.fetch()

        for post in posts:
            url = sitemap.get_by_url('posts.show_redirect', post=post)
            assert url is not None
            sitemap.assert_url(url, 0.6, 'weekly')
Example #20
0
    def test_posts_within_sitemap(self):
        '''It should return a post list from the sitemap.'''
        posts = PostFactory.create_batch(3)

        self.get_sitemap_tree()

        for post in posts:
            url = self.get_by_url('posts.show_redirect', post=post)
            self.assertIsNotNone(url)
            self.assert_url(url, 0.6, 'weekly')
Example #21
0
    def test_posts_within_sitemap(self, sitemap):
        '''It should return a post list from the sitemap.'''
        posts = PostFactory.create_batch(3)

        sitemap.fetch()

        for post in posts:
            url = sitemap.get_by_url('posts.show_redirect', post=post)
            assert url is not None
            sitemap.assert_url(url, 0.6, 'weekly')
Example #22
0
    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
Example #23
0
 def test_post_api_create(self, api):
     '''It should create a post from the API'''
     data = PostFactory.as_dict()
     data['datasets'] = [str(d.id) for d in data['datasets']]
     data['reuses'] = [str(r.id) for r in data['reuses']]
     api.login(AdminFactory())
     response = api.post(url_for('api.posts'), data)
     assert201(response)
     assert Post.objects.count() == 1
     post = Post.objects.first()
     for dataset, expected in zip(post.datasets, data['datasets']):
         assert str(dataset.id) == expected
     for reuse, expected in zip(post.reuses, data['reuses']):
         assert str(reuse.id) == expected
Example #24
0
 def test_post_api_create(self, api):
     '''It should create a post from the API'''
     data = PostFactory.as_dict()
     data['datasets'] = [str(d.id) for d in data['datasets']]
     data['reuses'] = [str(r.id) for r in data['reuses']]
     api.login(AdminFactory())
     response = api.post(url_for('api.posts'), data)
     assert201(response)
     assert Post.objects.count() == 1
     post = Post.objects.first()
     for dataset, expected in zip(post.datasets, data['datasets']):
         assert str(dataset.id) == expected
     for reuse, expected in zip(post.reuses, data['reuses']):
         assert str(reuse.id) == expected
Example #25
0
 def test_post_api_create(self):
     '''It should create a post from the API'''
     data = PostFactory.as_dict()
     data['datasets'] = [str(d.id) for d in data['datasets']]
     data['reuses'] = [str(r.id) for r in data['reuses']]
     self.login(AdminFactory())
     response = self.post(url_for('api.posts'), data)
     self.assert201(response)
     self.assertEqual(Post.objects.count(), 1)
     post = Post.objects.first()
     for dataset, expected in zip(post.datasets, data['datasets']):
         self.assertEqual(str(dataset.id), expected)
     for reuse, expected in zip(post.reuses, data['reuses']):
         self.assertEqual(str(reuse.id), expected)
Example #26
0
def post(app):
    post = PostFactory()
    visit(post)
    return post
Example #27
0
 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)
Example #28
0
 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')
Example #29
0
 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')
Example #30
0
 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)
Example #31
0
 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'))