def test_is_token_expired__fail(self): now = 1326542400 not_expired_token = { 'expires_at': (now + 61), } result = SpotifyOAuth.is_token_expired(not_expired_token) assert not result
def test_is_token_expired__pass(self): now = 1326542400 expired_token = { 'expires_at': now, } result = SpotifyOAuth.is_token_expired(expired_token) assert result
def _spotify_oauth(requester=None, client_id="arbitrary-client_id", client_secret="arbitrary-client_secret", redirect_uri="arbitrary-redirect_uri", state="arbitrary-state", scope="arbitrary-scope") -> SpotifyOAuth: return SpotifyOAuth(requester, client_id, client_secret, redirect_uri, state, scope)
def test_cookie_to_dict(self): cookie = "specific-access_token|specific-refresh_token|1531958718" actual = SpotifyOAuth.cookie_to_dict(cookie) expected = { "access_token": "specific-access_token", "refresh_token": "specific-refresh_token", "expires_at": "1531958718", } assert actual == expected
def _spotify_oauth() -> SpotifyOAuth: c = cfg.spotify_api() redirect_uri = '%s/callback' % \ ('https://musicify.herokuapp.com' if IS_PRODUCTION else 'http://0.0.0.0:8000') state = 'TODO' scope = 'user-read-private' return SpotifyOAuth( requests, # Pass in the external library client_id=c['client_id'], client_secret=c['client_secret'], redirect_uri=redirect_uri, state=state, scope=scope)
def test_decorate_with_expires_at(self): now = 1326542400 token = {'expires_in': 1} result = SpotifyOAuth._decorate_with_expires_at(token) assert result['expires_at'] == (now + 1)
def test_normalize_scope__fail(self): scope = "" actual = SpotifyOAuth._normalize_scope(scope) expected = None assert actual == expected
def test_normalize_scope__pass(self): scope = "specific-scope-3 specific-scope-2 specific-scope-1" actual = SpotifyOAuth._normalize_scope(scope) expected = "specific-scope-1 specific-scope-2 specific-scope-3" assert actual == expected
def test_json_to_cookie(self): actual = SpotifyOAuth.json_to_cookie(_fake_token()) expected = "specific-access_token|specific-refresh_token|1531958718" assert actual == expected