Skip to content

Commit 570bf26

Browse files
author
Andrei Neagu
committed
fixed transport for asynclcient
1 parent 4e19157 commit 570bf26

File tree

11 files changed

+19
-16
lines changed

11 files changed

+19
-16
lines changed

packages/service-library/tests/fastapi/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111
from fastapi import APIRouter, FastAPI
1212
from fastapi.params import Query
13-
from httpx import AsyncClient
13+
from httpx import ASGITransport, AsyncClient
1414
from pydantic.types import PositiveFloat
1515

1616

@@ -35,7 +35,9 @@ def _get_data(x: PositiveFloat, y: int = Query(..., gt=3, lt=4)):
3535

3636
@pytest.fixture
3737
async def client(app: FastAPI) -> AsyncIterator[AsyncClient]:
38-
async with AsyncClient(app=app, base_url="http://test") as client:
38+
async with AsyncClient(
39+
transport=ASGITransport(app=app), base_url="http://test"
40+
) as client:
3941
yield client
4042

4143

packages/service-library/tests/fastapi/long_running_tasks/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import pytest
99
from fastapi import FastAPI
10-
from httpx import AsyncClient
10+
from httpx import ASGITransport, AsyncClient
1111
from servicelib.fastapi import long_running_tasks
1212

1313

@@ -22,7 +22,7 @@ async def bg_task_app(router_prefix: str) -> FastAPI:
2222
@pytest.fixture
2323
async def async_client(bg_task_app: FastAPI) -> AsyncIterable[AsyncClient]:
2424
async with AsyncClient(
25-
app=bg_task_app,
25+
transport=ASGITransport(app=bg_task_app),
2626
base_url="http://backgroud.testserver.io",
2727
headers={"Content-Type": "application/json"},
2828
) as client:

services/datcore-adapter/tests/unit/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ async def initialized_app(
102102
@pytest.fixture
103103
async def async_client(initialized_app: FastAPI) -> AsyncIterator[httpx.AsyncClient]:
104104
async with httpx.AsyncClient(
105-
app=initialized_app,
105+
transport=httpx.ASGITransport(app=initialized_app),
106106
base_url="http://datcore-adapter.testserver.io",
107107
headers={"Content-Type": "application/json"},
108108
) as client:

services/dynamic-scheduler/tests/unit/api_rest/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def client(
2929
# - Needed for app to trigger start/stop event handlers
3030
# - Prefer this client instead of fastapi.testclient.TestClient
3131
async with AsyncClient(
32-
app=app,
32+
transport=ASGITransport(app=app),
3333
base_url="http://payments.testserver.io",
3434
headers={"Content-Type": "application/json"},
3535
) as httpx_client:

services/dynamic-sidecar/tests/unit/test_api_rest_containers_long_running_tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from asgi_lifespan import LifespanManager
1919
from fastapi import FastAPI
2020
from fastapi.routing import APIRoute
21-
from httpx import AsyncClient
21+
from httpx import ASGITransport, AsyncClient
2222
from models_library.api_schemas_long_running_tasks.base import (
2323
ProgressMessage,
2424
ProgressPercent,
@@ -186,7 +186,7 @@ async def httpx_async_client(
186186
) -> AsyncIterable[AsyncClient]:
187187
# crete dir here
188188
async with AsyncClient(
189-
app=app,
189+
transport=ASGITransport(app=app),
190190
base_url=f"{backend_url}",
191191
headers={"Content-Type": "application/json"},
192192
) as client:

services/dynamic-sidecar/tests/unit/test_api_rest_prometheus_metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from aiodocker.volumes import DockerVolume
1212
from asgi_lifespan import LifespanManager
1313
from fastapi import FastAPI, status
14-
from httpx import AsyncClient
14+
from httpx import ASGITransport, AsyncClient
1515
from models_library.callbacks_mapping import CallbacksMapping
1616
from models_library.services_creation import CreateServiceMetricsAdditionalParams
1717
from pydantic import AnyHttpUrl, TypeAdapter
@@ -70,7 +70,7 @@ async def httpx_async_client(
7070
cleanup_containers: None,
7171
) -> AsyncIterable[AsyncClient]:
7272
async with AsyncClient(
73-
app=app,
73+
transport=ASGITransport(app=app),
7474
base_url=f"{backend_url}",
7575
headers={"Content-Type": "application/json"},
7676
) as client:

services/dynamic-sidecar/tests/unit/test_api_rest_workflow_service_metrics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from aiodocker.volumes import DockerVolume
1818
from asgi_lifespan import LifespanManager
1919
from fastapi import FastAPI
20-
from httpx import AsyncClient
20+
from httpx import ASGITransport, AsyncClient
2121
from models_library.generated_models.docker_rest_api import ContainerState
2222
from models_library.generated_models.docker_rest_api import Status2 as ContainerStatus
2323
from models_library.rabbitmq_messages import (
@@ -113,7 +113,9 @@ async def httpx_async_client(
113113
) -> AsyncIterable[AsyncClient]:
114114
# crete dir here
115115
async with AsyncClient(
116-
app=app, base_url=f"{backend_url}", headers={"Content-Type": "application/json"}
116+
transport=ASGITransport(app=app),
117+
base_url=f"{backend_url}",
118+
headers={"Content-Type": "application/json"},
117119
) as client:
118120
yield client
119121

services/payments/tests/unit/api/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async def client(app: FastAPI) -> AsyncIterator[httpx.AsyncClient]:
2020
# - Needed for app to trigger start/stop event handlers
2121
# - Prefer this client instead of fastapi.testclient.TestClient
2222
async with httpx.AsyncClient(
23-
app=app,
23+
transport=ASGITransport(app=app),
2424
base_url="http://payments.testserver.io",
2525
headers={"Content-Type": "application/json"},
2626
) as client:

services/payments/tests/unit/api/test_rest_acknowledgements.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ async def client(
7777
external_base_url,
7878
)
7979
async with httpx.AsyncClient(
80-
app=None,
8180
base_url=external_base_url,
8281
headers={"Content-Type": "application/json"},
8382
) as new_client:

services/resource-usage-tracker/tests/unit/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def client(app_settings: ApplicationSettings) -> Iterator[TestClient]:
135135
@pytest.fixture
136136
async def async_client(initialized_app: FastAPI) -> AsyncIterator[httpx.AsyncClient]:
137137
async with httpx.AsyncClient(
138-
app=initialized_app,
138+
transport=httpx.ASGITransport(app=initialized_app),
139139
base_url=f"http://{initialized_app.title}.testserver.io",
140140
headers={"Content-Type": "application/json"},
141141
) as client:

0 commit comments

Comments
 (0)