Пример #1
0
        def test_author_can_update_own_comment(self, api_client):
            new_comment = CommentFactory()
            api_client.force_authenticate(new_comment.author)
            data = {'title': 'updated title'}
            response = api_client.patch(new_comment.get_absolute_url(), data)

            assert response.status_code == 200
Пример #2
0
    def test_parse_comment(self):

        response = '''{"response":[6,
            {"cid":2505,"uid":16271479,"date":1298365200,"text":"Добрый день , кароче такая идея когда опросы создаешь вместо статуса - можно выбрать аудитории опрашиваемых, например только женский или мужской пол могут участвовать (то бишь голосовать в опросе)."},
            {"cid":2507,"uid":16271479,"date":1286105582,"text":"Это уже не практично, имхо.<br>Для этого делайте группу и там опрос, а в группу принимайте тех, кого нужно.","reply_to_uid":16271479,"reply_to_cid":2505},
            {"cid":2547,"uid":2943,"date":1286218080,"text":"Он будет только для групп благотворительных организаций."}]}
            '''
        user = UserFactory(remote_id=USER_ID)
        post = PostFactory(remote_id=POST_ID, wall_owner=user)
        #instance = Comment(post=post)
        instance = CommentFactory(post=post)
        author = UserFactory(remote_id=16271479)
        instance.parse(json.loads(response)['response'][1])
        instance.save()

        self.assertEqual(instance.remote_id, '%s_2505' % USER_ID)
        self.assertEqual(
            instance.text,
            u'Добрый день , кароче такая идея когда опросы создаешь вместо статуса - можно выбрать аудитории опрашиваемых, например только женский или мужской пол могут участвовать (то бишь голосовать в опросе).'
        )
        self.assertEqual(instance.author, author)
        self.assertTrue(isinstance(instance.date, datetime))

        instance = Comment(post=post)
        instance.parse(json.loads(response)['response'][2])
        instance.save()

        self.assertEqual(instance.remote_id, '%s_2507' % USER_ID)
        self.assertEqual(instance.reply_for.remote_id, 16271479)
Пример #3
0
        def test_not_author_cant_delete_comment(self, api_client):
            new_comment = CommentFactory()
            random_user = UserFactory()
            api_client.force_authenticate(random_user)
            response = api_client.delete(new_comment.get_absolute_url())

            assert response.status_code == 403
Пример #4
0
        def test_comment_detail_page_render(self, api_client):
            new_comment = CommentFactory()
            api_client.force_authenticate(new_comment.author)

            response = api_client.get(new_comment.get_absolute_url())

            assert response.status_code == 200
Пример #5
0
        def test_not_author_cant_update_comment(self, api_client):
            new_comment = CommentFactory()
            random_user = UserFactory()
            api_client.force_authenticate(random_user)
            data = {'title': 'updated title'}
            response = api_client.patch(new_comment.get_absolute_url(), data)

            assert response.status_code == 403
Пример #6
0
    def test_fetch_group_post_comment_likes(self, *args, **kwargs):
        group = GroupFactory(remote_id=GROUP_ID)
        post = PostFactory(remote_id=GROUP_POST_ID, wall_owner=group)
        comment = CommentFactory(remote_id=GROUP_COMMENT_ID,
                                 post=post,
                                 wall_owner=group)

        self.assertEqual(comment.like_users.count(), 0)
        self.assertEqual(comment.likes, 0)
        users_initial = User.objects.count()

        users = comment.fetch_likes(all=True)

        self.assertTrue(comment.likes > 0)
        self.assertEqual(comment.likes, len(users))
        self.assertEqual(comment.likes, User.objects.count() - users_initial)
        self.assertEqual(comment.likes, comment.like_users.count())
Пример #7
0
 def fetch_post_comments_recursive_calls_ammount_side_effect(
         *args, **kwargs):
     comments_count = 100 if kwargs['offset'] == 0 else 6
     comments = [CommentFactory() for i in range(comments_count)]
     return Comment.objects.filter(
         pk__in=[comment.pk for comment in comments])
Пример #8
0
        def test_guest_user_cant_update_comment(self, api_client):
            first_comment = CommentFactory()
            data = {'title': 'updated title'}
            response = api_client.patch(first_comment.get_absolute_url(), data)

            assert response.status_code == 401
Пример #9
0
        def test_comment_delete(self, api_client):
            new_comment = CommentFactory()
            response = api_client.delete(new_comment.get_absolute_url())

            assert response.status_code == 401
Пример #10
0
        def test_author_can_delete_own_comment(self, api_client):
            new_comment = CommentFactory()
            api_client.force_authenticate(new_comment.author)
            response = api_client.delete(new_comment.get_absolute_url())

            assert response.status_code == 204
Пример #11
0
 def test_detail_resolve(self):
     new_comment = CommentFactory()
     url = f'/api/comments/delete/{new_comment.id}/'
     assert resolve(url).view_name == 'comments:delete'
Пример #12
0
 def test_detail_reverse(self):
     new_comment = CommentFactory()
     url = reverse('comments:delete', kwargs={'pk': new_comment.id})
     assert url == f'/api/comments/delete/{new_comment.id}/'
Пример #13
0
def test_get_delete_url():
    new_comment = CommentFactory()

    assert new_comment.get_delete_url() == reverse(
        'comments:delete', kwargs={"pk": new_comment.id})
Пример #14
0
def test_get_absolute_url():
    new_comment = CommentFactory()

    assert new_comment.get_absolute_url() == reverse(
        'comments:detail', kwargs={"pk": new_comment.id})
Пример #15
0
def test__str__():
    new_comment = CommentFactory()

    assert new_comment.__str__() == new_comment.title