Beispiel #1
0
    def test_specifying_pos_args_until_limit(self):
        client = Spotify(self.app_token, max_limits_on=True)
        s1, = client.search('piano', ('track', ), None, None)
        with client.max_limits(False):
            s2, = client.search('piano', ('track', ), None, None)

        self.assertGreater(s1.limit, s2.limit)
Beispiel #2
0
    def test_turning_on_max_limits_returns_more(self):
        client = Spotify(self.app_token)
        s1, = client.search('piano')
        with client.max_limits(True):
            s2, = client.search('piano')

        self.assertLess(s1.limit, s2.limit)
Beispiel #3
0
    def test_turning_off_max_limits_returns_less(self):
        client = Spotify(self.app_token, max_limits_on=True)
        s1, = client.search('piano')
        with client.max_limits(False):
            s2, = client.search('piano')

        self.assertGreater(s1.limit, s2.limit)
Beispiel #4
0
class TestSpotifyBaseUnits(TestCase):
    def setUp(self):
        self.client = Spotify('token')

    def test_new_token_used_in_context(self):
        with self.client.token_as('new'):
            self.assertEqual(self.client.token, 'new')

    def test_old_token_restored_after_context(self):
        with self.client.token_as('new'):
            pass
        self.assertEqual(self.client.token, 'token')

    def test_next_with_no_next_set_returns_none(self):
        paging = MagicMock()
        paging.next = None

        next_ = self.client.next(paging)
        self.assertIsNone(next_)

    def test_previous_with_no_previous_set_returns_none(self):
        paging = MagicMock()
        paging.previous = None

        previous = self.client.previous(paging)
        self.assertIsNone(previous)
Beispiel #5
0
    def setUpClass(cls):
        super().setUpClass()

        try:
            cls.user_token = cls.cred.refresh_user_token(cls.user_refresh)
        except HTTPError as e:
            skip_or_fail(HTTPError, 'Error in retrieving user token!', e)

        client = Spotify(cls.user_token)

        try:
            cls.current_user_id = client.current_user().id
        except HTTPError as e:
            skip_or_fail(
                HTTPError,
                'ID of current user could not be retrieved!',
                e
            )
Beispiel #6
0
    def setUpClass(cls):
        super().setUpClass()
        cls.aclient = Spotify(cls.user_token, asynchronous=True)

        cls.tracks = cls.client.album_tracks(album_id, limit=1)
        cls.played = cls.client.playback_recently_played()

        cls.handle = handle_warnings()
        cls.handle.__enter__()
Beispiel #7
0
    def setUpClass(cls):
        super().setUpClass()

        cls.cred = Credentials(
            cls.client_id,
            cls.client_secret,
            cls.redirect_uri
        )

        try:
            cls.app_token = cls.cred.request_client_token()
        except HTTPError as e:
            skip_or_fail(HTTPError, 'Error in retrieving application token!', e)

        sender = RetryingSender(sender=PersistentSender())
        cls.client = Spotify(cls.app_token, sender=sender)
Beispiel #8
0
class TestSpotifyPlayer(TestCaseWithUserCredentials):
    def setUp(self):
        self.client = Spotify(self.user_token)

    def test_recently_played(self):
        self.client.playback_recently_played()

    def test_recently_played_before_timestamp_next_is_before_current(self):
        p1 = self.client.playback_recently_played(limit=1)
        p2 = self.client.next(p1)
        self.assertLess(p2.cursors.after, p1.cursors.after)

    def test_recently_played_after_timestamp_next_is_after_current(self):
        p1 = self.client.playback_recently_played(limit=1, after=1569888000)
        p2 = self.client.next(p1)
        self.assertGreater(p2.cursors.after, p1.cursors.after)
Beispiel #9
0
    def test_specifying_limit_pos_arg_overrides_max_limits(self):
        client = Spotify(self.app_token, max_limits_on=True)
        s, = client.search('piano', ('track', ), None, None, 1)

        self.assertEqual(s.limit, 1)
Beispiel #10
0
    def test_specifying_limit_kwarg_overrides_max_limits(self):
        client = Spotify(self.app_token, max_limits_on=True)
        s, = client.search('piano', limit=1)

        self.assertEqual(s.limit, 1)
Beispiel #11
0
 def setUp(self):
     self.client = Spotify('token')
Beispiel #12
0
 def test_chunked_context_enables(self):
     client = Spotify(self.app_token)
     with client.chunked(True):
         self.assertTrue(client.chunked_on)
Beispiel #13
0
 def test_async_too_many_tracks_chunked_succeeds(self):
     client = Spotify(self.app_token, chunked_on=True, asynchronous=True)
     tracks = run(client.tracks(self.track_ids))
     self.assertEqual(len(self.track_ids), len(tracks))
Beispiel #14
0
 def test_too_many_tracks_chunked_succeeds(self):
     client = Spotify(self.app_token, chunked_on=True)
     tracks = client.tracks(self.track_ids)
     self.assertEqual(len(self.track_ids), len(tracks))
Beispiel #15
0
 def setUp(self):
     self.client = Spotify(self.user_token)
Beispiel #16
0
    def test_too_many_tracks_raises(self):
        client = Spotify(self.app_token)

        with self.assertRaises(BadRequest):
            client.tracks(self.track_ids)
Beispiel #17
0
    def test_async_too_many_tracks_raises(self):
        client = Spotify(self.app_token, asynchronous=True)

        with self.assertRaises(BadRequest):
            run(client.tracks(self.track_ids))
Beispiel #18
0
 def test_chunked_context_disables(self):
     client = Spotify(self.app_token, chunked_on=True)
     with client.chunked(False):
         self.assertFalse(client.chunked_on)