示例#1
0
def test_and_get_me_attr_attr_exists():
    spt = Spotify()

    spt.user_creds = UserCreds()
    spt.user_creds.id = "id1234"

    assert _set_and_get_me_attr_sync(spt, "id") == "id1234"
示例#2
0
def user_creds_from_env():
    user = UserCreds()
    user.load_from_env()
    if not user.access_token:
        raise AttributeError(
            "User must have an access token for some tests to run")
    yield user
示例#3
0
文件: spthelper.py 项目: Nksama/Panda
    def __init__(
        self,
        access_token=None,
        refresh_token=None,
    ):
        scopes = [
            "user-read-recently-played",
            "user-read-playback-state",
        ]

        user_creds = None

        if access_token and refresh_token:
            user_creds = UserCreds(access_token=access_token,
                                   refresh_token=refresh_token)

        super().__init__(
            client_creds=ClientCreds(
                client_id=SPT_CLIENT_ID,
                client_secret=SPT_CLIENT_SECRET,
                redirect_uri=APP_URL + "acutebot/webserver",
                scopes=scopes,
            ),
            user_creds=user_creds,
        )
    def __init__(
        self,
        access_token=None,
        refresh_token=None,
    ):
        scopes = [
            "user-read-recently-played",
            "user-read-playback-state",
            "user-modify-playback-state",
        ]

        user_creds = None

        if access_token and refresh_token:
            user_creds = UserCreds(access_token=access_token,
                                   refresh_token=refresh_token)

        super().__init__(
            client_creds=ClientCreds(
                client_id=os.getenv("SPOTIFY_CLIENT_ID"),
                client_secret=os.getenv("SPOTIFY_CLIENT_SECRET"),
                redirect_uri=os.getenv("SPOTIFY_CLIENT_REDIRECT"),
                scopes=scopes,
            ),
            user_creds=user_creds,
        )
示例#5
0
def test_populate_user_creds(me_stub):
    spt = Spotify(populate_user_creds=False)  # Offline test
    user = UserCreds()
    spt.user_creds = user
    spt._populate_user_creds(me_stub)
    assert getattr(spt.user_creds, "type", None) is None
    assert spt.user_creds.product == "premium"
示例#6
0
async def test_and_get_me_attr_attr_exists_async():
    spt = AsyncSpotify()

    spt.user_creds = UserCreds()
    spt.user_creds.id = 'id1234'

    assert await _set_and_get_me_attr_async(spt, 'id') == 'id1234'
示例#7
0
    def __init__(
        self,
        access_token=None,
        refresh_token=None,
        # modify_playback_state=False
    ):
        scopes = [
            "user-read-recently-played",
            "user-read-playback-state",
            "user-modify-playback-state",
        ]

        """
        if modify_playback_state:
            scopes.append("user-modify-playback-state")
        """

        user_creds = None

        if access_token and refresh_token:
            user_creds = UserCreds(
                access_token=access_token, refresh_token=refresh_token
            )

        super().__init__(
            client_creds=ClientCreds(
                client_id=config["spotify"]["client_id"],
                client_secret=config["spotify"]["client_secret"],
                redirect_uri=config["spotify"]["client_redirect"],
                scopes=scopes,
            ),
            user_creds=user_creds,
        )
示例#8
0
def test_client_instantiates_with_user_creds():
    u = UserCreds()
    u.load_from_env()
    spt = Spotify(user_creds=u,
                  ensure_user_auth=False,
                  populate_user_creds=False)
    assert spt.user_creds.access_token is not None

    assert spt._caller == spt.user_creds
示例#9
0
def async_spotify_user_auth():
    spotify = AsyncSpotify()
    user_creds = UserCreds()
    client_creds = ClientCreds()
    client_creds.load_from_env()
    user_creds.load_from_env()
    spotify.client_creds = client_creds
    spotify.user_creds = user_creds
    spotify._caller = spotify.user_creds
    yield spotify
示例#10
0
def test_client_instantiates_with_access_token():
    u = UserCreds()
    u.load_from_env()
    access_token = u.access_token
    spt = Spotify(access_token=access_token,
                  ensure_user_auth=False,
                  populate_user_creds=False)
    assert spt.user_creds.access_token is not None
    assert spt.user_creds.refresh_token is None

    assert spt._caller == spt.user_creds

    assert not hasattr(spt, "access_token")
def get_credentials(user):
    return UserCreds(access_token=user.spotify_access_token,
                     refresh_token=user.spotify_refresh_token)
示例#12
0
def user_creds_from_env_session():
    user = UserCreds()
    user.load_from_env()
    yield user
示例#13
0
def test_creds_json_loads_data_properly(user_creds_from_env):
    user_creds_from_env.save_as_json()
    new_user_creds = UserCreds()
    new_user_creds.load_from_json()
    assert new_user_creds.__dict__ == user_creds_from_env.__dict__
    user_creds_from_env._delete_json()
示例#14
0
def test_caller_defaults_to_user():
    u = UserCreds(access_token="asdasdasd")
    c = Spotify(user_creds=u, populate_user_creds=False)
    assert c._caller == c.user_creds
示例#15
0
def test_client_raises_error_if_both_access_token_and_model():
    u = UserCreds()
    u.load_from_env()
    with pytest.raises(ValueError):
        Spotify(user_creds=u, access_token=u.access_token)