Exemplo n.º 1
0
    def test_parse_topic(self):

        response = '''
            {"response":{
                "count":1,
                "items":[
                    {"id":51443905,
                    "title":"Вопросы по поводу создания приложений",
                    "created":1298365200,
                    "created_by":1,
                    "updated":0,
                    "updated_by":1,
                    "is_closed":0,
                    "is_fixed":1,
                    "comments":5045}
                ]
            }}'''
        instance = Topic.remote.parse_response(
            json.loads(response)['response'],
            {'group_id': GroupFactory(remote_id=GROUP_ID).pk})[0]
        instance.save()

        self.assertEqual(instance.remote_id, '-%s_51443905' % GROUP_ID)
        self.assertEqual(instance.group.remote_id, GROUP_ID)
        self.assertEqual(instance.title,
                         u'Вопросы по поводу создания приложений')
        self.assertEqual(instance.created_by, User.objects.get(remote_id=1))
        self.assertEqual(instance.updated_by, User.objects.get(remote_id=1))
        self.assertEqual(instance.is_closed, False)
        self.assertEqual(instance.is_fixed, True)
        self.assertEqual(instance.comments_count, 5045)
        self.assertIsNotNone(instance.created)
        self.assertIsNone(instance.updated)
Exemplo n.º 2
0
        def test_video_fetch_comments(self, *kwargs):

            owner = GroupFactory(remote_id=GROUP_ID)
            #album = AlbumFactory(remote_id=ALBUM_ID, owner=owner)
            # not factory coz we need video.comments_count later
            video = Video.remote.fetch(owner=owner, ids=[VIDEO_ID])[0]

            comments = video.fetch_comments(count=10, sort='desc')
            self.assertEqual(len(comments), video.comments.count())
            self.assertEqual(len(comments), 10)

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

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

            comments = video.fetch_comments(after=after, sort='desc')
            self.assertEqual(len(comments), Comment.objects.count())
            self.assertEqual(len(comments), video.comments.count())
            self.assertEqual(len(comments), 3)

            date = comments[0].date
            self.assertGreaterEqual(date, after)

            # testing `all` parameter
            Comment.objects.all().delete()
            self.assertEqual(Comment.objects.count(), 0)

            comments = video.fetch_comments(all=True)
            self.assertEqual(len(comments), Comment.objects.count())
            self.assertEqual(len(comments), video.comments.count())
            self.assertEqual(len(comments), video.comments_count)
            self.assertTrue(video.comments.count() > 10)
    def test_fetch_statistic(self):

        group = GroupFactory(remote_id=GROUP_ID)
        self.assertEqual(GroupStat.objects.count(), 0)

        group.fetch_statistic()
        self.assertGreater(GroupStat.objects.count(), 350)

        stat = GroupStat.objects.filter(period=30)[0]
        self.assertGreater(stat.views, 0)
        self.assertGreater(stat.visitors, 0)
        self.assertIsInstance(stat.date, date)

        stat = GroupStat.objects.filter(period=1)[0]
        self.assertGreater(stat.members, 0)
        self.assertGreater(stat.views, 0)
        self.assertGreater(stat.visitors, 0)
        self.assertGreater(stat.males, 0)
        self.assertGreater(stat.females, 0)
        self.assertIsInstance(stat.date, date)

        # test date_from argument
        date_from = timezone.now() - timedelta(5)
        stat_month_count = GroupStat.objects.filter(period=30).count()
        GroupStat.objects.all().delete()

        group.fetch_statistic(date_from=date_from)
        self.assertEqual(GroupStat.objects.filter(period=1).count(), 6)
        self.assertEqual(
            GroupStat.objects.filter(period=30).count(), stat_month_count)
Exemplo n.º 4
0
    def test_fetch_photo_comments(self, *kwargs):

        group = GroupFactory(remote_id=GROUP_ID)
        album = AlbumFactory(remote_id=ALBUM_ID, owner=group)
        photo = PhotoFactory(remote_id=PHOTO_ID, album=album, owner=group)

        comments = photo.fetch_comments(count=20, sort='desc')
        self.assertEqual(comments.count(), photo.comments.count())
        self.assertEqual(comments.count(), 20)

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

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

        comments = photo.fetch_comments(after=after, sort='desc')
        self.assertEqual(comments.count(), Comment.objects.count())
        self.assertEqual(comments.count(), photo.comments.count())
        self.assertEqual(comments.count(), comments_count)

        # testing `all` parameter
        Comment.objects.all().delete()
        self.assertEqual(Comment.objects.count(), 0)

        comments = photo.fetch_comments(all=True)
        self.assertEqual(comments.count(), Comment.objects.count())
        self.assertEqual(comments.count(), photo.comments.count())
        self.assertGreater(photo.comments.count(), comments_count)
Exemplo n.º 5
0
    def test_parse_album(self):

        response = '''{"response":[{"id":16178407,"thumb_id":"96509883","owner_id":6492,"title":"qwerty",
            "description":"desc","created":"1298365200","updated":"1298365201","size":"3",
            "privacy":"3"},{"id":"17071606","thumb_id":"98054577","owner_id":-6492,
            "title":"","description":"","created":"1204576880","updated":"1229532461",
            "size":"3","privacy":"0"}]}
            '''
        instance = Album()
        owner = UserFactory(remote_id=6492)
        instance.parse(json.loads(response)['response'][0])
        instance.save()

        self.assertEqual(instance.remote_id, 16178407)
        self.assertEqual(instance.thumb_id, 96509883)
        self.assertEqual(instance.owner, owner)
        self.assertEqual(instance.title, 'qwerty')
        self.assertEqual(instance.description, 'desc')
        self.assertEqual(instance.size, 3)
        self.assertEqual(instance.privacy, 3)
        self.assertIsNotNone(instance.created)
        self.assertIsNotNone(instance.updated)

        instance = Album()
        group = GroupFactory(remote_id=6492)
        instance.parse(json.loads(response)['response'][1])
        instance.save()

        self.assertEqual(instance.remote_id, 17071606)
        self.assertEqual(instance.owner, group)
Exemplo n.º 6
0
    def test_fetch_comments(self):

        group = GroupFactory(remote_id=GROUP_ID)
        topic = TopicFactory(remote_id=TOPIC_ID, group=group)

        comments = topic.fetch_comments(count=20, sort='desc')
        self.assertEqual(len(comments), topic.comments.count())
        self.assertEqual(len(comments), 20)

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

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

        comments = topic.fetch_comments(after=after, sort='desc')
        self.assertEqual(len(comments), Comment.objects.count())
        self.assertEqual(len(comments), topic.comments.count())
        self.assertEqual(len(comments), 20)

        # testing `all` parameter
        Comment.objects.all().delete()
        self.assertEqual(Comment.objects.count(), 0)

        comments = topic.fetch_comments(all=True)
        self.assertEqual(len(comments), Comment.objects.count())
        self.assertEqual(len(comments), topic.comments.count())
        self.assertTrue(len(comments) > 20)
Exemplo n.º 7
0
    def test_fetch_comments_of_deleted_topic(self):

        group = GroupFactory(remote_id=17589818)
        topic = TopicFactory(remote_id='-17589818_26390905', group=group)

        comments = topic.fetch_comments()
        self.assertEqual(topic.comments.count(), 0)
        self.assertEqual(topic.comments.count(), len(comments))
Exemplo n.º 8
0
    def test_fetch_photo_comments_parser(self):

        group = GroupFactory(remote_id=GROUP_ID)
        album = AlbumFactory(remote_id=ALBUM_ID, group=group)
        photo = PhotoFactory(remote_id=PHOTO_ID, album=album)

        self.assertEqual(photo.comments, 0)
        photo.fetch_comments_parser()
        self.assertTrue(photo.comments > 0)
Exemplo n.º 9
0
    def test_fetch_photo_likes_parser(self):

        group = GroupFactory(remote_id=GROUP_ID)
        album = AlbumFactory(remote_id=ALBUM_ID, group=group)
        photo = PhotoFactory(remote_id=PHOTO_ID, album=album)

        self.assertEqual(photo.likes_count, 0)
        photo.fetch_likes_parser()
        self.assertGreater(photo.likes_count, 0)
Exemplo n.º 10
0
    def test_fetch_photo_comments_parser(self):

        group = GroupFactory(remote_id=GROUP_ID)
        album = AlbumFactory(remote_id=ALBUM_ID, owner=group)
        photo = PhotoFactory(remote_id=PHOTO_ID, album=album, owner=group)

        #self.assertEqual(photo.comments_count, 0)
        photo.fetch_comments_parser()
        self.assertGreater(photo.comments_count, 0)
Exemplo n.º 11
0
    def test_fetch_photo_likes(self):

        group = GroupFactory(remote_id=GROUP_ID)
        album = AlbumFactory(remote_id=ALBUM_ID, group=group)
        photo = PhotoFactory(remote_id=PHOTO_ID, album=album, group=group)

        self.assertEqual(photo.likes, 0)
        users = photo.fetch_likes(all=True)
        self.assertTrue(photo.likes > 0)
        self.assertEqual(photo.likes, len(users))
Exemplo n.º 12
0
    def test_fetch_topics(self):

        group = GroupFactory(remote_id=GROUP_ID)
        group.fetch_topics()

        self.assertTrue(group.topics.count() > 10)

        topics = group.fetch_topics(all=True, extended=True)

        self.assertTrue(topics.count() > 10)
Exemplo n.º 13
0
    def test_fetch_group_albums(self):

        group = GroupFactory(remote_id=GROUP_ID)

        self.assertEqual(Album.objects.count(), 0)

        albums = group.fetch_albums()

        self.assertTrue(len(albums) > 0)
        self.assertEqual(Album.objects.count(), len(albums))
        self.assertEqual(albums[0].group, group)
Exemplo n.º 14
0
    def test_upload_to_group_album(self):
        group = GroupFactory(remote_id=59154616)
        album = AlbumFactory(remote_id=209832918, owner=group)

        caption = 'test_upload'
        photos = album.upload_photos(self.files, caption=caption)

        self.objects_to_delete += photos  # delete photos

        self.assertEqual(len(photos), len(self.files))
        self.assertEqual(photos[0].text, caption)
Exemplo n.º 15
0
        def test_comment_wall_crud_methods(self):
            group = GroupFactory(remote_id=GROUP_CRUD_ID)
            post = PostFactory(remote_id=POST_CRUD_ID, text='', owner=group)
            user = UserFactory(remote_id=self.token_user_id)

            self.assertNoCommentsForObject(post)

            # create
            Comment.remote.fetch_by_object(object=post)
            self.assertEqual(Comment.objects.count(), 0)

            # create
            comment = Comment(text='Test comment', object=post, owner=group, author=user, date=timezone.now())
            comment.save(commit_remote=True)
            self.objects_to_delete += [comment]

            self.assertEqual(Comment.objects.count(), 1)
            self.assertNotEqual(len(comment.remote_id), 0)
            self.assertCommentTheSameEverywhere(comment)

            # create by manager
            comment = Comment.objects.create(
                text='Test comment created by manager', object=post, owner=group, author=user, date=timezone.now(), commit_remote=True)
            self.objects_to_delete += [comment]

            self.assertEqual(Comment.objects.count(), 2)
            self.assertNotEqual(len(comment.remote_id), 0)
            self.assertCommentTheSameEverywhere(comment)

            # update
            comment.text = 'Test comment updated'
            comment.save(commit_remote=True)

            self.assertEqual(Comment.objects.count(), 2)
            self.assertCommentTheSameEverywhere(comment)

            # delete
            comment.delete(commit_remote=True)

            self.assertEqual(Comment.objects.count(), 2)
            self.assertTrue(comment.archived)
            self.assertEqual(Comment.remote.fetch_by_object(
                object=comment.object).filter(remote_id=comment.remote_id).count(), 0)

            # restore
            comment.restore(commit_remote=True)
            self.assertFalse(comment.archived)

            self.assertEqual(Comment.objects.count(), 2)
            self.assertCommentTheSameEverywhere(comment)
    def test_fetch_statistic_via_api(self):

        group = GroupFactory(remote_id=GROUP_ID)
        self.assertEqual(GroupStatistic.objects.count(), 0)

        group.fetch_statistic(source='api')
        self.assertGreater(GroupStatistic.objects.count(), 0)

        stat = GroupStatistic.objects.all()[0]
        self.assertGreater(stat.views, 0)
        self.assertGreater(stat.visitors, 0)
        self.assertGreater(stat.males, 0)
        self.assertGreater(stat.females, 0)
        self.assertIsInstance(stat.date, date)
Exemplo n.º 17
0
        def test_comment_video_crud_methods(self):
            owner = GroupFactory(remote_id=GROUP_CRUD_ID)
            album = AlbumFactory(remote_id=ALBUM_CRUD_ID, owner=owner)
            video = VideoFactory(remote_id=VIDEO_CRUD_ID, album=album, owner=owner)

            self.assertNoCommentsForObject(video)

            # create
            comment = Comment(text='Test comment', object=video, author=owner, date=timezone.now())
            comment.save(commit_remote=True)
            self.objects_to_delete += [comment]

            self.assertEqual(Comment.objects.count(), 1)
            self.assertEqual(comment.author, owner)
            self.assertNotEqual(len(comment.remote_id), 0)
            self.assertCommentTheSameEverywhere(comment)

            # create by manager
            comment = Comment.objects.create(
                text='Test comment created by manager', object=video, author=owner, date=timezone.now(), commit_remote=True)
            self.objects_to_delete += [comment]
            self.assertEqual(Comment.objects.count(), 2)

            self.assertEqual(Comment.objects.count(), 2)
            self.assertEqual(comment.author, owner)
            self.assertNotEqual(len(comment.remote_id), 0)
            self.assertCommentTheSameEverywhere(comment)

            # update
            comment.text = 'Test comment updated'
            comment.save(commit_remote=True)

            self.assertEqual(Comment.objects.count(), 2)
            self.assertCommentTheSameEverywhere(comment)

            # delete
            comment.delete(commit_remote=True)

            self.assertEqual(Comment.objects.count(), 2)
            self.assertTrue(comment.archived)
            self.assertEqual(Comment.remote.fetch_by_object(
                object=comment.object).filter(remote_id=comment.remote_id).count(), 0)

            # restore
            comment.restore(commit_remote=True)
            self.assertFalse(comment.archived)

            self.assertEqual(Comment.objects.count(), 2)
            self.assertCommentTheSameEverywhere(comment)
Exemplo n.º 18
0
    def test_fetch_group_photos(self):

        group = GroupFactory(remote_id=GROUP_ID)
        album = AlbumFactory(remote_id=ALBUM_ID, group=group)

        self.assertEqual(Photo.objects.count(), 0)

        photos = album.fetch_photos(extended=True)

        self.assertTrue(len(photos) > 0)
        self.assertEqual(Photo.objects.count(), len(photos))
        self.assertEqual(photos[0].group, group)
        self.assertEqual(photos[0].album, album)
        self.assertTrue(photos[0].likes > 0)
        self.assertTrue(photos[0].comments > 0)
Exemplo n.º 19
0
    def test_fetch_photo_likes(self, *kwargs):

        group = GroupFactory(remote_id=GROUP_ID)
        album = AlbumFactory(remote_id=ALBUM_ID, owner=group)
        photo = PhotoFactory(remote_id=PHOTO_ID, album=album, owner=group)

        self.assertEqual(photo.likes_count, 0)
        users_initial = User.objects.count()

        users = photo.fetch_likes(all=True)

        self.assertGreater(photo.likes_count, 0)
        self.assertEqual(photo.likes_count, len(users))
        self.assertEqual(photo.likes_count,
                         User.objects.count() - users_initial)
        self.assertEqual(photo.likes_count, photo.likes_users.count())
Exemplo n.º 20
0
    def test_parse_comment(self):

        response = '''{"response":[21, {"date": 1387173931, "message": "[id94721323|\u0410\u043b\u0435\u043d\u0447\u0438\u043a], \u043d\u0435 1 \u0430 3 \u0431\u0430\u043d\u043a\u0430 5 \u043b\u0438\u0442\u0440\u043e\u0432 =20 \u0431\u0430\u043b\u043b\u043e\u0432", "from_id": 232760293, "likes": {"count": 1, "can_like": 1, "user_likes": 0}, "id": 91121},
            {"date": 1386245221, "message": "\u0410 1\u043b. \u0432 \u043f\u043e\u0434\u0430\u0440\u043e\u043a,\u0431\u043e\u043d\u0443\u0441 +))))", "from_id": 94721323, "likes": {"count": 0, "can_like": 1, "user_likes": 0}, "id": 88976},
            {"date": 1354592120, "message": "\u0445\u0430\u0445<br>", "from_id": 138571769, "likes": {"count": 0, "can_like": 1, "user_likes": 0}, "cid": 50392}]}
        '''
        group = GroupFactory(remote_id=GROUP_ID)
        album = AlbumFactory(remote_id=ALBUM_ID, owner=group)
        photo = PhotoFactory(remote_id=PHOTO_ID, album=album, owner=group)
        instance = Comment(object=photo)
        instance.parse(json.loads(response)['response'][1])
        instance.save()

        self.assertEqual(instance.remote_id, '-%s_91121' % GROUP_ID)
        self.assertEqual(instance.object, photo)
        self.assertEqual(instance.author.remote_id, 232760293)
        self.assertGreater(len(instance.text), 10)
        self.assertIsNotNone(instance.date)
Exemplo n.º 21
0
    def test_parse_photo(self):

        response = '''{"response":[{"pid":"146771291","aid":"100001227","owner_id":"6492",
            "src":"http://cs9231.vkontakte.ru/u06492/100001227/m_7875d2fb.jpg",
            "src_big":"http://cs9231.vkontakte.ru/u06492/100001227/x_cd563004.jpg",
            "src_small":"http://cs9231.vkontakte.ru/u06492/100001227/s_c3bba2a8.jpg",
            "src_xbig":"http://cs9231.vkontakte.ru/u06492/100001227/y_62a74569.jpg",
            "src_xxbig":"http://cs9231.vkontakte.ru/u06492/100001227/z_793e9682.jpg",
            "text":"test","user_id":6492,"width":10,"height":10,
            "created":"1298365200"},{"pid":"146772677","aid":"100001227","owner_id":-6492,
            "src":"http://cs9231.vkontakte.ru/u06492/100001227/m_fd092958.jpg",
            "src_big":"http://cs9231.vkontakte.ru/u06492/100001227/x_1f8ec9b8.jpg",
            "src_small":"http://cs9231.vkontakte.ru/u06492/100001227/s_603d27ab.jpg",
            "src_xbig":"http://cs9231.vkontakte.ru/u06492/100001227/y_6938f576.jpg",
            "src_xxbig":"http://cs9231.vkontakte.ru/u06492/100001227/z_6a27e9fd.jpg",
            "text":"test","user_id":6492,"width":10,"height":10,
            "created":"1260887080"}]}
            '''
        instance = Photo()
        owner = UserFactory(remote_id=6492)
        album = AlbumFactory(remote_id='6492_100001227')
        instance.parse(json.loads(response)['response'][0])
        instance.save()

        self.assertEqual(instance.remote_id, '6492_146771291')
        self.assertEqual(instance.album, album)
        self.assertEqual(instance.owner, owner)
        self.assertEqual(
            instance.src,
            'http://cs9231.vkontakte.ru/u06492/100001227/m_7875d2fb.jpg')
        self.assertEqual(instance.text, 'test')
        self.assertEqual(instance.width, 10)
        self.assertEqual(instance.height, 10)
        self.assertIsNotNone(instance.created)

        instance = Photo()
        group = GroupFactory(remote_id=6492)
        album = AlbumFactory(remote_id='-6492_100001227')
        instance.parse(json.loads(response)['response'][1])
        instance.save()

        self.assertEqual(instance.remote_id, '-6492_146772677')
        self.assertEqual(instance.album, album)
        self.assertEqual(instance.group, group)
Exemplo n.º 22
0
        def test_fetch_with_count_and_offset(self):
            # testing `count` parameter, count is the same as limit
            owner = GroupFactory(remote_id=GROUP_ID)
            album = AlbumFactory(remote_id=ALBUM_ID, owner=owner)
            video = VideoFactory(remote_id=VIDEO_ID, album=album, owner=owner)

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

            comments = video.fetch_comments(count=5)

            self.assertEqual(len(comments), 5)
            self.assertEqual(Comment.objects.count(), 5)

            # testing `offset` parameter
            comments2 = video.fetch_comments(count=2, offset=4)

            self.assertEqual(len(comments2), 2)
            self.assertEqual(Comment.objects.count(), 6)

            self.assertEqual(comments[4].remote_id, comments2[0].remote_id)
Exemplo n.º 23
0
    def test_parse_photo(self):

        response = '''{"response":[{"id":"146771291","album_id":"100001227","owner_id":6492,
            "photo_130":"http://cs9231.vkontakte.ru/u06492/100001227/m_7875d2fb.jpg",
            "text":"test","user_id":6492,"width":10,"height":10,
            "date":"1298365200"},

            {"id":"146772677","album_id":"100001227","owner_id":-6492,
            "photo_130":"http://cs9231.vkontakte.ru/u06492/100001227/m_fd092958.jpg",
            "text":"test","user_id":6492,"width":10,"height":10,
            "date":"1260887080"}]}
            '''
        instance = Photo()
        owner = UserFactory(remote_id=6492)
        album = AlbumFactory(remote_id=100001227, owner=owner)
        instance.parse(json.loads(response)['response'][0])
        instance.save()

        self.assertEqual(instance.remote_id, 146771291)
        self.assertEqual(instance.album, album)
        self.assertEqual(instance.owner, owner)
        self.assertEqual(instance.src, instance.photo_130)
        self.assertEqual(
            instance.src,
            'http://cs9231.vkontakte.ru/u06492/100001227/m_7875d2fb.jpg')
        self.assertEqual(instance.text, 'test')
        self.assertEqual(instance.width, 10)
        self.assertEqual(instance.height, 10)
        self.assertIsNotNone(instance.created)

        instance = Photo()
        group = GroupFactory(remote_id=6492)
        #album = AlbumFactory(remote_id=100001227, owner=owner)
        instance.parse(json.loads(response)['response'][1])
        instance.save()

        self.assertEqual(instance.remote_id, 146772677)
        self.assertEqual(instance.album, album)
        self.assertEqual(instance.owner, group)
Exemplo n.º 24
0
        def test_parse_comment(self):

            response = u'''{"date": 1387304612,
                "text": "Даёшь \\"Байкал\\"!!!!",
                "likes": {"count": 0, "can_like": 1, "user_likes": 0},
                "id": 811,
                "from_id": 27224390}
            '''

            owner = GroupFactory(remote_id=GROUP_ID)
            album = AlbumFactory(remote_id=ALBUM_ID, owner=owner)
            video = VideoFactory(remote_id=VIDEO_ID, album=album, owner=owner)

            comment = Comment(object=video)
            comment.parse(json.loads(response))
            comment.save()

            self.assertEqual(comment.remote_id, '-%s_811' % GROUP_ID)
            self.assertEqual(comment.object, video)
            self.assertEqual(comment.author.remote_id, 27224390)
            self.assertEqual(comment.text, u'Даёшь "Байкал"!!!!')
            self.assertIsNotNone(comment.date)
Exemplo n.º 25
0
    def test_fetch_group_photos(self):

        group = GroupFactory(remote_id=GROUP_ID)
        album = AlbumFactory(remote_id=ALBUM_ID, owner=group)

        self.assertEqual(Photo.objects.count(), 0)

        photos = album.fetch_photos(extended=True)

        self.assertGreater(len(photos), 0)
        self.assertEqual(Photo.objects.count(), len(photos))
        self.assertEqual(photos[0].owner, group)
        self.assertEqual(photos[0].album, album)
        self.assertGreater(photos[0].likes_count, 0)
        self.assertGreater(photos[0].comments_count, 0)

        # testing `after` parameter
        after = Photo.objects.order_by('-date')[4].date

        photos_count = Photo.objects.count()
        Photo.objects.all().delete()
        self.assertEqual(Photo.objects.count(), 0)

        photos = album.fetch_photos(after=after)
        self.assertEqual(photos.count(), Photo.objects.count())
        self.assertLess(photos.count(), photos_count)

        # testing `before` parameter
        before = Photo.objects.order_by('-date')[2].date

        photos_count = Photo.objects.count()
        Photo.objects.all().delete()
        self.assertEqual(Photo.objects.count(), 0)

        photos = album.fetch_photos(before=before, after=after)
        self.assertEqual(photos.count(), Photo.objects.count())
        self.assertLess(photos.count(), photos_count)
Exemplo n.º 26
0
    def test_fetch_group_albums(self):

        group = GroupFactory(remote_id=GROUP_ID)

        self.assertEqual(Album.objects.count(), 0)

        albums = group.fetch_albums()

        self.assertGreater(len(albums), 0)
        self.assertEqual(Album.objects.count(), len(albums))
        self.assertEqual(albums[0].owner, group)

        # check force ordering
        self.assertItemsEqual(albums, Album.objects.order_by('-updated'))

        # testing `after` parameter
        after = Album.objects.order_by('-updated')[10].updated

        albums_count = Album.objects.count()
        Album.objects.all().delete()
        self.assertEqual(Album.objects.count(), 0)

        albums = group.fetch_albums(after=after)
        self.assertEqual(albums.count(), Album.objects.count())
        self.assertLess(albums.count(), albums_count)

        # testing `before` parameter
        before = Album.objects.order_by('-updated')[5].updated

        albums_count = Album.objects.count()
        Album.objects.all().delete()
        self.assertEqual(Album.objects.count(), 0)

        albums = group.fetch_albums(before=before, after=after)
        self.assertEqual(albums.count(), Album.objects.count())
        self.assertLess(albums.count(), albums_count)
Exemplo n.º 27
0
    def test_comment_crud_methods(self):
        group = GroupFactory(remote_id=GROUP_CRUD_ID)
        album = AlbumFactory(remote_id=ALBUM_CRUD_ID, owner=group)
        photo = PhotoFactory(remote_id=PHOTO_CRUD_ID, owner=group, album=album)

        def assert_local_equal_to_remote(comment):
            comment_remote = Comment.remote.fetch_by_object(
                object=comment.object).get(remote_id=comment.remote_id)
            self.assertEqual(comment_remote.remote_id, comment.remote_id)
            self.assertEqual(comment_remote.text, comment.text)
            self.assertEqual(comment_remote.author, comment.author)

        # try to delete comments from prev tests
        for comment in Comment.remote.fetch_by_object(object=photo):
            comment.delete(commit_remote=True)
        # checks there is no remote and local comments
        comments = Comment.remote.fetch_by_object(object=photo)
        self.assertEqual(
            Comment.objects.count(), 0,
            'Error: There are %s comments from previous test. Delete them manually here %s'
            % (comments.count(), photo.get_url()))

        # create
        comment = Comment(text='Test comment',
                          object=photo,
                          author=group,
                          date=timezone.now())
        comment.save(commit_remote=True)
        self.objects_to_delete += [comment]

        self.assertEqual(Comment.objects.count(), 1)
        self.assertEqual(comment.author, group)
        self.assertNotEqual(len(comment.remote_id), 0)
        assert_local_equal_to_remote(comment)

        # create by manager
        comment = Comment.objects.create(
            text='Test comment created by manager',
            object=photo,
            author=group,
            date=timezone.now(),
            commit_remote=True)
        self.objects_to_delete += [comment]
        self.assertEqual(Comment.objects.count(), 2)

        self.assertEqual(Comment.objects.count(), 2)
        self.assertEqual(comment.author, group)
        self.assertNotEqual(len(comment.remote_id), 0)
        assert_local_equal_to_remote(comment)

        # update
        comment.text = 'Test comment updated'
        comment.save(commit_remote=True)

        self.assertEqual(Comment.objects.count(), 2)
        assert_local_equal_to_remote(comment)

        # delete
        comment.delete(commit_remote=True)

        self.assertEqual(Comment.objects.count(), 2)
        self.assertTrue(comment.archived)
        self.assertEqual(
            Comment.remote.fetch_by_object(object=comment.object).filter(
                remote_id=comment.remote_id).count(), 0)

        # restore
        comment.restore(commit_remote=True)
        self.assertFalse(comment.archived)

        self.assertEqual(Comment.objects.count(), 2)
        assert_local_equal_to_remote(comment)