def create_albums(): nu = User(firstname='f', lastname='l', email='*****@*****.**') nu.set_password('test') db.session.add(nu) db.session.commit() album1 = Album.create_album(user_pk=nu.pk, name='album1', cover_image='google.com') album2 = Album.create_album(user_pk=nu.pk, name='album2', cover_image='google.com') album3 = Album.create_album(user_pk=nu.pk, name='album3', cover_image='google.com') newsong = Song(name='song1', user=nu.pk, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song2', user=nu.pk, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song3', user=nu.pk, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='notin1', user=nu.pk, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='notin2', user=nu.pk, mp3_file='google.com') db.session.add(newsong) db.session.commit() album1.add_song(1) album1.add_song(2) album1.add_song(3) album2.add_song(4) album3.add_song(5)
def test_add_entry_user_song_relationship_update(app): user = User(email='*****@*****.**', firstname='f', lastname='l') user.set_password('password') song = Song(name='song1', user=1, mp3_file='google.com') db.session.add(user) db.session.add(song) db.session.commit() UserSongRelationship.add_entry(user=1, song=1, is_like=False) assert UserSongRelationship.query.first().user == 1 assert UserSongRelationship.query.first().song == 1 assert UserSongRelationship.query.first().is_like == False
def get_sample_data(): user = User(email='*****@*****.**', firstname='fn', lastname='ln') user.set_password('password') db.session.add(user) db.session.commit() genre = Genre(name='genre1') db.session.add(genre) db.session.commit() song = Song(name='song1', user=user.pk, genre=genre.pk, mp3_file="http://google.com") db.session.add(song) db.session.commit() return user, song, genre
def test_add_entry_user_song_relationship_duplicate_addition(app): user = User(email='*****@*****.**', firstname='f', lastname='l') user.set_password('password') song = Song(name='song1', user=1, mp3_file='google.com') db.session.add(user) db.session.add(song) db.session.commit() UserSongRelationship.add_entry(user=1, song=1, is_like=True) with pytest.raises(Exception) as execinfo: UserSongRelationship.add_entry(user=1, song=1, is_like=True) print(execinfo) assert 'Cannot add multiple rows with the same primary key' in str(execinfo.value)
def test_like_song_valid_post_form(app): user = User(email='*****@*****.**', firstname='f', lastname='l') user.set_password('password') song = Song(name='song1', user=1, mp3_file='google.com') db.session.add(user) db.session.add(song) db.session.commit() with app.test_client() as client: # login in uer resp = client.post('/users/login', data=dict(email='*****@*****.**', password='******', remember=False)) assert resp.status_code == 200 resp = client.post('/songs/like', data=dict(song=1, is_like=True)) assert resp.status_code == 200 assert json.loads(resp.data)['success'] == True assert json.loads(resp.data)['message'] == 'added like/dislike to database'
def create_songs(): ns = Song(name='a song that is new', user=1, mp3_file='google.com') db.session.add(ns) ns = Song(name='a song that is new', user=1, mp3_file='google.com') db.session.add(ns) db.session.commit()
def get(self): q = Song.get_100() return q
def create_albumns2(): nu1 = User(firstname='f', lastname='l', email='*****@*****.**') nu1.set_password('test') db.session.add(nu1) db.session.commit() nu2 = User(firstname='f2', lastname='l2', email='*****@*****.**') nu2.set_password('test') db.session.add(nu2) db.session.commit() DisplayStatus.add_default_display_status() # user 1 u1albumu1 = Album.create_album(user_pk=nu1.pk, name='album1', cover_image='google.com') u1albumu2 = Album.create_album(user_pk=nu1.pk, name='album2', cover_image='google.com') u1albumu3 = Album.create_album(user_pk=nu1.pk, name='album3', cover_image='google.com') pp = Playlist.create_playlist(nu1.pk, name='playlist1', cover_image='google.com', display_status=3) unlisted = Playlist.create_playlist(nu1.pk, name='playlist2', cover_image='google.com', display_status=2) user_private = Playlist.create_playlist(nu1.pk, name='playlist_p', cover_image='google.com', display_status=1) # user 2 u2albumu1 = Album.create_album(user_pk=nu1.pk, name='album21', cover_image='google.com') u2albumu2 = Album.create_album(user_pk=nu1.pk, name='album22', cover_image='google.com') u2albumu3 = Album.create_album(user_pk=nu1.pk, name='album23', cover_image='google.com') newsong = Song(name='song1', user=nu2.pk, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song2', user=nu2.pk, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song3', user=nu1.pk, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song4', user=nu1.pk, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song5', user=nu1.pk, mp3_file='google.com') db.session.add(newsong) db.session.commit() u1albumu1.add_song(1) u1albumu1.add_song(2) u1albumu1.add_song(3) u2albumu1.add_song(4) u2albumu2.add_song(5)