Esempio n. 1
0
    def test_missing_request(self):
        response_body = bytes(
            '{'
            '"tracks" : {'
            '"href" : "https://api.spotify.com/v1/search?query=duifhjslkef'
            '+album%3Alkajsdflakjsd+artist%3A&offset=0&limit=20&type=track",'
            '"items" : [ ],'
            '"limit" : 20,'
            '"next" : null,'
            '"offset" : 0,'
            '"previous" : null,'
            '"total" : 0'
            '}'
            '}'
        )
        responses.add(responses.GET, 'https://api.spotify.com/v1/search',
                      body=response_body, status=200,
                      content_type='application/json')
        item = Item(
            mb_trackid=u'01234',
            album=u'lkajsdflakjsd',
            albumartist=u'ujydfsuihse',
            title=u'duifhjslkef',
            length=10
        )
        item.add(self.lib)
        self.assertEqual([], self.spotify.query_spotify(self.lib, u""))

        params = _params(responses.calls[0].request.url)
        self.assertEqual(
            params['q'],
            [u'duifhjslkef album:lkajsdflakjsd artist:ujydfsuihse'],
        )
        self.assertEqual(params['type'], [u'track'])
Esempio n. 2
0
    def test_missing_request(self):
        json_file = os.path.join(_common.RSRC, b'spotify',
                                 b'missing_request.json')
        with open(json_file, 'rb') as f:
            response_body = f.read()

        responses.add(responses.GET,
                      'https://api.spotify.com/v1/search',
                      body=response_body,
                      status=200,
                      content_type='application/json')
        item = Item(mb_trackid=u'01234',
                    album=u'lkajsdflakjsd',
                    albumartist=u'ujydfsuihse',
                    title=u'duifhjslkef',
                    length=10)
        item.add(self.lib)
        self.assertEqual([], self.spotify.query_spotify(self.lib, u""))

        params = _params(responses.calls[0].request.url)
        self.assertEqual(
            params['q'],
            [u'duifhjslkef album:lkajsdflakjsd artist:ujydfsuihse'],
        )
        self.assertEqual(params['type'], [u'track'])
Esempio n. 3
0
 def test_missing_request(self):
     response_body = str(
         '{'
         '"tracks" : {'
         '"href" : "https://api.spotify.com/v1/search?query=duifhjslkef'
         '+album%3Alkajsdflakjsd+artist%3A&offset=0&limit=20&type=track",'
         '"items" : [ ],'
         '"limit" : 20,'
         '"next" : null,'
         '"offset" : 0,'
         '"previous" : null,'
         '"total" : 0'
         '}'
         '}'
     )
     responses.add(responses.GET,
                   'https://api.spotify.com/v1/search?q=duifhjslkef+album'
                   '%3Alkajsdflakjsd+artist%3A&type=track',
                   body=response_body, status=200,
                   content_type='application/json')
     item = Item(
         mb_trackid='01234',
         album='lkajsdflakjsd',
         albumartist='ujydfsuihse',
         title='duifhjslkef',
         length=10
     )
     item.add(self.lib)
     self.assertEquals([], self.spotify.query_spotify(self.lib, ""))
Esempio n. 4
0
    def test_track_request(self):

        json_file = os.path.join(_common.RSRC, b'spotify',
                                 b'track_request.json')
        with open(json_file, 'rb') as f:
            response_body = f.read()

        responses.add(responses.GET,
                      'https://api.spotify.com/v1/search',
                      body=response_body,
                      status=200,
                      content_type='application/json')
        item = Item(mb_trackid=u'01234',
                    album=u'Despicable Me 2',
                    albumartist=u'Pharrell Williams',
                    title=u'Happy',
                    length=10)
        item.add(self.lib)
        results = self.spotify.query_spotify(self.lib, u"Happy")
        self.assertEqual(1, len(results))
        self.assertEqual(u"6NPVjNh8Jhru9xOmyQigds", results[0]['id'])
        self.spotify.output_results(results)

        params = _params(responses.calls[0].request.url)
        self.assertEqual(
            params['q'],
            [u'Happy album:Despicable Me 2 artist:Pharrell Williams'],
        )
        self.assertEqual(params['type'], [u'track'])
Esempio n. 5
0
    def test_missing_request(self):
        response_body = bytes(
            '{'
            '"tracks" : {'
            '"href" : "https://api.spotify.com/v1/search?query=duifhjslkef'
            '+album%3Alkajsdflakjsd+artist%3A&offset=0&limit=20&type=track",'
            '"items" : [ ],'
            '"limit" : 20,'
            '"next" : null,'
            '"offset" : 0,'
            '"previous" : null,'
            '"total" : 0'
            '}'
            '}')
        responses.add(responses.GET,
                      'https://api.spotify.com/v1/search',
                      body=response_body,
                      status=200,
                      content_type='application/json')
        item = Item(mb_trackid=u'01234',
                    album=u'lkajsdflakjsd',
                    albumartist=u'ujydfsuihse',
                    title=u'duifhjslkef',
                    length=10)
        item.add(self.lib)
        self.assertEqual([], self.spotify.query_spotify(self.lib, u""))

        params = _params(responses.calls[0].request.url)
        self.assertEqual(
            params['q'],
            [u'duifhjslkef album:lkajsdflakjsd artist:ujydfsuihse'],
        )
        self.assertEqual(params['type'], [u'track'])
Esempio n. 6
0
    def test_missing_request(self):
        json_file = os.path.join(_common.RSRC, b'spotify',
                                 b'missing_request.json')
        with open(json_file, 'rb') as f:
            response_body = f.read()

        responses.add(responses.GET, 'https://api.spotify.com/v1/search',
                      body=response_body, status=200,
                      content_type='application/json')
        item = Item(
            mb_trackid=u'01234',
            album=u'lkajsdflakjsd',
            albumartist=u'ujydfsuihse',
            title=u'duifhjslkef',
            length=10
        )
        item.add(self.lib)
        self.assertEqual([], self.spotify.query_spotify(self.lib, u""))

        params = _params(responses.calls[0].request.url)
        self.assertEqual(
            params['q'],
            [u'duifhjslkef album:lkajsdflakjsd artist:ujydfsuihse'],
        )
        self.assertEqual(params['type'], [u'track'])
Esempio n. 7
0
    def test_track_request(self):

        json_file = os.path.join(_common.RSRC, b'spotify',
                                 b'track_request.json')
        with open(json_file, 'rb') as f:
            response_body = f.read()

        responses.add(responses.GET, 'https://api.spotify.com/v1/search',
                      body=response_body, status=200,
                      content_type='application/json')
        item = Item(
            mb_trackid=u'01234',
            album=u'Despicable Me 2',
            albumartist=u'Pharrell Williams',
            title=u'Happy',
            length=10
        )
        item.add(self.lib)
        results = self.spotify.query_spotify(self.lib, u"Happy")
        self.assertEqual(1, len(results))
        self.assertEqual(u"6NPVjNh8Jhru9xOmyQigds", results[0]['id'])
        self.spotify.output_results(results)

        params = _params(responses.calls[0].request.url)
        self.assertEqual(
            params['q'],
            [u'Happy album:Despicable Me 2 artist:Pharrell Williams'],
        )
        self.assertEqual(params['type'], [u'track'])
Esempio n. 8
0
    def test_store_data(self, echonest_track, echonest_profile, item_write):
        profile = Mock(
            artist_name='artist',
            title='title',
            id='echonestid',
            audio_summary={
                'duration': 10,
                'energy': 0.5,
                'liveness': 0.5,
                'loudness': 0.5,
                'speechiness': 0.5,
                'danceability': 0.5,
                'tempo': 120,
                'key': 2,
                'mode': 0
            },
        )
        echonest_profile.return_value = [profile]
        echonest_track.return_value = Mock(song_id='echonestid')

        item = Item(
            mb_trackid='01234',
            artist='artist',
            title='title',
            length=10,
        )
        item.add(self.lib)
        self.assertNotIn('danceability', item)
        self.assertNotIn('initialkey', item)

        self.run_command('echonest')
        item.load()
        self.assertEqual(item['danceability'], '0.5')
        self.assertEqual(item['initial_key'], 'C#m')
Esempio n. 9
0
    def test_track_request(self):
        json_file = os.path.join(_common.RSRC, b'spotify',
                                 b'track_request.json')
        with open(json_file, 'rb') as f:
            response_body = f.read()

        responses.add(
            responses.GET,
            spotify.SpotifyPlugin.search_url,
            body=response_body,
            status=200,
            content_type='application/json',
        )
        item = Item(
            mb_trackid='01234',
            album='Despicable Me 2',
            albumartist='Pharrell Williams',
            title='Happy',
            length=10,
        )
        item.add(self.lib)
        results = self.spotify._match_library_tracks(self.lib, "Happy")
        self.assertEqual(1, len(results))
        self.assertEqual("6NPVjNh8Jhru9xOmyQigds", results[0]['id'])
        self.spotify._output_match_results(results)

        params = _params(responses.calls[0].request.url)
        query = params['q'][0]
        self.assertIn('Happy', query)
        self.assertIn('artist:Pharrell Williams', query)
        self.assertIn('album:Despicable Me 2', query)
        self.assertEqual(params['type'], ['track'])
Esempio n. 10
0
    def test_store_data(self, echonest_track, echonest_profile, item_write):
        profile = Mock(
            artist_name='artist',
            title='title',
            id='echonestid',
            audio_summary={
                'duration': 10,
                'energy': 0.5,
                'liveness': 0.5,
                'loudness': 0.5,
                'speechiness': 0.5,
                'danceability': 0.5,
                'tempo': 120,
                'key': 2,
                'mode': 0
            },
        )
        echonest_profile.return_value = [profile]
        echonest_track.return_value = Mock(song_id='echonestid')

        item = Item(
            mb_trackid='01234',
            artist='artist',
            title='title',
            length=10,
        )
        item.add(self.lib)
        self.assertNotIn('danceability', item)
        self.assertNotIn('initialkey', item)

        self.run_command('echonest')
        item.load()
        self.assertEqual(item['danceability'], '0.5')
        self.assertEqual(item['initial_key'], 'C#m')
Esempio n. 11
0
 def test_missing_request(self):
     response_body = str(
         '{'
         '"tracks" : {'
         '"href" : "https://api.spotify.com/v1/search?query=duifhjslkef'
         '+album%3Alkajsdflakjsd+artist%3A&offset=0&limit=20&type=track",'
         '"items" : [ ],'
         '"limit" : 20,'
         '"next" : null,'
         '"offset" : 0,'
         '"previous" : null,'
         '"total" : 0'
         '}'
         '}')
     responses.add(responses.GET,
                   'https://api.spotify.com/v1/search?q=duifhjslkef+album'
                   '%3Alkajsdflakjsd+artist%3A&type=track',
                   body=response_body,
                   status=200,
                   content_type='application/json')
     item = Item(mb_trackid='01234',
                 album='lkajsdflakjsd',
                 albumartist='ujydfsuihse',
                 title='duifhjslkef',
                 length=10)
     item.add(self.lib)
     self.assertEquals([], self.spotify.query_spotify(self.lib, ""))
Esempio n. 12
0
    def test_missing_request(self):
        json_file = os.path.join(_common.RSRC, b'spotify',
                                 b'missing_request.json')
        with open(json_file, 'rb') as f:
            response_body = f.read()

        responses.add(
            responses.GET,
            spotify.SpotifyPlugin.search_url,
            body=response_body,
            status=200,
            content_type='application/json',
        )
        item = Item(
            mb_trackid='01234',
            album='lkajsdflakjsd',
            albumartist='ujydfsuihse',
            title='duifhjslkef',
            length=10,
        )
        item.add(self.lib)
        self.assertEqual([], self.spotify._match_library_tracks(self.lib, ""))

        params = _params(responses.calls[0].request.url)
        query = params['q'][0]
        self.assertIn('duifhjslkef', query)
        self.assertIn('artist:ujydfsuihse', query)
        self.assertIn('album:lkajsdflakjsd', query)
        self.assertEqual(params['type'], ['track'])
Esempio n. 13
0
    def test_normal_case(self):
        item = Item(path='/file', mb_workid='1', parentwork_workid_current='1')
        item.add(self.lib)

        self.run_command('parentwork')

        item.load()
        self.assertEqual(item['mb_parentworkid'], '3')
Esempio n. 14
0
    def test_do_not_overwrite(self):
        item = Item(path='/file', initial_key='F')
        item.add(self.lib)

        self.command_output.return_value = 'dbm'
        self.run_command('keyfinder')

        item.load()
        self.assertEqual(item['initial_key'], 'F')
Esempio n. 15
0
    def test_update_rating(self):
        item = Item(title=u'title', path='', id=1)
        item.add(self.lib)

        log = Mock()
        mpdstats = MPDStats(self.lib, log)

        self.assertFalse(mpdstats.update_rating(item, True))
        self.assertFalse(mpdstats.update_rating(None, True))
Esempio n. 16
0
    def test_do_not_overwrite(self):
        item = Item(path='/file', initial_key='F')
        item.add(self.lib)

        self.command_output.return_value = 'dbm'
        self.run_command('keyfinder')

        item.load()
        self.assertEqual(item['initial_key'], 'F')
Esempio n. 17
0
    def test_do_not_overwrite(self, command_output):
        item = Item(path='/file', initial_key='F')
        item.add(self.lib)

        command_output.return_value = util.CommandOutput(b"dbm", b"")
        self.run_command('keyfinder')

        item.load()
        self.assertEqual(item['initial_key'], 'F')
Esempio n. 18
0
    def test_no_key(self, command_output):
        item = Item(path='/file')
        item.add(self.lib)

        command_output.return_value = util.CommandOutput(b"", b"")
        self.run_command('keyfinder')

        item.load()
        self.assertEqual(item['initial_key'], None)
Esempio n. 19
0
    def test_do_not_overwrite(self):
        item = Item(path="/file", initial_key="F")
        item.add(self.lib)

        self.command_output.return_value = "dbm"
        self.run_command("keyfinder")

        item.load()
        self.assertEqual(item["initial_key"], "F")
Esempio n. 20
0
    def test_add_key(self):
        item = Item(path='/file')
        item.add(self.lib)

        self.command_output.return_value = 'dbm'
        self.run_command('keyfinder')

        item.load()
        self.assertEqual(item['initial_key'], 'C#m')
        self.command_output.assert_called_with(['KeyFinder', '-f', item.path])
Esempio n. 21
0
    def test_add_key(self):
        item = Item(path="/file")
        item.add(self.lib)

        self.command_output.return_value = "dbm"
        self.run_command("keyfinder")

        item.load()
        self.assertEqual(item["initial_key"], "C#m")
        self.command_output.assert_called_with(["KeyFinder", "-f", item.path])
Esempio n. 22
0
    def test_normal_case(self):
        item = Item(path='/file',
                    mb_workid=u'e27bda6e-531e-36d3-9cd7-b8ebc18e8c53')
        item.add(self.lib)

        self.run_command('parentwork')

        item.load()
        self.assertEqual(item['mb_parentworkid'],
                         u'32c8943f-1b27-3a23-8660-4567f4847c94')
Esempio n. 23
0
    def test_force_overwrite(self):
        self.config['keyfinder']['overwrite'] = True

        item = Item(path='/file', initial_key='F')
        item.add(self.lib)

        self.command_output.return_value = 'C#m'
        self.run_command('keyfinder')

        item.load()
        self.assertEqual(item['initial_key'], 'C#m')
Esempio n. 24
0
    def test_get_item(self):
        item_path = '/foo/bar.flac'
        item = Item(title=u'title', path=item_path, id=1)
        item.add(self.lib)

        log = Mock()
        mpdstats = MPDStats(self.lib, log)

        self.assertEqual(str(mpdstats.get_item(item_path)), str(item))
        self.assertIsNone(mpdstats.get_item('/some/non-existing/path'))
        self.assertIn(u'item not found:', log.info.call_args[0][0])
Esempio n. 25
0
    def test_add_key(self, command_output):
        item = Item(path='/file')
        item.add(self.lib)

        command_output.return_value = util.CommandOutput(b"dbm", b"")
        self.run_command('keyfinder')

        item.load()
        self.assertEqual(item['initial_key'], 'C#m')
        command_output.assert_called_with(
            ['KeyFinder', '-f', util.syspath(item.path)])
Esempio n. 26
0
    def test_force_overwrite(self):
        self.config['keyfinder']['overwrite'] = True

        item = Item(path='/file', initial_key='F')
        item.add(self.lib)

        self.command_output.return_value = 'C#m'
        self.run_command('keyfinder')

        item.load()
        self.assertEqual(item['initial_key'], 'C#m')
Esempio n. 27
0
    def test_add_key(self):
        item = Item(path='/file')
        item.add(self.lib)

        self.command_output.return_value = 'dbm'
        self.run_command('keyfinder')

        item.load()
        self.assertEqual(item['initial_key'], 'C#m')
        self.command_output.assert_called_with(
            ['KeyFinder', '-f', item.path])
Esempio n. 28
0
    def test_force_overwrite(self):
        self.config["keyfinder"]["overwrite"] = True

        item = Item(path="/file", initial_key="F")
        item.add(self.lib)

        self.command_output.return_value = "C#m"
        self.run_command("keyfinder")

        item.load()
        self.assertEqual(item["initial_key"], "C#m")
Esempio n. 29
0
    def test_no_force(self):
        self.config['parentwork']['force'] = True
        item = Item(path='/file',
                    mb_workid=u'e27bda6e-531e-36d3-9cd7-\
                    b8ebc18e8c53',
                    mb_parentworkid=u'XXX')
        item.add(self.lib)

        self.run_command('parentwork')

        item.load()
        self.assertEqual(item['mb_parentworkid'], u'XXX')
Esempio n. 30
0
    def test_track_for_id(self):
        """Tests if plugin is able to fetch a track by its Spotify ID"""

        # Mock the Spotify 'Get Track' call
        json_file = os.path.join(_common.RSRC, b'spotify', b'track_info.json')
        with open(json_file, 'rb') as f:
            response_body = f.read()

        responses.add(
            responses.GET,
            spotify.SpotifyPlugin.track_url + '6NPVjNh8Jhru9xOmyQigds',
            body=response_body,
            status=200,
            content_type='application/json',
        )

        # Mock the Spotify 'Get Album' call
        json_file = os.path.join(_common.RSRC, b'spotify', b'album_info.json')
        with open(json_file, 'rb') as f:
            response_body = f.read()

        responses.add(
            responses.GET,
            spotify.SpotifyPlugin.album_url + '5l3zEmMrOhOzG8d8s83GOL',
            body=response_body,
            status=200,
            content_type='application/json',
        )

        # Mock the Spotify 'Search' call
        json_file = os.path.join(_common.RSRC, b'spotify',
                                 b'track_request.json')
        with open(json_file, 'rb') as f:
            response_body = f.read()

        responses.add(
            responses.GET,
            spotify.SpotifyPlugin.search_url,
            body=response_body,
            status=200,
            content_type='application/json',
        )

        track_info = self.spotify.track_for_id('6NPVjNh8Jhru9xOmyQigds')
        item = Item(mb_trackid=track_info.track_id,
                    albumartist=track_info.artist,
                    title=track_info.title,
                    length=track_info.length)
        item.add(self.lib)

        results = self.spotify._match_library_tracks(self.lib, "Happy")
        self.assertEqual(1, len(results))
        self.assertEqual("6NPVjNh8Jhru9xOmyQigds", results[0]['id'])
Esempio n. 31
0
    def test_force(self):
        self.config['parentwork']['force'] = True
        item = Item(path='/file',
                    mb_workid=u'e27bda6e-531e-36d3-9cd7-b8ebc18e8c53',
                    mb_parentworkid=u'XXX')
        item.add(self.lib)

        self.run_command('parentwork')

        item.load()
        self.assertEqual(item['mb_parentworkid'],
                         u'32c8943f-1b27-3a23-8660-4567f4847c94')
Esempio n. 32
0
    def test_no_force(self):
        self.config['parentwork']['force'] = False
        item = Item(path='/file',
                    mb_workid='1',
                    mb_parentworkid=u'XXX',
                    parentwork_workid_current='1',
                    parentwork='parentwork')
        item.add(self.lib)

        self.run_command('parentwork')

        item.load()
        self.assertEqual(item['mb_parentworkid'], u'XXX')
Esempio n. 33
0
    def test_run_mpdstats(self, mpd_mock):
        item = Item(title=u'title', path=self.item_path, id=1)
        item.add(self.lib)

        log = Mock()
        try:
            MPDStats(self.lib, log).run()
        except KeyboardInterrupt:
            pass

        log.debug.assert_has_calls(
            [call(u'unhandled status "{0}"', ANY)])
        log.info.assert_has_calls(
            [call(u'pause'), call(u'playing {0}', ANY), call(u'stop')])
Esempio n. 34
0
    def test_no_force_real(self):
        self.config['parentwork']['force'] = False
        item = Item(path='/file',
                    mb_workid='e27bda6e-531e-36d3-9cd7-\
                    b8ebc18e8c53',
                    mb_parentworkid='XXX',
                    parentwork_workid_current='e27bda6e-531e-36d3-9cd7-\
                    b8ebc18e8c53',
                    parentwork='whatever')
        item.add(self.lib)

        self.run_command('parentwork')

        item.load()
        self.assertEqual(item['mb_parentworkid'], 'XXX')
Esempio n. 35
0
    def add_item(self, **values_):
        """Add an item to the library and return it.

        The item receives sensible default values for the title, artist,
        and album fields. These default values contain unicode
        characters to test for encoding issues. The track title also
        includes a counter to make sure we do not create items with the
        same attributes.
        """
        values = {
            'title': u't\u00eftle {0}'.format(self._get_item_count()),
            'artist': u'the \u00e4rtist',
            'album': u'the \u00e4lbum',
        }
        values.update(values_)
        item = Item(**values)
        if hasattr(self, 'lib'):
            item.add(self.lib)
        return item
Esempio n. 36
0
    def test_flex_field_type(self):
        class RatingPlugin(plugins.BeetsPlugin):
            item_types = {'rating': types.Float()}

        self.register_plugin(RatingPlugin)
        self.config['plugins'] = 'rating'

        item = Item(path='apath', artist='aaa')
        item.add(self.lib)

        # Do not match unset values
        out = self.run_with_output('ls', 'rating:1..3')
        self.assertNotIn('aaa', out)

        self.run_command('modify', 'rating=2', '--yes')

        # Match in range
        out = self.run_with_output('ls', 'rating:1..3')
        self.assertIn('aaa', out)

        # Don't match out of range
        out = self.run_with_output('ls', 'rating:3..5')
        self.assertNotIn('aaa', out)
Esempio n. 37
0
 def test_custom_field_range_query(self):
     item = Item(liveness=2.2)
     item.add(self.lib)
     item = self.lib.items('liveness:2.2..3').get()
     self.assertEqual(item['liveness'], 2.2)
Esempio n. 38
0
 def test_track_request(self):
     response_body = str(
         '{'
         '"tracks" : {'
         '"href" : "https://api.spotify.com/v1/search?query=Happy+album%3A'
         'Despicable+Me+2+artist%3APharrell+Williams&offset=0&limit=20'
         '&type=track",'
         '"items" : [ {'
         '"album" : {'
         '"album_type" : "compilation",'
         '"available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG",'
         '"BO", "BR", "CA", "CH", "CL", "CO",'
         '"CR", "CY", "CZ", "DE", "DK", "DO",'
         '"EC", "EE", "ES", "FI", "FR", "GB",'
         '"GR", "GT", "HK", "HN", "HU", "IE",'
         '"IS", "IT", "LI", "LT", "LU", "LV",'
         '"MC", "MT", "MX", "MY", "NI", "NL",'
         '"NO", "NZ", "PA", "PE", "PH", "PL",'
         '"PT", "PY", "RO", "SE", "SG", "SI",'
         '"SK", "SV", "TR", "TW", "US", "UY" ],'
         '"external_urls" : {'
         '"spotify" : "https://open.spotify.com/album/'
         '5l3zEmMrOhOzG8d8s83GOL"'
         '},'
         '"href" : "https://api.spotify.com/v1/albums/'
         '5l3zEmMrOhOzG8d8s83GOL",'
         '"id" : "5l3zEmMrOhOzG8d8s83GOL",'
         '"images" : [ {'
         '"height" : 640,'
         '"url" : "https://i.scdn.co/image/cb7905340c132365bb'
         'aee3f17498f062858382e8",'
         '"width" : 640'
         '}, {'
         '"height" : 300,'
         '"url" : "https://i.scdn.co/image/af369120f0b20099'
         'd6784ab31c88256113f10ffb",'
         '"width" : 300'
         '}, {'
         '"height" : 64,'
         '"url" : "https://i.scdn.co/image/'
         '9dad385ddf2e7db0bef20cec1fcbdb08689d9ae8",'
         '"width" : 64'
         '} ],'
         '"name" : "Despicable Me 2 (Original Motion Picture Soundtrack)",'
         '"type" : "album",'
         '"uri" : "spotify:album:5l3zEmMrOhOzG8d8s83GOL"'
         '},'
         '"artists" : [ {'
         '"external_urls" : {'
         '"spotify" : "https://open.spotify.com/artist/'
         '2RdwBSPQiwcmiDo9kixcl8"'
         '},'
         '"href" : "https://api.spotify.com/v1/artists/'
         '2RdwBSPQiwcmiDo9kixcl8",'
         '"id" : "2RdwBSPQiwcmiDo9kixcl8",'
         '"name" : "Pharrell Williams",'
         '"type" : "artist",'
         '"uri" : "spotify:artist:2RdwBSPQiwcmiDo9kixcl8"'
         '} ],'
         '"available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG", "BO",'
         '"BR", "CA", "CH", "CL", "CO", "CR", "CY",'
         '"CZ", "DE", "DK", "DO", "EC", "EE", "ES",'
         '"FI", "FR", "GB", "GR", "GT", "HK", "HN",'
         '"HU", "IE", "IS", "IT", "LI", "LT", "LU",'
         '"LV", "MC", "MT", "MX", "MY", "NI", "NL",'
         '"NO", "NZ", "PA", "PE", "PH", "PL", "PT",'
         '"PY", "RO", "SE", "SG", "SI", "SK", "SV",'
         '"TR", "TW", "US", "UY" ],'
         '"disc_number" : 1,'
         '"duration_ms" : 233305,'
         '"explicit" : false,'
         '"external_ids" : {'
         '"isrc" : "USQ4E1300686"'
         '},'
         '"external_urls" : {'
         '"spotify" : "https://open.spotify.com/track/'
         '6NPVjNh8Jhru9xOmyQigds"'
         '},'
         '"href" : "https://api.spotify.com/v1/tracks/'
         '6NPVjNh8Jhru9xOmyQigds",'
         '"id" : "6NPVjNh8Jhru9xOmyQigds",'
         '"name" : "Happy",'
         '"popularity" : 89,'
         '"preview_url" : "https://p.scdn.co/mp3-preview/'
         '6b00000be293e6b25f61c33e206a0c522b5cbc87",'
         '"track_number" : 4,'
         '"type" : "track",'
         '"uri" : "spotify:track:6NPVjNh8Jhru9xOmyQigds"'
         '} ],'
         '"limit" : 20,'
         '"next" : null,'
         '"offset" : 0,'
         '"previous" : null,'
         '"total" : 1'
         '}'
         '}'
     )
     responses.add(responses.GET,
                   'https://api.spotify.com/v1/search?q=Happy+album%3A'
                   'Despicable%20Me%202+artist%3APharrell%20'
                   'Williams&type=track',
                   body=response_body, status=200,
                   content_type='application/json')
     item = Item(
         mb_trackid='01234',
         album='Despicable Me 2',
         albumartist='Pharrell Williams',
         title='Happy',
         length=10
     )
     item.add(self.lib)
     results = self.spotify.query_spotify(self.lib, "Happy")
     self.assertEquals(1, len(results))
     self.assertEquals("6NPVjNh8Jhru9xOmyQigds", results[0]['id'])
     self.spotify.output_results(results)
Esempio n. 39
0
 def test_custom_field_range_query(self):
     item = Item(liveness=2.2)
     item.add(self.lib)
     item = self.lib.items('liveness:2.2..3').get()
     self.assertEqual(item['liveness'], 2.2)
Esempio n. 40
0
 def test_track_request(self):
     response_body = str(
         '{'
         '"tracks" : {'
         '"href" : "https://api.spotify.com/v1/search?query=Happy+album%3A'
         'Despicable+Me+2+artist%3APharrell+Williams&offset=0&limit=20'
         '&type=track",'
         '"items" : [ {'
         '"album" : {'
         '"album_type" : "compilation",'
         '"available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG",'
         '"BO", "BR", "CA", "CH", "CL", "CO",'
         '"CR", "CY", "CZ", "DE", "DK", "DO",'
         '"EC", "EE", "ES", "FI", "FR", "GB",'
         '"GR", "GT", "HK", "HN", "HU", "IE",'
         '"IS", "IT", "LI", "LT", "LU", "LV",'
         '"MC", "MT", "MX", "MY", "NI", "NL",'
         '"NO", "NZ", "PA", "PE", "PH", "PL",'
         '"PT", "PY", "RO", "SE", "SG", "SI",'
         '"SK", "SV", "TR", "TW", "US", "UY" ],'
         '"external_urls" : {'
         '"spotify" : "https://open.spotify.com/album/'
         '5l3zEmMrOhOzG8d8s83GOL"'
         '},'
         '"href" : "https://api.spotify.com/v1/albums/'
         '5l3zEmMrOhOzG8d8s83GOL",'
         '"id" : "5l3zEmMrOhOzG8d8s83GOL",'
         '"images" : [ {'
         '"height" : 640,'
         '"url" : "https://i.scdn.co/image/cb7905340c132365bb'
         'aee3f17498f062858382e8",'
         '"width" : 640'
         '}, {'
         '"height" : 300,'
         '"url" : "https://i.scdn.co/image/af369120f0b20099'
         'd6784ab31c88256113f10ffb",'
         '"width" : 300'
         '}, {'
         '"height" : 64,'
         '"url" : "https://i.scdn.co/image/'
         '9dad385ddf2e7db0bef20cec1fcbdb08689d9ae8",'
         '"width" : 64'
         '} ],'
         '"name" : "Despicable Me 2 (Original Motion Picture Soundtrack)",'
         '"type" : "album",'
         '"uri" : "spotify:album:5l3zEmMrOhOzG8d8s83GOL"'
         '},'
         '"artists" : [ {'
         '"external_urls" : {'
         '"spotify" : "https://open.spotify.com/artist/'
         '2RdwBSPQiwcmiDo9kixcl8"'
         '},'
         '"href" : "https://api.spotify.com/v1/artists/'
         '2RdwBSPQiwcmiDo9kixcl8",'
         '"id" : "2RdwBSPQiwcmiDo9kixcl8",'
         '"name" : "Pharrell Williams",'
         '"type" : "artist",'
         '"uri" : "spotify:artist:2RdwBSPQiwcmiDo9kixcl8"'
         '} ],'
         '"available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG", "BO",'
         '"BR", "CA", "CH", "CL", "CO", "CR", "CY",'
         '"CZ", "DE", "DK", "DO", "EC", "EE", "ES",'
         '"FI", "FR", "GB", "GR", "GT", "HK", "HN",'
         '"HU", "IE", "IS", "IT", "LI", "LT", "LU",'
         '"LV", "MC", "MT", "MX", "MY", "NI", "NL",'
         '"NO", "NZ", "PA", "PE", "PH", "PL", "PT",'
         '"PY", "RO", "SE", "SG", "SI", "SK", "SV",'
         '"TR", "TW", "US", "UY" ],'
         '"disc_number" : 1,'
         '"duration_ms" : 233305,'
         '"explicit" : false,'
         '"external_ids" : {'
         '"isrc" : "USQ4E1300686"'
         '},'
         '"external_urls" : {'
         '"spotify" : "https://open.spotify.com/track/'
         '6NPVjNh8Jhru9xOmyQigds"'
         '},'
         '"href" : "https://api.spotify.com/v1/tracks/'
         '6NPVjNh8Jhru9xOmyQigds",'
         '"id" : "6NPVjNh8Jhru9xOmyQigds",'
         '"name" : "Happy",'
         '"popularity" : 89,'
         '"preview_url" : "https://p.scdn.co/mp3-preview/'
         '6b00000be293e6b25f61c33e206a0c522b5cbc87",'
         '"track_number" : 4,'
         '"type" : "track",'
         '"uri" : "spotify:track:6NPVjNh8Jhru9xOmyQigds"'
         '} ],'
         '"limit" : 20,'
         '"next" : null,'
         '"offset" : 0,'
         '"previous" : null,'
         '"total" : 1'
         '}'
         '}')
     responses.add(responses.GET,
                   'https://api.spotify.com/v1/search?q=Happy+album%3A'
                   'Despicable%20Me%202+artist%3APharrell%20'
                   'Williams&type=track',
                   body=response_body,
                   status=200,
                   content_type='application/json')
     item = Item(mb_trackid='01234',
                 album='Despicable Me 2',
                 albumartist='Pharrell Williams',
                 title='Happy',
                 length=10)
     item.add(self.lib)
     results = self.spotify.query_spotify(self.lib, "Happy")
     self.assertEquals(1, len(results))
     self.assertEquals("6NPVjNh8Jhru9xOmyQigds", results[0]['id'])
     self.spotify.output_results(results)