Exemplo n.º 1
0
        def test_comment_create_post_request_not_allowed(self, api_client):
            new_user = UserFactory()
            comment_data = CommentFactory.build()
            new_recipe = RecipeFactory()

            data = {
                'title': {comment_data.title},
                'recipe': {new_recipe.id},
                'author': {new_user.id}
            }
            response = api_client.post(create_comment_url, data)

            assert response.status_code == 401
Exemplo n.º 2
0
        def test_comment_author_is_current_logged_in_user(self, api_client):
            ''' testing the method perform_create '''
            new_user = UserFactory()
            api_client.force_authenticate(new_user)
            new_recipe = RecipeFactory()
            comment_data = CommentFactory.build()

            data = {
                'title': {comment_data.title},
                'recipe': {new_recipe.id},
                'author': {new_user.id}
            }
            api_client.post(create_comment_url, data)
            new_comment = Comment.objects.get(title=comment_data.title)

            assert new_comment.author == new_user
Exemplo n.º 3
0
        def test_recipe_author_can_delete_other_users_recipe_comments_on_his_recipe(
                self, api_client):
            new_recipe = RecipeFactory()
            new_user = UserFactory()
            api_client.force_authenticate(new_user)
            comment_data = CommentFactory.build()

            data = {
                'title': {comment_data.title},
                'recipe': {new_recipe.id},
                'author': {new_user.id}
            }
            response = api_client.post(create_comment_url, data)

            api_client.logout()
            api_client.force_authenticate(new_recipe.author)
            new_comment = Comment.objects.get(title=comment_data.title)
            response = api_client.delete(new_comment.get_delete_url())

            assert response.status_code == 204