Skip to content

Commit 50d4910

Browse files
committed
wip: dependency injection for httpx
1 parent 2fa8a82 commit 50d4910

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ remove_pytest_asyncio_from_sync:
3737
sed -i 's/@pytest.mark.asyncio//g' tests/_sync/test_client.py
3838
sed -i 's/_async/_sync/g' tests/_sync/test_client.py
3939
sed -i 's/Async/Sync/g' tests/_sync/test_client.py
40+
sed -i 's/Async/Sync/g' postgrest/_sync/request_builder.py
4041

4142
sleep:
4243
sleep 2

postgrest/_async/client.py

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(
3030
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
3131
verify: bool = True,
3232
proxy: Optional[str] = None,
33+
client: Union[AsyncClient, None] = None,
3334
) -> None:
3435
BasePostgrestClient.__init__(
3536
self,
@@ -39,6 +40,7 @@ def __init__(
3940
timeout=timeout,
4041
verify=verify,
4142
proxy=proxy,
43+
client=client,
4244
)
4345
self.session = cast(AsyncClient, self.session)
4446

@@ -49,7 +51,11 @@ def create_session(
4951
timeout: Union[int, float, Timeout],
5052
verify: bool = True,
5153
proxy: Optional[str] = None,
54+
client: Union[AsyncClient, None] = None,
5255
) -> AsyncClient:
56+
if client is not None:
57+
return client
58+
5359
return AsyncClient(
5460
base_url=base_url,
5561
headers=headers,

postgrest/_sync/client.py

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(
3030
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
3131
verify: bool = True,
3232
proxy: Optional[str] = None,
33+
client: Union[SyncClient, None] = None,
3334
) -> None:
3435
BasePostgrestClient.__init__(
3536
self,
@@ -39,6 +40,7 @@ def __init__(
3940
timeout=timeout,
4041
verify=verify,
4142
proxy=proxy,
43+
client=client,
4244
)
4345
self.session = cast(SyncClient, self.session)
4446

@@ -49,7 +51,11 @@ def create_session(
4951
timeout: Union[int, float, Timeout],
5052
verify: bool = True,
5153
proxy: Optional[str] = None,
54+
client: Union[SyncClient, None] = None,
5255
) -> SyncClient:
56+
if client is not None:
57+
return client
58+
5359
return SyncClient(
5460
base_url=base_url,
5561
headers=headers,

postgrest/base_client.py

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def create_session(
4545
timeout: Union[int, float, Timeout],
4646
verify: bool = True,
4747
proxy: Optional[str] = None,
48+
client: Union[SyncClient, AsyncClient, None] = None,
4849
) -> Union[SyncClient, AsyncClient]:
4950
raise NotImplementedError()
5051

0 commit comments

Comments
 (0)