Пример #1
0
    def test_displays_trimmed_content(self):
        fake = Faker()
        post = util.save_valid_post_object(content=fake.sentence(nb_words=100))

        response = self.client.get(reverse('home'))

        trimmed_content = post.content[:97] + '...'
        self.assertContains(response, trimmed_content)
Пример #2
0
    def test_for_invalid_post_nothing_saved_to_db(self):
        correct_post = util.save_valid_post_object()

        incorrect_post = copy.deepcopy(correct_post)
        incorrect_post.title = ''

        self.POST_object_to_update_url(incorrect_post)

        saved_post = Post.objects.first()

        self.assertPostIsSavedCorrectly(correct_post, saved_post)
Пример #3
0
    def test_can_save_a_valid_POST_request(self):
        post = util.save_valid_post_object()

        post.title = 'New title'
        post.content = 'New content'
        ## We put a new temporary image
        post.image = util.get_test_image()
        post.publication_date = post.publication_date + datetime.timedelta(3)
        post.expiring_date = post.expiring_date + datetime.timedelta(1)

        self.POST_object_to_update_url(post)

        self.assertEqual(Post.objects.count(), 1)
        saved_post = Post.objects.first()

        self.assertPostIsSavedCorrectly(post=post, saved_post=saved_post)
Пример #4
0
    def post_invalid_post(self):
        post = util.save_valid_post_object()

        post.title = ''

        return self.POST_object_to_update_url(post)
Пример #5
0
 def test_POST_redirects_to_show_post_view(self):
     post = util.save_valid_post_object()
     response = self.POST_object_to_update_url(post)
     post = Post.objects.first()
     self.assertRedirects(
         response, reverse('posts:show', kwargs={'post_id': post.id}))