def test_client_access_token(): client = APIClient(access_token="foo") assert client.access_token == "foo" assert client.session.headers['Authorization'] == "Bearer foo" client.access_token = "bar" assert client.access_token == "bar" assert client.session.headers['Authorization'] == "Bearer bar" client.access_token = None assert client.access_token is None assert 'Authorization' not in client.session.headers
def test_custom_client(): # Can specify API server custom = APIClient(api_server="https://example.com") assert custom.api_server == "https://example.com" # Must be a valid URL with pytest.raises(Exception) as exc: APIClient(api_server="invalid") assert exc.value.args[0] == ( "When overriding the Nylas API server address, " "you must include https://")
def test_client_access_token(): client = APIClient(access_token="foo") assert client.access_token == "foo" assert client.session.headers["Authorization"] == "Bearer foo" client.access_token = "bar" assert client.access_token == "bar" assert client.session.headers["Authorization"] == "Bearer bar" client.access_token = None assert client.access_token is None assert "Authorization" not in client.session.headers
def test_client_admin_headers(): client = APIClient(app_id="bounce", app_secret="foo") headers = client.admin_session.headers assert headers["Authorization"] == "Basic Zm9vOg==" assert headers["X-Nylas-API-Wrapper"] == "python" assert headers["X-Nylas-Client-Id"] == "bounce" assert "Nylas Python SDK" in headers["User-Agent"]
def test_client_headers(): client = APIClient(app_id="whee", app_secret="foo") headers = client.session.headers assert headers["X-Nylas-API-Wrapper"] == "python" assert headers["X-Nylas-Client-Id"] == "whee" assert "Nylas Python SDK" in headers["User-Agent"] assert "Authorization" not in headers
def test_client_app_secret(): client = APIClient(app_secret="foo") headers = client.admin_session.headers assert headers['Authorization'] == "Basic Zm9vOg==" assert headers['X-Nylas-API-Wrapper'] == "python" assert "Nylas Python SDK" in headers['User-Agent']