Skip to content

feat(api): manual updates #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 10 additions & 46 deletions src/finch/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ class Finch(SyncAPIClient):
access_token: str | None
client_id: str | None
client_secret: str | None
sandbox_client_id: str | None
sandbox_client_secret: str | None
webhook_secret: str | None

def __init__(
Expand All @@ -78,8 +76,6 @@ def __init__(
access_token: str | None = None,
client_id: str | None = None,
client_secret: str | None = None,
sandbox_client_id: str | None = None,
sandbox_client_secret: str | None = None,
webhook_secret: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
Expand Down Expand Up @@ -111,8 +107,6 @@ def __init__(
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
- `client_id` from `FINCH_CLIENT_ID`
- `client_secret` from `FINCH_CLIENT_SECRET`
- `sandbox_client_id` from `FINCH_SANDBOX_CLIENT_ID`
- `sandbox_client_secret` from `FINCH_SANDBOX_CLIENT_SECRET`
- `webhook_secret` from `FINCH_WEBHOOK_SECRET`
"""
self.access_token = access_token
Expand All @@ -125,14 +119,6 @@ def __init__(
client_secret = os.environ.get("FINCH_CLIENT_SECRET")
self.client_secret = client_secret

if sandbox_client_id is None:
sandbox_client_id = os.environ.get("FINCH_SANDBOX_CLIENT_ID")
self.sandbox_client_id = sandbox_client_id

if sandbox_client_secret is None:
sandbox_client_secret = os.environ.get("FINCH_SANDBOX_CLIENT_SECRET")
self.sandbox_client_secret = sandbox_client_secret

if webhook_secret is None:
webhook_secret = os.environ.get("FINCH_WEBHOOK_SECRET")
self.webhook_secret = webhook_secret
Expand Down Expand Up @@ -191,11 +177,11 @@ def _bearer_auth(self) -> dict[str, str]:

@property
def _basic_auth(self) -> dict[str, str]:
if self.sandbox_client_id is None:
if self.client_id is None:
return {}
if self.sandbox_client_secret is None:
if self.client_secret is None:
return {}
credentials = f"{self.sandbox_client_id}:{self.sandbox_client_secret}".encode("ascii")
credentials = f"{self.client_id}:{self.client_secret}".encode("ascii")
header = f"Basic {base64.b64encode(credentials).decode('ascii')}"
return {"Authorization": header}

Expand All @@ -216,13 +202,13 @@ def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
if isinstance(custom_headers.get("Authorization"), Omit):
return

if self.sandbox_client_id and self.sandbox_client_secret and headers.get("Authorization"):
if self.client_id and self.client_secret and headers.get("Authorization"):
return
if isinstance(custom_headers.get("Authorization"), Omit):
return

raise TypeError(
'"Could not resolve authentication method. Expected either access_token, sandbox_client_id or sandbox_client_secret to be set. Or for one of the `Authorization` or `Authorization` headers to be explicitly omitted"'
'"Could not resolve authentication method. Expected either access_token, client_id or client_secret to be set. Or for one of the `Authorization` or `Authorization` headers to be explicitly omitted"'
)

def copy(
Expand All @@ -231,8 +217,6 @@ def copy(
access_token: str | None = None,
client_id: str | None = None,
client_secret: str | None = None,
sandbox_client_id: str | None = None,
sandbox_client_secret: str | None = None,
webhook_secret: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -288,8 +272,6 @@ def copy(
access_token=access_token or self.access_token,
client_id=client_id or self.client_id,
client_secret=client_secret or self.client_secret,
sandbox_client_id=sandbox_client_id or self.sandbox_client_id,
sandbox_client_secret=sandbox_client_secret or self.sandbox_client_secret,
webhook_secret=webhook_secret or self.webhook_secret,
base_url=base_url or self.base_url,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
Expand Down Expand Up @@ -356,8 +338,6 @@ class AsyncFinch(AsyncAPIClient):
access_token: str | None
client_id: str | None
client_secret: str | None
sandbox_client_id: str | None
sandbox_client_secret: str | None
webhook_secret: str | None

def __init__(
Expand All @@ -366,8 +346,6 @@ def __init__(
access_token: str | None = None,
client_id: str | None = None,
client_secret: str | None = None,
sandbox_client_id: str | None = None,
sandbox_client_secret: str | None = None,
webhook_secret: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
Expand Down Expand Up @@ -399,8 +377,6 @@ def __init__(
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
- `client_id` from `FINCH_CLIENT_ID`
- `client_secret` from `FINCH_CLIENT_SECRET`
- `sandbox_client_id` from `FINCH_SANDBOX_CLIENT_ID`
- `sandbox_client_secret` from `FINCH_SANDBOX_CLIENT_SECRET`
- `webhook_secret` from `FINCH_WEBHOOK_SECRET`
"""
self.access_token = access_token
Expand All @@ -413,14 +389,6 @@ def __init__(
client_secret = os.environ.get("FINCH_CLIENT_SECRET")
self.client_secret = client_secret

if sandbox_client_id is None:
sandbox_client_id = os.environ.get("FINCH_SANDBOX_CLIENT_ID")
self.sandbox_client_id = sandbox_client_id

if sandbox_client_secret is None:
sandbox_client_secret = os.environ.get("FINCH_SANDBOX_CLIENT_SECRET")
self.sandbox_client_secret = sandbox_client_secret

if webhook_secret is None:
webhook_secret = os.environ.get("FINCH_WEBHOOK_SECRET")
self.webhook_secret = webhook_secret
Expand Down Expand Up @@ -479,11 +447,11 @@ def _bearer_auth(self) -> dict[str, str]:

@property
def _basic_auth(self) -> dict[str, str]:
if self.sandbox_client_id is None:
if self.client_id is None:
return {}
if self.sandbox_client_secret is None:
if self.client_secret is None:
return {}
credentials = f"{self.sandbox_client_id}:{self.sandbox_client_secret}".encode("ascii")
credentials = f"{self.client_id}:{self.client_secret}".encode("ascii")
header = f"Basic {base64.b64encode(credentials).decode('ascii')}"
return {"Authorization": header}

Expand All @@ -504,13 +472,13 @@ def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
if isinstance(custom_headers.get("Authorization"), Omit):
return

if self.sandbox_client_id and self.sandbox_client_secret and headers.get("Authorization"):
if self.client_id and self.client_secret and headers.get("Authorization"):
return
if isinstance(custom_headers.get("Authorization"), Omit):
return

raise TypeError(
'"Could not resolve authentication method. Expected either access_token, sandbox_client_id or sandbox_client_secret to be set. Or for one of the `Authorization` or `Authorization` headers to be explicitly omitted"'
'"Could not resolve authentication method. Expected either access_token, client_id or client_secret to be set. Or for one of the `Authorization` or `Authorization` headers to be explicitly omitted"'
)

def copy(
Expand All @@ -519,8 +487,6 @@ def copy(
access_token: str | None = None,
client_id: str | None = None,
client_secret: str | None = None,
sandbox_client_id: str | None = None,
sandbox_client_secret: str | None = None,
webhook_secret: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -576,8 +542,6 @@ def copy(
access_token=access_token or self.access_token,
client_id=client_id or self.client_id,
client_secret=client_secret or self.client_secret,
sandbox_client_id=sandbox_client_id or self.sandbox_client_id,
sandbox_client_secret=sandbox_client_secret or self.sandbox_client_secret,
webhook_secret=webhook_secret or self.webhook_secret,
base_url=base_url or self.base_url,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
Expand Down
16 changes: 0 additions & 16 deletions tests/api_resources/connect/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
class TestSessions:
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
def test_method_new(self, client: Finch) -> None:
session = client.connect.sessions.new(
Expand All @@ -30,7 +29,6 @@ def test_method_new(self, client: Finch) -> None:
)
assert_matches_type(SessionNewResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
def test_method_new_with_all_params(self, client: Finch) -> None:
session = client.connect.sessions.new(
Expand All @@ -49,7 +47,6 @@ def test_method_new_with_all_params(self, client: Finch) -> None:
)
assert_matches_type(SessionNewResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
def test_raw_response_new(self, client: Finch) -> None:
response = client.connect.sessions.with_raw_response.new(
Expand All @@ -63,7 +60,6 @@ def test_raw_response_new(self, client: Finch) -> None:
session = response.parse()
assert_matches_type(SessionNewResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
def test_streaming_response_new(self, client: Finch) -> None:
with client.connect.sessions.with_streaming_response.new(
Expand All @@ -79,15 +75,13 @@ def test_streaming_response_new(self, client: Finch) -> None:

assert cast(Any, response.is_closed) is True

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
def test_method_reauthenticate(self, client: Finch) -> None:
session = client.connect.sessions.reauthenticate(
connection_id="connection_id",
)
assert_matches_type(SessionReauthenticateResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
def test_method_reauthenticate_with_all_params(self, client: Finch) -> None:
session = client.connect.sessions.reauthenticate(
Expand All @@ -98,7 +92,6 @@ def test_method_reauthenticate_with_all_params(self, client: Finch) -> None:
)
assert_matches_type(SessionReauthenticateResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
def test_raw_response_reauthenticate(self, client: Finch) -> None:
response = client.connect.sessions.with_raw_response.reauthenticate(
Expand All @@ -110,7 +103,6 @@ def test_raw_response_reauthenticate(self, client: Finch) -> None:
session = response.parse()
assert_matches_type(SessionReauthenticateResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
def test_streaming_response_reauthenticate(self, client: Finch) -> None:
with client.connect.sessions.with_streaming_response.reauthenticate(
Expand All @@ -128,7 +120,6 @@ def test_streaming_response_reauthenticate(self, client: Finch) -> None:
class TestAsyncSessions:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
async def test_method_new(self, async_client: AsyncFinch) -> None:
session = await async_client.connect.sessions.new(
Expand All @@ -138,7 +129,6 @@ async def test_method_new(self, async_client: AsyncFinch) -> None:
)
assert_matches_type(SessionNewResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
async def test_method_new_with_all_params(self, async_client: AsyncFinch) -> None:
session = await async_client.connect.sessions.new(
Expand All @@ -157,7 +147,6 @@ async def test_method_new_with_all_params(self, async_client: AsyncFinch) -> Non
)
assert_matches_type(SessionNewResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
async def test_raw_response_new(self, async_client: AsyncFinch) -> None:
response = await async_client.connect.sessions.with_raw_response.new(
Expand All @@ -171,7 +160,6 @@ async def test_raw_response_new(self, async_client: AsyncFinch) -> None:
session = response.parse()
assert_matches_type(SessionNewResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
async def test_streaming_response_new(self, async_client: AsyncFinch) -> None:
async with async_client.connect.sessions.with_streaming_response.new(
Expand All @@ -187,15 +175,13 @@ async def test_streaming_response_new(self, async_client: AsyncFinch) -> None:

assert cast(Any, response.is_closed) is True

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
async def test_method_reauthenticate(self, async_client: AsyncFinch) -> None:
session = await async_client.connect.sessions.reauthenticate(
connection_id="connection_id",
)
assert_matches_type(SessionReauthenticateResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
async def test_method_reauthenticate_with_all_params(self, async_client: AsyncFinch) -> None:
session = await async_client.connect.sessions.reauthenticate(
Expand All @@ -206,7 +192,6 @@ async def test_method_reauthenticate_with_all_params(self, async_client: AsyncFi
)
assert_matches_type(SessionReauthenticateResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
async def test_raw_response_reauthenticate(self, async_client: AsyncFinch) -> None:
response = await async_client.connect.sessions.with_raw_response.reauthenticate(
Expand All @@ -218,7 +203,6 @@ async def test_raw_response_reauthenticate(self, async_client: AsyncFinch) -> No
session = response.parse()
assert_matches_type(SessionReauthenticateResponse, session, path=["response"])

@pytest.mark.skip(reason="authentication setup doesn't currently work with the mock server")
@parametrize
async def test_streaming_response_reauthenticate(self, async_client: AsyncFinch) -> None:
async with async_client.connect.sessions.with_streaming_response.reauthenticate(
Expand Down
8 changes: 0 additions & 8 deletions tests/api_resources/sandbox/connections/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
class TestAccounts:
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])

@pytest.mark.skip(reason="Auth isn't setup correctly in this test")
@parametrize
def test_method_create(self, client: Finch) -> None:
account = client.sandbox.connections.accounts.create(
Expand All @@ -29,7 +28,6 @@ def test_method_create(self, client: Finch) -> None:
)
assert_matches_type(AccountCreateResponse, account, path=["response"])

@pytest.mark.skip(reason="Auth isn't setup correctly in this test")
@parametrize
def test_method_create_with_all_params(self, client: Finch) -> None:
account = client.sandbox.connections.accounts.create(
Expand All @@ -40,7 +38,6 @@ def test_method_create_with_all_params(self, client: Finch) -> None:
)
assert_matches_type(AccountCreateResponse, account, path=["response"])

@pytest.mark.skip(reason="Auth isn't setup correctly in this test")
@parametrize
def test_raw_response_create(self, client: Finch) -> None:
response = client.sandbox.connections.accounts.with_raw_response.create(
Expand All @@ -53,7 +50,6 @@ def test_raw_response_create(self, client: Finch) -> None:
account = response.parse()
assert_matches_type(AccountCreateResponse, account, path=["response"])

@pytest.mark.skip(reason="Auth isn't setup correctly in this test")
@parametrize
def test_streaming_response_create(self, client: Finch) -> None:
with client.sandbox.connections.accounts.with_streaming_response.create(
Expand Down Expand Up @@ -104,7 +100,6 @@ def test_streaming_response_update(self, client: Finch) -> None:
class TestAsyncAccounts:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])

@pytest.mark.skip(reason="Auth isn't setup correctly in this test")
@parametrize
async def test_method_create(self, async_client: AsyncFinch) -> None:
account = await async_client.sandbox.connections.accounts.create(
Expand All @@ -113,7 +108,6 @@ async def test_method_create(self, async_client: AsyncFinch) -> None:
)
assert_matches_type(AccountCreateResponse, account, path=["response"])

@pytest.mark.skip(reason="Auth isn't setup correctly in this test")
@parametrize
async def test_method_create_with_all_params(self, async_client: AsyncFinch) -> None:
account = await async_client.sandbox.connections.accounts.create(
Expand All @@ -124,7 +118,6 @@ async def test_method_create_with_all_params(self, async_client: AsyncFinch) ->
)
assert_matches_type(AccountCreateResponse, account, path=["response"])

@pytest.mark.skip(reason="Auth isn't setup correctly in this test")
@parametrize
async def test_raw_response_create(self, async_client: AsyncFinch) -> None:
response = await async_client.sandbox.connections.accounts.with_raw_response.create(
Expand All @@ -137,7 +130,6 @@ async def test_raw_response_create(self, async_client: AsyncFinch) -> None:
account = response.parse()
assert_matches_type(AccountCreateResponse, account, path=["response"])

@pytest.mark.skip(reason="Auth isn't setup correctly in this test")
@parametrize
async def test_streaming_response_create(self, async_client: AsyncFinch) -> None:
async with async_client.sandbox.connections.accounts.with_streaming_response.create(
Expand Down
Loading