Beispiel #1
0
 def test_list_serializer(self):
     PostFactory.create_batch(size=10)
     self.get("api_v1:post-list")
     self.response_200()
     data = self.last_response.json()
     self.assertEqual(10, len(data))
     self.assertNotIn("content", data[0])
Beispiel #2
0
 def test_search(self):
     PostFactory.create_batch(title="foo", content="dummy", size=10)
     PostFactory(title="potato")
     self.get("api_v1:post-list", data={"search": "potato"})
     self.response_200()
     data = self.last_response.json()
     self.assertEqual(1, len(data))
Beispiel #3
0
    def test_index_shows_posts(self):
        posts = PostFactory.create_batch(random.randint(1, 10))
        response = self.client.get(url_for('main.index'))
        self.assertTemplateUsed('index.html')

        for post in posts:
            self.assertTrue(post.title in str(response.get_data()))
Beispiel #4
0
def test_lists_with_anonymous_user(db_connection, test_client, event_loop):
    author = event_loop.run_until_complete(UserFactory.create())
    draft_posts = event_loop.run_until_complete(
        PostFactory.create_batch(4, author=author))
    posts = event_loop.run_until_complete(
        PostFactory.create_batch(5, author=author, state=PostState.PUBLISHED))
    response = test_client.get('/blog')

    assert response.status_code == 200
    assert '<script defer data-api="/analytics/event" data-domain=' \
           '"raiseexception.dev"' in response.text
    for post in posts:
        assert post.title_slug in response.text
        assert post.title.capitalize() in response.text

    for post in draft_posts:
        assert post.title_slug not in response.text
        assert post.title.capitalize() not in response.text
Beispiel #5
0
 def test_annotate_total_posts(self):
     blog = BlogFactory()
     PostFactory.create_batch(blog=blog, size=10)
     annotated_blog = Blog.objects.annotate_total_posts().first()
     self.assertEqual(10, annotated_blog.total_posts)
Beispiel #6
0
 def test_search_combined(self):
     PostFactory.create_batch(size=10)
     PostFactory(title="title and", content="content")
     posts = Post.objects.search(query="and content")
     self.assertEqual(1, posts.count())
Beispiel #7
0
 def test_search_mixin(self):
     PostFactory.create_batch(size=10)
     PostFactory(title="very exact title")
     posts = Post.objects.search(query="exact")
     self.assertEqual(1, posts.count())
Beispiel #8
0
 def test_annotate_total_posts(self):
     blog = BlogFactory()
     PostFactory.create_batch(blog=blog, size=10)
     self.get("api_v1:blog-detail", pk=blog.pk)
     self.response_200()
     self.assertEquals(10, self.last_response.data["total_posts"])
Beispiel #9
0
 def test_retrieve_serializer(self):
     posts = PostFactory.create_batch(size=10)
     self.get("api_v1:post-detail", pk=posts[0].pk)
     self.response_200()
     data = self.last_response.json()
     self.assertIn("content", data)