Example #1
0
    def test_parse_comments(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":"Он будет только для групп благотворительных организаций."}]}
            '''
        group = GroupFactory.create(remote_id=OWNER_ID)
        post = PostFactory.create(remote_id=TR_POST_ID, wall_owner=group)
        instance = CommentFactory.create(post=post)
        author = UserFactory.create(remote_id=16271479)
        instance.parse(json.loads(response)['response'][1])
        instance.save()

        self.assertEqual(instance.remote_id, '201164356_2505')
        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, '201164356_2507')
        self.assertEqual(instance.reply_for.remote_id, 16271479)
Example #2
0
    def test_comment_crud_methods(self):
        text = 'Test message'
        user = UserFactory.create(remote_id=TRAVIS_USER_ID)
        post = PostFactory.create(remote_id=TR_POST_ID, wall_owner=user)
        mock_comment = CommentFactory.create(text=text, post=post, wall_owner=user)

        # Create
        comment = Comment.objects.create(
                **CommentFactory.get_mock_params_dict(
                    mock_comment, commit_remote=True)
        )

        self.assertTrue(comment.remote_id > 0)
        self.assertEqual(comment.text, text)

        fetched_comment = post.fetch_comments(sort='asc').first()
        self.assertEqual(fetched_comment.text, text)

        # Update
        edited_message = 'Edited comment message'
        comment = Comment.objects.get(id=comment.id)
        comment.text = edited_message
        comment.save(commit_remote=True)

        self.assertEqual(comment.text, edited_message)

        fetched_comment = post.fetch_comments(sort='asc').first()
        self.assertEqual(fetched_comment.text, edited_message)

        # Delete
        comment.delete()
        comment1 = Comment.objects.get(id=comment.id)
        self.assertTrue(comment1.archived)

        fetched_ids = [comment.remote_id for comment in post.fetch_comments()]
        self.assertFalse(comment1.remote_id in fetched_ids)

        # Restore
        comment.restore()
        comment1 = Comment.objects.get(id=comment.id)
        self.assertFalse(comment1.archived)

        fetched_ids = [comment.remote_id for comment in post.fetch_comments()]
        self.assertTrue(comment1.remote_id in fetched_ids)

        # Create with save()
        comment = Comment()
        comment.__dict__.update(
            CommentFactory.get_mock_params_dict(mock_comment)
        )
        comment.text = text + text
        comment.save(commit_remote=True)

        self.assertTrue(comment.remote_id > 0)
        self.assertEqual(comment.text, text + text)

        fetched_comment = post.fetch_comments(sort='asc').first()
        self.assertEqual(fetched_comment.text, text + text)

        comment.delete()
Example #3
0
    def test_fetch_group_post_comments(self, *args, **kwargs):
        group = GroupFactory.create(remote_id=GROUP_ID, screen_name=GROUP_SCREEN_NAME)
        post = PostFactory.create(remote_id=GROUP_POST_ID, wall_owner=group)
        self.assertEqual(Comment.objects.count(), 0)

        comments = post.fetch_comments(sort='desc', count=90)

        self.assertTrue(len(comments) == Comment.objects.count() == post.wall_comments.count() == 90)
        self.assertEqual(comments[0].post, post)
        self.assertEqual(comments[0].wall_owner, group)

        # testing `after` parameter
        after = Comment.objects.order_by('date')[0].date

        Comment.objects.all().delete()
        self.assertEqual(Comment.objects.count(), 0)

        comments = post.fetch_comments(sort='desc', after=after, count=100)
        self.assertTrue(len(comments) == Comment.objects.count() == post.wall_comments.count() == 90)

        # testing `after` and `all` parameters
        Comment.objects.all().delete()
        self.assertEqual(Comment.objects.count(), 0)

        comments = post.fetch_comments(sort='desc', after=after, all=True)
        self.assertTrue(len(comments) == Comment.objects.count() == post.wall_comments.count() == 90)
Example #4
0
 def test_post_prepare_delete_restore_params(self):
     group = GroupFactory.create(remote_id=OWNER_ID)
     post = PostFactory.create(remote_id='%s_17' % OWNER_ID, wall_owner=group)
     expected_params = {
         'owner_id': OWNER_ID,
         'post_id': '17',
     }
     self.assertEqual(post.prepare_delete_restore_params(), expected_params)
Example #5
0
    def test_fetch_post_reposts(self, *args, **kwargs):

        group = GroupFactory.create(remote_id=GROUP_ID)
        post = PostFactory.create(remote_id=GROUP_POST_ID, wall_owner=group)

        self.assertTrue(post.repost_users.count() == 0)
        users = post.fetch_reposts(all=True)
        self.assertTrue(post.reposts >= 20)
        self.assertTrue(post.reposts == post.repost_users.count() == users.count())

        group = GroupFactory.create(remote_id=36948301)
        post = PostFactory.create(remote_id='-36948301_13599', wall_owner=group)

        self.assertTrue(post.reposts == post.repost_users.count() == 0)
        users = post.fetch_reposts(all=True)
        self.assertTrue(post.reposts == 1)
        self.assertTrue(post.reposts == post.repost_users.count() == users.count())
Example #6
0
    def test_post_crud_methods(self):
        message = 'Test message'
        user = UserFactory.create(remote_id=TRAVIS_USER_ID)
        mock_post = PostFactory.create(text=message, wall_owner=user)

        #create by objects api
        post = Post.objects.create(
                **PostFactory.get_mock_params_dict(
                    mock_post, commit_remote=True)
        )

        self.assertTrue(post.remote_id > 0)
        self.assertEqual(post.text, message)

        fetched_post = Post.remote.fetch(ids=[post.remote_id]).first()
        self.assertEqual(fetched_post.text, post.text)

        # Update
        edited_message = 'Edited message with CRUD'
        post = Post.objects.get(id=post.id)
        post.text = edited_message
        post.save(commit_remote=True)
        self.assertEqual(post.text, edited_message)

        fetched_post = Post.remote.fetch(ids=[post.remote_id]).first()
        self.assertEqual(fetched_post.text, edited_message)

        # Delete
        post.delete()
        post1 = Post.objects.get(id=post.id)
        self.assertTrue(post1.archived)

        fetched_post = Post.remote.fetch(ids=[post.remote_id])
        self.assertFalse(fetched_post)

        # Restore
        post.restore()
        post1 = Post.objects.get(id=post.id)
        self.assertFalse(post1.archived)

        fetched_post = Post.remote.fetch(ids=[post1.remote_id])
        self.assertTrue(fetched_post)

        post.delete()

        # Create with save()
        post = Post()
        post.__dict__.update(PostFactory.get_mock_params_dict(mock_post))
        post.text = message + message
        post.save(commit_remote=True)

        self.assertTrue(post.remote_id > 0)
        self.assertEqual(post.text, message + message)

        fetched_post = Post.remote.fetch(ids=[post.remote_id]).first()
        self.assertEqual(fetched_post.text, post.text)

        post.delete()
Example #7
0
    def test_fetch_post_comments_recursive_calls_ammount(self, fetch_method, *args, **kwargs):

        post = PostFactory.create(remote_id=TR_POST_ID)
        comments = post.fetch_comments(sort='desc', all=True)

        self.assertTrue(len(comments) > 105)
        self.assertEqual(fetch_method.called, True)
        self.assertEqual(fetch_method.call_count, 2)
        self.assertEqual(fetch_method.call_args_list[0][1]['offset'], 0)
        self.assertEqual(fetch_method.call_args_list[1][1]['offset'], 100)
Example #8
0
    def test_fetch_comment_likes(self, *args, **kwargs):
        user = UserFactory.create(remote_id=TRAVIS_USER_ID)
        post = PostFactory.create(remote_id=TR_POST_ID, wall_owner=user)
        comment = post.fetch_comments().last()

        self.assertTrue(comment.like_users.count() == 0)

        comment.fetch_likes(all=True)
        self.assertTrue(comment.like_users.count() >= 1)
        self.assertTrue(comment.likes >= 1)
Example #9
0
    def test_fetch_user_post_comments(self):
        owner = UserFactory.create(remote_id=TRAVIS_USER_ID)
        post = PostFactory.create(remote_id=TR_POST_ID, wall_owner=owner)
        self.assertEqual(Comment.objects.count(), 0)

        comments = post.fetch_comments()

        self.assertTrue(len(comments) > 0)
        self.assertEqual(Comment.objects.count(), len(comments))
        self.assertEqual(comments[0].post, post)

        post.fetch_comments(all=True)
Example #10
0
    def test_fetch_post_likes(self, *args, **kwargs):

        group = GroupFactory.create(remote_id=GROUP_ID)
        post = PostFactory.create(remote_id=GROUP_POST_ID, wall_owner=group)

        self.assertTrue(post.likes == post.like_users.count() == 0)

        post.fetch_likes(source='parser')
        self.assertTrue(post.likes == post.like_users.count() > 120)

        post.like_users.all().delete()
        post.likes = 0
        post.save()
        self.assertTrue(post.likes == post.like_users.count() == 0)

        post.fetch_likes(all=True)
        self.assertTrue(post.likes == post.like_users.count() > 120)
Example #11
0
 def test_post_prepare_update_params(self):
     group = GroupFactory.create(remote_id=OWNER_ID)
     post = PostFactory.create(remote_id='%s_17' % OWNER_ID, wall_owner=group)
     update_text = 'update text'
     expected_config = {
         'owner_id': OWNER_ID,
         'friends_only': 0,
         'from_group': '',
         'message': update_text,
         'attachments': u'',
         'services': '',
         'signed': 0,
         'publish_date': '',
         'lat': '',
         'long': '',
         'place_id': '',
         'post_id': '17'
     }
     post1 = Post.objects.get(id=post.id)
     post1.text = update_text
     self.assertEqual(post1.prepare_update_params(), expected_config)
Example #12
0
 def test_post_prepare_create_params(self):
     text = 'test text'
     expected_config = {
         'owner_id': OWNER_ID,
         'friends_only': 0,
         'from_group': '',
         'message': text,
         'attachments': u'',
         'services': '',
         'signed': 0,
         'publish_date': '',
         'lat': '',
         'long': '',
         'place_id': '',
         'post_id': ''
     }
     group = GroupFactory.create(remote_id=OWNER_ID)
     post = PostFactory.create()
     post.wall_owner = group
     post.text = text
     self.assertEqual(post.prepare_create_params(), expected_config)