コード例 #1
0
    async def test_renewal_with_error(self, prepared_api: SpotifyApiClient):
        invalid_token = prepared_api.spotify_authorization_token
        invalid_token.access_token = 'invalid'
        prepared_api.spotify_authorization_token = invalid_token

        prepared_api.token_renew_instance = FalseRenew()

        with pytest.raises(TokenExpired):
            await prepared_api.albums.get_one('03dlqdFWY9gwJxGl3AREVy')
コード例 #2
0
    def test_get_hold_authentication(self, api: SpotifyApiClient):
        api.hold_authentication = False
        assert False is api.hold_authentication

        with pytest.raises(SpotifyError):
            api.spotify_authorization_token = SpotifyAuthorisationToken()

        with pytest.raises(SpotifyError):
            token = api.spotify_authorization_token
コード例 #3
0
    async def test_renewal(self, prepared_api: SpotifyApiClient):
        invalid_token = prepared_api.spotify_authorization_token
        invalid_token.access_token = 'invalid'
        prepared_api.spotify_authorization_token = invalid_token

        prepared_api.token_renew_instance = TokenRenewClass()

        album = await prepared_api.albums.get_one('03dlqdFWY9gwJxGl3AREVy')
        assert isinstance(album, dict)
コード例 #4
0
    async def test_inability_to_get_token_with_client_credentials(self, api: SpotifyApiClient):
        auth_code_flow = AuthorizationCodeFlow()
        auth_code_flow.load_from_env()

        api = SpotifyApiClient(auth_code_flow)
        with pytest.raises(SpotifyError):
            await api.get_auth_token_with_client_credentials()
コード例 #5
0
    async def test_inability_to_get_token_client_credential(self):
        client_credentials = ClientCredentialsFlow()
        client_credentials.load_from_env()
        client_credentials.scopes = TestDataTransfer.scopes

        api = SpotifyApiClient(client_credentials)
        with pytest.raises(SpotifyError):
            await api.get_code_with_cookie(TestDataTransfer.cookies)
コード例 #6
0
    async def test_authorization_code_flow(self, api: SpotifyApiClient):
        auth_code_flow = AuthorizationCodeFlow()
        auth_code_flow.load_from_env()
        auth_code_flow.scopes = TestDataTransfer.scopes

        api = SpotifyApiClient(auth_code_flow)
        code = await api.get_code_with_cookie(TestDataTransfer.cookies)
        await api.get_auth_token_with_code(code)
コード例 #7
0
    def test_pass_authentication(self):
        client = SpotifyApiClient(
            TestDataTransfer.auth_code_flow,
            hold_authentication=True,
            spotify_authorisation_token=SpotifyAuthorisationToken(
                refresh_token='1'))

        assert client.spotify_authorization_token.refresh_token is '1'
コード例 #8
0
 def test_auth_url(self, api: SpotifyApiClient):
     url = api.build_authorization_url(show_dialog=False, state="TestState")
     assert ("show_dialog=False" in url and "state=TestState" in url
             and TestDataTransfer.auth_code_flow.application_id in url
             and urlencode({
                 "redirect_uri":
                 TestDataTransfer.auth_code_flow.redirect_url
             }) in url)
コード例 #9
0
    async def test_wrong_code_url(self):
        auth_flow = AuthorizationCodeFlow("test-with-wrong-code",
                                          "test-with-wrong-code",
                                          ["test-with-wrong-code"],
                                          "test-with-wrong-code")
        api = SpotifyApiClient(auth_flow)

        with pytest.raises(SpotifyError):
            await api.get_code_with_cookie(TestDataTransfer.cookies)
コード例 #10
0
    async def test_expired_token(self, prepared_api: SpotifyApiClient):
        await prepared_api.create_new_client()
        token = SpotifyAuthorisationToken(access_token='t',
                                          refresh_token='i',
                                          activation_time=int(time.time()))

        prepared_api.spotify_authorization_token = token

        with pytest.raises(TokenExpired):
            await prepared_api.albums.get_one('03dlqdFWY9gwJxGl3AREVy')
コード例 #11
0
    def add_api():
        """
        Add api parameter
        """
        auth_code_flow = AuthorizationCodeFlow()
        auth_code_flow.load_from_env()
        auth_code_flow.scopes = TestDataTransfer.scopes

        TestDataTransfer.api = SpotifyApiClient(auth_code_flow,
                                                hold_authentication=True)
コード例 #12
0
    async def test_client_credentials(self):
        client_credentials = ClientCredentialsFlow()
        client_credentials.load_from_env()
        client_credentials.scopes = TestDataTransfer.scopes

        api = SpotifyApiClient(client_credentials)
        await api.get_auth_token_with_client_credentials()
        await api.create_new_client()

        resp = await api.albums.get_one('03dlqdFWY9gwJxGl3AREVy')
        assert isinstance(resp, dict)
コード例 #13
0
def api():
    """
    Returns: The an api instance
    """

    auth_code_flow = AuthorizationCodeFlow()
    auth_code_flow.load_from_env()
    auth_code_flow.scopes = TestDataTransfer.scopes

    api = SpotifyApiClient(auth_code_flow)
    return api
コード例 #14
0
    def __init__(self, bot):
        self.bot = bot
        self.games = {}

        if not bot.spy_client:
            auth_flow = AuthorizationCodeFlow(scopes=[])
            auth_flow.load_from_env()
            api_client = SpotifyApiClient(
                auth_flow,
                hold_authentication=True,
                token_renew_instance=TokenRenewClass())
            bot.spy_client = api_client
            bot.loop.create_task(self.connect_to_spotify())

        bot.loop.create_task(self.create_tables())
コード例 #15
0
async def prepared_api():
    """
    Returns: A ready to go api client
    """

    auth_code_flow = AuthorizationCodeFlow()
    auth_code_flow.load_from_env()
    auth_code_flow.scopes = TestDataTransfer.scopes

    api = SpotifyApiClient(auth_code_flow, hold_authentication=True)
    code = await api.get_code_with_cookie(TestDataTransfer.cookies)
    await api.get_auth_token_with_code(code)

    await api.create_new_client()

    yield api

    await api.close_client()
コード例 #16
0
    def test_getter_and_setter(self, prepared_api: SpotifyApiClient):
        renew = TokenRenewClass()
        prepared_api.token_renew_instance = renew

        assert prepared_api.token_renew_instance is renew
コード例 #17
0
 def test_load_wrong_auth_flow(self):
     auth_flow = AuthorizationCodeFlow()
     with pytest.raises(SpotifyError):
         SpotifyApiClient(auth_flow)
コード例 #18
0
 def test_open_browser(self, api: SpotifyApiClient):
     api.open_oauth_dialog_in_browser()
     assert True
コード例 #19
0
 async def test_remove_authentication(self, prepared_api: SpotifyApiClient):
     prepared_api.hold_authentication = False
     await prepared_api.create_new_client()
     with pytest.raises(SpotifyError):
         await prepared_api.albums.get_one('somerandomstring')
     await prepared_api.close_client()