Пример #1
0
    def test_playlist_len(self):
        """
        Test playlist len() and check if tracks are synced to database.

        """
        title = 'playlist_with_tracks_append'
        thumbnail = 'thumbnail1234'
        description = 'desc'
        list_id = create_sample_playlist(title, thumbnail, description,
                                         PlaylistTest.db_url)

        sample_list = Playlist(list_id, title, thumbnail, description)
        for track in PlaylistTest.test_tracks:
            sample_list.append(track)

        self.assertTrue(len(sample_list) == len(PlaylistTest.test_tracks))
        playlist_tracks = [track for track in sample_list]
        self.assertTrue(len(playlist_tracks) == len(PlaylistTest.test_tracks))
        self.assertTrue(len(playlist_tracks) == len(sample_list))
        # Check results in the database
        db_tracks = get_playlist_tracks_from_db(sample_list.list_id,
                                                PlaylistTest.db_url)
        playlist_tracks = [track for track in sample_list]
        self.assertTrue(
            db_tracks == PlaylistTest.test_tracks == playlist_tracks)
Пример #2
0
    def test_app_playlist_list(self):
        """
        Test fetching available playlists.

        """
        api_url = r'http://127.0.0.1:8080/api/get_playlist'
        title = 'playlist_list_all'
        thumbnail = 'thumb.example'
        description = 'desc'
        list_id = create_sample_playlist(title, thumbnail, description,
                                         TestApp.db_url)
        # Get all playlists and evaluate the result
        r = requests.get(api_url, params={'session_id': TestApp.session_id})
        r.raise_for_status()
        self.assertTrue(
            r.headers.get('content-type', '').startswith('application/json'))
        json_obj = json.loads(r.json())
        all_playlists = json_obj['playlists']
        self.assertTrue(len(all_playlists) > 0)
        for playlist in all_playlists:
            self.assertTrue(playlist['title'])
            self.assertTrue(playlist['thumbnail'])
        # Check for a single playlist
        r = requests.get(api_url,
                         params={
                             'session_id': TestApp.session_id,
                             'list_id': list_id
                         })
        r.raise_for_status()
        self.assertTrue(
            r.headers.get('content-type', '').startswith('application/json'))
        playlist_json = json.loads(r.json())
        self.assertEqual(playlist_json['id'], list_id)
        self.assertEqual(playlist_json['title'], title)
        self.assertEqual(playlist_json['thumbnail'], thumbnail)
Пример #3
0
    def test_app_playlist_tracks_delete(self):
        """
        Test delete track from playlist.

        """
        api_url = r'http://127.0.0.1:8080/api/delete_track'
        list_id = create_sample_playlist('tracks delete', 'thumbnal.test',
                                         'desc', TestApp.db_url)
        test_track = {
            'id': '1abcd',
            'title': 'some title1',
            'thumbnail': 'itthumb1a',
            'artist': 'artist a'
        }
        add_playlist_tracks_to_db(list_id, [test_track], TestApp.db_url)
        # Delete invalid track
        r = requests.post(api_url,
                          params={
                              'session_id': TestApp.session_id,
                              'list_id': list_id,
                              'track_id': 'aaaaa'
                          })
        self.assertEqual(r.status_code, 404)
        # Delete the real track
        r = requests.post(api_url,
                          params={
                              'session_id': TestApp.session_id,
                              'list_id': list_id,
                              'track_id': test_track['id']
                          })
        r.raise_for_status()
        playlist_tracks = get_playlist_tracks_from_db(list_id, TestApp.db_url)
        self.assertEqual(playlist_tracks, None)
Пример #4
0
    def test_app_playlist_tracks_add(self):
        """
        Test add tracks to playlist.

        """
        api_url = r'http://127.0.0.1:8080/api/add_tracks'
        test_tracks = [{
            'id': '1abcd',
            'title': 'some title1',
            'thumbnail': 'itthumb1a',
            'artist': 'artist a'
        }, {
            'id': '2abce',
            'title': 'some title2',
            'thumbnail': 'itthumb2b',
            'artist': 'artist b'
        }]
        # Create sample playlist
        list_id = create_sample_playlist('tracks add', 'thumbnal.test', 'desc',
                                         TestApp.db_url)
        r = requests.post(api_url,
                          params={
                              'session_id': TestApp.session_id,
                              'list_id': list_id
                          },
                          data=json.dumps({'tracks': test_tracks}))
        r.raise_for_status()
        playlist_tracks = get_playlist_tracks_from_db(list_id, TestApp.db_url)
        self.assertEqual(playlist_tracks, test_tracks)
Пример #5
0
    def test_app_playlist_tracks_get(self):
        """
        Test fecthing playlist tracks.

        """
        api_url = r'http://127.0.0.1:8080/api/get_tracks'
        # Create sample playlist
        list_id = create_sample_playlist('tracks get', 'thumbnal.test', 'desc',
                                         TestApp.db_url)
        test_tracks = [{
            'id': '1abcd',
            'title': 'some title1',
            'thumbnail': 'itthumb1a',
            'artist': 'artist a'
        }, {
            'id': '2abce',
            'title': 'some title2',
            'thumbnail': 'itthumb2b',
            'artist': 'artist b'
        }]
        # Add the tracks to playlist
        add_playlist_tracks_to_db(list_id, test_tracks, TestApp.db_url)
        # Test fetching the tracks via the API
        r = requests.get(api_url,
                         params={
                             'session_id': TestApp.session_id,
                             'list_id': list_id
                         })
        r.raise_for_status()
        self.assertTrue(
            r.headers.get('content-type', '').startswith('application/json'))
        json_obj = json.loads(r.json())
        self.assertEqual(json_obj['tracks'], test_tracks)
Пример #6
0
    def test_app_playlist_update(self):
        """
        Test the process of updating playlist information.

        """
        api_url = r'http://127.0.0.1:8080/api/update_playlist'
        title = 'Testing app update'
        thumbnail = 'some thumbnail update'
        description = 'desc'
        # Create the playlist first
        list_id = create_sample_playlist(title, thumbnail, description,
                                         TestApp.db_url)
        title = 'Testing app update new title'
        r = requests.put(api_url,
                         params={
                             'session_id': TestApp.session_id,
                             'list_id': list_id
                         },
                         data=json.dumps({
                             'title': title,
                             'thumbnail': thumbnail
                         }))
        r.raise_for_status()
        json_obj = json.loads(r.json())
        self.assertEqual(json_obj['id'], list_id)
        self.assertEqual(json_obj['title'], title)
Пример #7
0
    def test_playlist_all(self):
        """
        Test getting all playlist in the database.

        """
        title1 = 'playlist_all_1'
        title2 = 'playlist_all_2'
        thumbnail = 'thumbnail1234'
        description = 'some description'
        list_id_1 = create_sample_playlist(title1, thumbnail, description,
                                           PlaylistTest.db_url)
        list_id_2 = create_sample_playlist(title2, thumbnail, description,
                                           PlaylistTest.db_url)
        playlists = Library.all()
        self.assertTrue(len(playlists) == 2)
        self.assertTrue(playlists[0].title == title1)
        self.assertTrue(playlists[1].title == title2)
Пример #8
0
    def test_playlist_delete(self):
        """
        Test deleting a playlist.

        """
        # Create a playlist
        list_id = create_sample_playlist('p', 't', 'd', PlaylistTest.db_url)
        # Test
        Library.delete(list_id)
        p = Library.playlist(list_id)
        self.assertTrue(p == None)
        self.assertFalse(verify_playlist_in_db('p', PlaylistTest.db_url))
Пример #9
0
    def test_playlist_iterate(self):
        """
        Test iterating a playlist like a python list.

        """
        title = 'playlist_with_items_iterate'
        thumbnail = 'thumbnail1234'
        description = 'desc iterate'
        list_id = create_sample_playlist(title, thumbnail, description,
                                         PlaylistTest.db_url)
        sample_list = Playlist(list_id, title, thumbnail, description)
        # Test item iteration
        sample_list.extend(PlaylistTest.test_tracks)
        for idx, track in enumerate(sample_list):
            self.assertTrue(track == PlaylistTest.test_tracks[idx])
Пример #10
0
    def test_playlist_remove(self):
        """
        Test removing tracks from playlist.

        """
        title = 'playlist_with_items_remove'
        thumbnail = 'thumbnail1234'
        description = 'desc remove'
        list_id = create_sample_playlist(title, thumbnail, description,
                                         PlaylistTest.db_url)
        sample_list = Playlist(list_id, title, thumbnail, description)
        sample_list.extend(PlaylistTest.test_tracks)
        sample_list.remove(PlaylistTest.test_tracks[0]['id'])
        playlist_tracks = [track for track in sample_list]
        self.assertTrue(
            len(playlist_tracks) == (len(PlaylistTest.test_tracks) - 1))
        self.assertTrue(playlist_tracks[0] == PlaylistTest.test_tracks[1])
Пример #11
0
    def test_playlist_data(self):
        """
        Test playlist data content for consistency.

        """
        title = 'playlist_test_data'
        thumbnail = 'thumbnail1234'
        description = 'desc data'
        list_id = create_sample_playlist('temp_title', 'temp_thumbnail',
                                         'temp_descr', PlaylistTest.db_url)
        sample_list = Playlist(list_id, 'temp_title', 'temp_thumbnail',
                               'temp_descr')
        sample_list.title = title
        sample_list.thumbnail = thumbnail
        self.assertTrue(sample_list.title == title)
        self.assertTrue(sample_list.thumbnail == thumbnail)
        self.assertTrue(
            verify_playlist_in_db(sample_list.title, PlaylistTest.db_url))
Пример #12
0
    def test_app_playlist_delete(self):
        """
        Test the process of deleting a playlist.

        """
        api_url = r'http://127.0.0.1:8080/api/delete_playlist'
        title = 'Testing app delete'
        thumbnail = 'some thumbnail delete'
        description = 'desc'
        # Create the playlist first
        list_id = create_sample_playlist(title, thumbnail, description,
                                         TestApp.db_url)
        r = requests.delete(api_url,
                            params={
                                'session_id': TestApp.session_id,
                                'list_id': list_id
                            })
        r.raise_for_status()
        self.assertFalse(verify_playlist_in_db(title, TestApp.db_url))
Пример #13
0
    def test_playlist_get(self):
        """
        Test getting a playlist.

        """
        playlist = Library.playlist(2343)
        self.assertTrue(playlist == None)
        # Create a playlist
        title = 'playlist title get'
        thumb = 'http://localhost/get.png'
        description = 'get description'
        list_id = create_sample_playlist(title, thumb, description,
                                         PlaylistTest.db_url)
        # Test result
        playlist = Library.playlist(list_id)
        self.assertTrue(playlist.list_id == list_id)
        self.assertTrue(playlist.title == title)
        self.assertTrue(playlist.thumbnail == thumb)
        self.assertTrue(playlist.description == description)
        self.assertTrue(verify_playlist_in_db(title, PlaylistTest.db_url))
Пример #14
0
    def test_playlist_speed_test(self):
        """
        Do a speed (performance) test.

        """
        title = 'playlist_speed_test'
        thumbnail = 'thumbnail1234'
        list_id = create_sample_playlist(title, thumbnail, 'desc',
                                         PlaylistTest.db_url)
        p1 = Playlist(list_id, title, thumbnail)
        track = {
            'id': 'QjXcf3wYfhc',
            'title': 'Jess Glynne No One (Jonas Blue Remix',
            'thumbnail':
            'https://lh3.googleusercontent.com/ET1uVviDNeKkr7LMkRcHLElE75EsW4dT6quWHlGKQgz36PkFmCQirCPQKu8rewziGgD6cZJvOtuc0yct=w544-h544-l90-rj',
            'artist': 'Jess Glynne'
        }
        for _ in range(0, 1000):
            p1.append(track)
        p2 = Playlist(list_id, title, thumbnail, 'desc')
        self.assertTrue(len(p2) == 1000)
Пример #15
0
    def test_playlist_extend_and_clear(self):
        """
        Test extending a playlist with new tracks and then clear all the tracks.

        """
        title = 'playlist_with_items_extend'
        thumbnail = 'thumbnail1234'
        description = 'desc extend'
        list_id = create_sample_playlist(title, thumbnail, description,
                                         PlaylistTest.db_url)
        sample_list = Playlist(list_id, title, description, thumbnail)
        sample_list.extend(PlaylistTest.test_tracks)
        # Check results in the database
        db_tracks = get_playlist_tracks_from_db(sample_list.list_id,
                                                PlaylistTest.db_url)
        playlist_tracks = [track for track in sample_list]
        self.assertTrue(
            db_tracks == PlaylistTest.test_tracks == playlist_tracks)
        # Test clear method
        sample_list.clear()
        db_tracks = get_playlist_tracks_from_db(sample_list.list_id,
                                                PlaylistTest.db_url)
        self.assertTrue(db_tracks == None)
        self.assertTrue(len(sample_list) == 0)