def test_client_api_key(): """Setting up a valid api key or access token should be possible.""" client = Client() client.set_access_token('access_123') assert client.api_key == 'access_123' client.set_api_key('live_123') assert client.api_key == 'live_123' client.set_api_key('test_123') assert client.api_key == 'test_123'
def test_client_invalid_api_key(): """Setting up an invalid api key raises an error.""" client = Client() with pytest.raises(RequestSetupError, match="Invalid API key: 'invalid'"): client.set_api_key('invalid') with pytest.raises(RequestSetupError, match="Invalid API key: 'access_123'"): client.set_api_key('access_123') with pytest.raises(RequestSetupError, match="Invalid access token: 'invalid'"): client.set_access_token('invalid') with pytest.raises(RequestSetupError, match="Invalid access token: 'live_123'"): client.set_access_token('live_123') with pytest.raises(RequestSetupError, match="Invalid access token: 'test_123'"): client.set_access_token('test_123')
def test_client_user_agent_with_access_token(): """When authenticating with an access token, the User-Agent should contain an OAuth component.""" client = Client() assert 'OAuth'.lower() not in client.user_agent.lower() client.set_access_token('access_123') assert 'OAuth/2.0' in client.user_agent
def test_client_user_agent_with_oauth(): """When authenticating with an access token, the User-Agent should cont an OAuth component.""" client = Client() assert 'OAuth'.lower() not in client.user_agent.lower() client.set_access_token('access_123') assert 'OAuth/2.0' in client.user_agent