Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 def test_is_token_expired__pass(self):
     now = 1326542400
     expired_token = {
         'expires_at': now,
     }
     result = SpotifyOAuth.is_token_expired(expired_token)
     assert result
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 def test_normalize_scope__fail(self):
     scope = ""
     actual = SpotifyOAuth._normalize_scope(scope)
     expected = None
     assert actual == expected
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
 def test_json_to_cookie(self):
     actual = SpotifyOAuth.json_to_cookie(_fake_token())
     expected = "specific-access_token|specific-refresh_token|1531958718"
     assert actual == expected