def test_album_detail_view(rf, db): album = AlbumFactory() album.save() request = rf.get('/album/' + str(album.id) + '/') response = album_detail(request, album.id) assert response.status_code == 200
def test_get_url(self): 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(album.get_url().count("-"), 1) self.assertEqual(video.get_url().count("-"), 1) user = UserFactory(remote_id=13312307) album = AlbumFactory(remote_id=55976289, owner=user) video = VideoFactory(remote_id=165144348, album=album, owner=user) self.assertEqual(album.get_url().count("-"), 0) self.assertEqual(video.get_url().count("-"), 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)
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)
def test_fetch_photo_comments(self): group = GroupFactory.create(remote_id=GROUP_ID) album = AlbumFactory.create(remote_id=ALBUM_ID, group=group) photo = PhotoFactory.create(remote_id=PHOTO_ID, album=album) self.assertEqual(photo.comments, 0) photo.fetch_comments() self.assertTrue(photo.comments > 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)
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))
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.create(remote_id=6492) album = AlbumFactory.create(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.created, datetime(2011,2,22,9,0,0)) 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) instance = Photo() group = GroupFactory.create(remote_id=6492) album = AlbumFactory.create(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)
def test_fetch_group_photos(self): group = GroupFactory.create(remote_id=GROUP_ID) album = AlbumFactory.create(remote_id=ALBUM_ID, group=group) self.assertEqual(Photo.objects.count(), 0) photos = album.fetch_photos() self.assertTrue(len(photos) > 0) self.assertEqual(Photo.objects.count(), len(photos)) self.assertEqual(photos[0].group, group) self.assertEqual(photos[0].album, album)
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) self.assertEqual(Video.objects.count(), 0) videos = album.fetch_videos(count=5) self.assertEqual(len(videos), 5) self.assertEqual(Video.objects.count(), 5) # testing `offset` parameter videos2 = album.fetch_videos(count=2, offset=4) self.assertEqual(len(videos2), 2) self.assertEqual(Video.objects.count(), 6) # print videos[4].remote_id # print videos2[0].remote_id # print videos2[1].remote_id self.assertEqual(videos[4].remote_id, videos2[0].remote_id)
def test_max_three_items_per_page(self): user = UserFactory() album = AlbumFactory.create(owner=user) page = PageFactory.create(album=album) PageItemFactory.create(page=page) PageItemFactory.create(page=page) PageItemFactory.create(page=page) PageItemFactory.create(page=page) self.assertEquals(3, page.page_items.all().count(), 'Test that a page has at maximum three items')
def test_position_unique(self): user = UserFactory() album = AlbumFactory.create(owner=user) page = PageFactory.create(album=album) item1 = PageItemFactory.create( page=page, value='item1') #initialized with position 0 item2 = PageItemFactory.create( page=page, value='item2') #initialized with position 0 item3 = PageItemFactory.create( page=page, position=0, value='item3') #initialized with position 0 item4 = PageItemFactory.create( page=page, value='item4') #initialized with position 0 self.assertNotEqual(item1.position, item2.position, "Test that no two items have the same position")
def test_album_detail_url(client, db): album = AlbumFactory() album.save() id = album.id assert client.get('/albuns/' + str(id) + '/').status_code == 200
def test_create_album(db): album = AlbumFactory() album.save()
def test_album_genre_too_big(db): album = AlbumFactory() album.genre = "genero muito grande, não deveria ter mais de 50 caracteres." with pytest.raises(ValidationError): album.full_clean()
def test_album_year_too_big(db): album = AlbumFactory() album.year = 2020 with pytest.raises(ValidationError): album.full_clean()
def test_album_name_too_big(db): album = AlbumFactory() album.name = "nome do album muito grande, não deve ter mais de 100 caracteres e no momento se encontra maior que tal." with pytest.raises(ValidationError): album.full_clean()
def test_to_string(db): album = AlbumFactory() assert str(album) == album.name + " [" + album.arthist + " - " + str( album.year) + "]"
def test_album_arthist_too_big(db): album = AlbumFactory() album.arthist = "nome do artista é muito grande, não deveria ter mais de 50 caracteres." with pytest.raises(ValidationError): album.full_clean()