def create_album(): a1 = Playlist.create_playlist(1, name='album1', cover_image='google.com') a2 = Playlist.create_playlist(1, name='album2', cover_image='google.com') a3 = Playlist.create_playlist(1, name='album3', cover_image='google.com') newsong = Song(name='song1', user=1, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song2', user=1, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song3', user=1, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song4', user=1, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song5', user=1, mp3_file='google.com') db.session.add(newsong) db.session.commit() a1.add_song(1) a2.add_song(2) a3.add_song(3) a1.like(user_pk=1) a2.like(user_pk=2) a3.like(user_pk=1)
def test_playlist_creation(app): su = User(firstname='fn', lastname='ln', email='*****@*****.**') su.set_password('123') db.session.add(su) db.session.commit() DisplayStatus.add_default_display_status() Playlist.create_playlist(user_pk=su.pk, name="playlist 1", cover_image='hi', display_status=1) query_pl = Playlist.query.get(1) assert query_pl.name == 'playlist 1' assert SongCollection.query.get( query_pl.song_collection).cover_image == 'hi'
def create__playlist(): nu = User(firstname='f', lastname='l', email='*****@*****.**') nu.set_password('test') db.session.add(nu) db.session.commit() DisplayStatus.add_default_display_status() pp = Playlist.create_playlist(nu.pk, name='playlist1', cover_image='google.com', display_status=3) unlisted = Playlist.create_playlist(nu.pk, name='playlist2', cover_image='google.com', display_status=2) private_p = Playlist.create_playlist(nu.pk, name='playlist3', cover_image='google.com', display_status=1) 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='notinpp1', user=nu.pk, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='notinpp2', user=nu.pk, mp3_file='google.com') db.session.add(newsong) db.session.commit() pp.add_song(1) pp.add_song(2) pp.add_song(3)
def create_playlist(): DisplayStatus.add_default_display_status() pp = Playlist.create_playlist(1, name='playlist1', cover_image='google.com', display_status=3) unlisted = Playlist.create_playlist(1, name='playlist2', cover_image='google.com', display_status=2) private_p = Playlist.create_playlist(1, name='playlist3', cover_image='google.com', display_status=1) newsong = Song(name='song1', user=1, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song2', user=1, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='song3', user=1, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='notinpp1', user=1, mp3_file='google.com') db.session.add(newsong) newsong = Song(name='notinpp2', user=1, mp3_file='google.com') db.session.add(newsong) db.session.commit() pp.add_song(1) pp.add_song(2) pp.add_song(3) pp.like(user_pk=1) unlisted.like(user_pk=2) unlisted.like(user_pk=1)
def post(self): if not current_user.is_authenticated: return {'sucess': False, 'is_authenticated': False, 'error': 'login then we can talk'} args = self.reqparse.parse_args() print('args', args) ''' expected for data: { 'name': 'a name' 'is_playlist': 'Album or Playlist' 'cover_image': 'url link to image' 'songs': '[1,2,3,4,5,6]' (list of song ids) } ''' name = args['name'] cover_image = args['cover_image'] songs = [] #args['songs'] is_playlist = args['is_playlist'] if is_playlist.lower() == 'playlist': print('creating playlist') new_playlist = Playlist.create(user_pk=current_user.pk, name=name, cover_image=cover_image) print('songs', songs) for song in songs: new_playlist.add_song(song) return {'success': True, 'message': 'playlist created'}, 201 elif args['is_playlist'].lower() == 'album': print('creating albumn') new_album = Album.create(user_pk=current_user.pk, name=name, cover_image=cover_image) for song in songs: new_album.add_song(song) return {'success': True, 'message': 'albumn created'}, 201 return {'success': False, 'message': 'invalid form'}
def get(self): if not current_user.is_authenticated: return {'error': 'Not logged in'} q = Playlist.get_liked_playlists(current_user.pk) 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)