Skip to content

Commit 3366baa

Browse files
author
artur.shiriev
committed
review fixes
1 parent 0d007c4 commit 3366baa

File tree

7 files changed

+49
-49
lines changed

7 files changed

+49
-49
lines changed

tests/bootstrappers/test_fastapi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import typing
22
from unittest.mock import MagicMock
33

4+
from fastapi import status
45
from fastapi.testclient import TestClient
5-
from litestar import status_codes
66

77
from microbootstrap.bootstrappers.fastapi import FastApiBootstrapper
88
from microbootstrap.config.fastapi import FastApiConfig
@@ -22,7 +22,7 @@ def test_fastapi_configure_instrument() -> None:
2222
)
2323

2424
response: typing.Final = TestClient(app=application).get(test_metrics_path)
25-
assert response.status_code == status_codes.HTTP_200_OK
25+
assert response.status_code == status.HTTP_200_OK
2626

2727

2828
def test_fastapi_configure_instruments() -> None:
@@ -36,7 +36,7 @@ def test_fastapi_configure_instruments() -> None:
3636
)
3737

3838
response: typing.Final = TestClient(app=application).get(test_metrics_path)
39-
assert response.status_code == status_codes.HTTP_200_OK
39+
assert response.status_code == status.HTTP_200_OK
4040

4141

4242
def test_fastapi_configure_application() -> None:

tests/instruments/test_health_checks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import fastapi
44
import litestar
5-
from fastapi.testclient import TestClient
5+
from fastapi.testclient import TestClient as FastAPITestClient
66
from litestar import status_codes
7-
from litestar.testing import AsyncTestClient
7+
from litestar.testing import TestClient as LitestarTestClient
88

99
from microbootstrap.bootstrappers.fastapi import FastApiHealthChecksInstrument
1010
from microbootstrap.bootstrappers.litestar import LitestarHealthChecksInstrument
@@ -40,7 +40,7 @@ def test_health_checks_teardown(
4040
assert health_checks_instrument.teardown() is None # type: ignore[func-returns-value]
4141

4242

43-
async def test_litestar_health_checks_bootstrap() -> None:
43+
def test_litestar_health_checks_bootstrap() -> None:
4444
test_health_checks_path: typing.Final = "/test-path/"
4545
heatlh_checks_config: typing.Final = HealthChecksConfig(health_checks_path=test_health_checks_path)
4646
health_checks_instrument: typing.Final = LitestarHealthChecksInstrument(heatlh_checks_config)
@@ -50,8 +50,8 @@ async def test_litestar_health_checks_bootstrap() -> None:
5050
**health_checks_instrument.bootstrap_before(),
5151
)
5252

53-
async with AsyncTestClient(app=litestar_application) as async_client:
54-
response = await async_client.get(heatlh_checks_config.health_checks_path)
53+
with LitestarTestClient(app=litestar_application) as async_client:
54+
response = async_client.get(heatlh_checks_config.health_checks_path)
5555
assert response.status_code == status_codes.HTTP_200_OK
5656

5757

@@ -66,5 +66,5 @@ def test_fastapi_health_checks_bootstrap() -> None:
6666
)
6767
fastapi_application = health_checks_instrument.bootstrap_after(fastapi_application)
6868

69-
response = TestClient(app=fastapi_application).get(heatlh_checks_config.health_checks_path)
69+
response = FastAPITestClient(app=fastapi_application).get(heatlh_checks_config.health_checks_path)
7070
assert response.status_code == status_codes.HTTP_200_OK

tests/instruments/test_logging.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import fastapi
66
import litestar
7-
from fastapi.testclient import TestClient
8-
from litestar.testing import AsyncTestClient
7+
from fastapi.testclient import TestClient as FastAPITestClient
8+
from litestar.testing import TestClient as LitestarTestClient
99
from opentelemetry import trace
1010
from opentelemetry.sdk.trace import TracerProvider
1111
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
@@ -51,7 +51,7 @@ def test_litestar_logging_bootstrap(minimal_logging_config: LoggingConfig) -> No
5151
assert len(bootsrap_result["middleware"]) == 1
5252

5353

54-
async def test_litestar_logging_bootstrap_working(minimal_logging_config: LoggingConfig) -> None:
54+
def test_litestar_logging_bootstrap_working(minimal_logging_config: LoggingConfig) -> None:
5555
logging_instrument: typing.Final = LitestarLoggingInstrument(minimal_logging_config)
5656

5757
@litestar.get("/test-handler")
@@ -64,12 +64,12 @@ async def error_handler() -> str:
6464
**logging_instrument.bootstrap_before(),
6565
)
6666

67-
async with AsyncTestClient(app=litestar_application) as async_client:
68-
await async_client.get("/test-handler?test-query=1")
69-
await async_client.get("/test-handler")
67+
with LitestarTestClient(app=litestar_application) as test_client:
68+
test_client.get("/test-handler?test-query=1")
69+
test_client.get("/test-handler")
7070

7171

72-
async def test_litestar_logging_bootstrap_tracer_injection(minimal_logging_config: LoggingConfig) -> None:
72+
def test_litestar_logging_bootstrap_tracer_injection(minimal_logging_config: LoggingConfig) -> None:
7373
trace.set_tracer_provider(TracerProvider())
7474
tracer = trace.get_tracer(__name__)
7575
span_processor = SimpleSpanProcessor(ConsoleSpanExporter())
@@ -89,8 +89,8 @@ async def test_handler() -> str:
8989
# Do some fake work inside the span
9090
span.set_attribute("example_attribute", "value")
9191
span.add_event("example_event", {"event_attr": 1})
92-
async with AsyncTestClient(app=litestar_application) as async_client:
93-
await async_client.get("/test-handler")
92+
with LitestarTestClient(app=litestar_application) as test_client:
93+
test_client.get("/test-handler")
9494

9595

9696
def test_memory_logger_factory_info() -> None:
@@ -145,6 +145,6 @@ async def test_handler() -> str:
145145
logging_instrument.bootstrap()
146146
logging_instrument.bootstrap_after(fastapi_application)
147147

148-
with TestClient(app=fastapi_application) as test_client:
148+
with FastAPITestClient(app=fastapi_application) as test_client:
149149
test_client.get("/test-handler?test-query=1")
150150
test_client.get("/test-handler")

tests/instruments/test_opentelemetry.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import fastapi
66
import litestar
77
import pytest
8-
from fastapi.testclient import TestClient
8+
from fastapi.testclient import TestClient as FastAPITestClient
99
from litestar.middleware.base import DefineMiddleware
10-
from litestar.testing import AsyncTestClient
10+
from litestar.testing import TestClient as LitestarTestClient
1111

1212
from microbootstrap import OpentelemetryConfig
1313
from microbootstrap.bootstrappers.fastapi import FastApiOpentelemetryInstrument
@@ -70,7 +70,7 @@ def test_litestar_opentelemetry_teardown(
7070
opentelemetry_instrument.teardown()
7171

7272

73-
async def test_litestar_opentelemetry_bootstrap_working(
73+
def test_litestar_opentelemetry_bootstrap_working(
7474
minimal_opentelemetry_config: OpentelemetryConfig,
7575
async_mock: AsyncMock,
7676
) -> None:
@@ -91,10 +91,10 @@ async def test_handler() -> None:
9191
route_handlers=[test_handler],
9292
**opentelemetry_bootstrap_result,
9393
)
94-
async with AsyncTestClient(app=litestar_application) as async_client:
95-
# Silencing error, cause we are mocking middleware call, so ASGI scope remains unchanged.
94+
with LitestarTestClient(app=litestar_application) as test_client:
95+
# Silencing error, because we are mocking middleware call, so ASGI scope remains unchanged.
9696
with contextlib.suppress(AssertionError):
97-
await async_client.get("/test-handler")
97+
test_client.get("/test-handler")
9898
assert async_mock.called
9999

100100

@@ -112,5 +112,5 @@ async def test_handler() -> None:
112112
return None
113113

114114
with patch("opentelemetry.trace.use_span") as mock_capture_event:
115-
TestClient(app=fastapi_application).get("/test-handler")
115+
FastAPITestClient(app=fastapi_application).get("/test-handler")
116116
assert mock_capture_event.called

tests/instruments/test_prometheus.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import fastapi
44
import litestar
5-
from fastapi.testclient import TestClient
5+
from fastapi.testclient import TestClient as FastAPITestClient
66
from litestar import status_codes
77
from litestar.middleware.base import DefineMiddleware
8-
from litestar.testing import AsyncTestClient
8+
from litestar.testing import TestClient as LitestarTestClient
99

1010
from microbootstrap import FastApiPrometheusConfig, LitestarPrometheusConfig
1111
from microbootstrap.bootstrappers.fastapi import FastApiPrometheusInstrument
@@ -56,7 +56,7 @@ def test_litestar_prometheus_bootstrap(minimal_litestar_prometheus_config: Lites
5656
assert isinstance(prometheus_bootstrap_result["middleware"][0], DefineMiddleware)
5757

5858

59-
async def test_litestar_prometheus_bootstrap_working(
59+
def test_litestar_prometheus_bootstrap_working(
6060
minimal_litestar_prometheus_config: LitestarPrometheusConfig,
6161
) -> None:
6262
minimal_litestar_prometheus_config.prometheus_metrics_path = "/custom-metrics-path"
@@ -67,8 +67,8 @@ async def test_litestar_prometheus_bootstrap_working(
6767
**prometheus_instrument.bootstrap_before(),
6868
)
6969

70-
async with AsyncTestClient(app=litestar_application) as async_client:
71-
response: typing.Final = await async_client.get(minimal_litestar_prometheus_config.prometheus_metrics_path)
70+
with LitestarTestClient(app=litestar_application) as test_client:
71+
response: typing.Final = test_client.get(minimal_litestar_prometheus_config.prometheus_metrics_path)
7272
assert response.status_code == status_codes.HTTP_200_OK
7373
assert response.text
7474

@@ -80,7 +80,7 @@ def test_fastapi_prometheus_bootstrap_working(minimal_fastapi_prometheus_config:
8080
fastapi_application = fastapi.FastAPI()
8181
fastapi_application = prometheus_instrument.bootstrap_after(fastapi_application)
8282

83-
response: typing.Final = TestClient(app=fastapi_application).get(
83+
response: typing.Final = FastAPITestClient(app=fastapi_application).get(
8484
minimal_fastapi_prometheus_config.prometheus_metrics_path
8585
)
8686
assert response.status_code == status_codes.HTTP_200_OK

tests/instruments/test_sentry.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import fastapi
66
import litestar
7-
from fastapi.testclient import TestClient
8-
from litestar.testing import AsyncTestClient
7+
from fastapi.testclient import TestClient as FastAPITestClient
8+
from litestar.testing import TestClient as LitestarTestClient
99

1010
from microbootstrap import SentryConfig
1111
from microbootstrap.bootstrappers.fastapi import FastApiSentryInstrument
@@ -45,7 +45,7 @@ def test_litestar_sentry_bootstrap(minimal_sentry_config: SentryConfig) -> None:
4545
assert sentry_instrument.bootstrap_before() == {}
4646

4747

48-
async def test_litestar_sentry_bootstrap_catch_exception(
48+
def test_litestar_sentry_bootstrap_catch_exception(
4949
minimal_sentry_config: SentryConfig,
5050
) -> None:
5151
sentry_instrument: typing.Final = LitestarSentryInstrument(minimal_sentry_config)
@@ -57,8 +57,8 @@ async def error_handler() -> None:
5757
sentry_instrument.bootstrap()
5858
litestar_application: typing.Final = litestar.Litestar(route_handlers=[error_handler])
5959
with patch("sentry_sdk.Scope.capture_event") as mock_capture_event:
60-
async with AsyncTestClient(app=litestar_application) as async_client:
61-
await async_client.get("/test-error-handler")
60+
with LitestarTestClient(app=litestar_application) as test_client:
61+
test_client.get("/test-error-handler")
6262

6363
assert mock_capture_event.called
6464

@@ -82,5 +82,5 @@ async def error_handler() -> None:
8282
sentry_instrument.bootstrap()
8383
with patch("sentry_sdk.Scope.capture_event") as mock_capture_event:
8484
with contextlib.suppress(ValueError):
85-
TestClient(app=app).get("/test-error-handler")
85+
FastAPITestClient(app=app).get("/test-error-handler")
8686
assert mock_capture_event.called

tests/instruments/test_swagger.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import fastapi
44
import litestar
5-
from fastapi.testclient import TestClient
5+
from fastapi.testclient import TestClient as FastAPITestClient
66
from litestar import openapi, status_codes
77
from litestar.openapi import spec as litestar_openapi
88
from litestar.openapi.plugins import ScalarRenderPlugin
99
from litestar.static_files import StaticFilesConfig
10-
from litestar.testing import AsyncTestClient
10+
from litestar.testing import TestClient as LitestarTestClient
1111

1212
from microbootstrap.bootstrappers.fastapi import FastApiSwaggerInstrument
1313
from microbootstrap.bootstrappers.litestar import LitestarSwaggerInstrument
@@ -97,7 +97,7 @@ def test_litestar_swagger_bootstrap_offline_docs(minimal_swagger_config: Swagger
9797
assert isinstance(bootstrap_result["static_files_config"][0], StaticFilesConfig)
9898

9999

100-
async def test_litestar_swagger_bootstrap_working_online_docs(
100+
def test_litestar_swagger_bootstrap_working_online_docs(
101101
minimal_swagger_config: SwaggerConfig,
102102
) -> None:
103103
minimal_swagger_config.swagger_path = "/my-docs-path"
@@ -108,12 +108,12 @@ async def test_litestar_swagger_bootstrap_working_online_docs(
108108
**swagger_instrument.bootstrap_before(),
109109
)
110110

111-
async with AsyncTestClient(app=litestar_application) as async_client:
112-
response: typing.Final = await async_client.get(minimal_swagger_config.swagger_path)
111+
with LitestarTestClient(app=litestar_application) as test_client:
112+
response: typing.Final = test_client.get(minimal_swagger_config.swagger_path)
113113
assert response.status_code == status_codes.HTTP_200_OK
114114

115115

116-
async def test_litestar_swagger_bootstrap_working_offline_docs(
116+
def test_litestar_swagger_bootstrap_working_offline_docs(
117117
minimal_swagger_config: SwaggerConfig,
118118
) -> None:
119119
minimal_swagger_config.service_static_path = "/my-static-path"
@@ -125,10 +125,10 @@ async def test_litestar_swagger_bootstrap_working_offline_docs(
125125
**swagger_instrument.bootstrap_before(),
126126
)
127127

128-
async with AsyncTestClient(app=litestar_application) as async_client:
129-
response = await async_client.get(minimal_swagger_config.swagger_path)
128+
with LitestarTestClient(app=litestar_application) as test_client:
129+
response = test_client.get(minimal_swagger_config.swagger_path)
130130
assert response.status_code == status_codes.HTTP_200_OK
131-
response = await async_client.get(f"{minimal_swagger_config.service_static_path}/swagger-ui.css")
131+
response = test_client.get(f"{minimal_swagger_config.service_static_path}/swagger-ui.css")
132132
assert response.status_code == status_codes.HTTP_200_OK
133133

134134

@@ -152,7 +152,7 @@ def test_fastapi_swagger_bootstrap_working_online_docs(
152152
**swagger_instrument.bootstrap_before(),
153153
)
154154

155-
response: typing.Final = TestClient(app=fastapi_application).get(minimal_swagger_config.swagger_path)
155+
response: typing.Final = FastAPITestClient(app=fastapi_application).get(minimal_swagger_config.swagger_path)
156156
assert response.status_code == status_codes.HTTP_200_OK
157157

158158

@@ -167,7 +167,7 @@ def test_fastapi_swagger_bootstrap_working_offline_docs(
167167
)
168168
swagger_instrument.bootstrap_after(fastapi_application)
169169

170-
with TestClient(app=fastapi_application) as test_client:
170+
with FastAPITestClient(app=fastapi_application) as test_client:
171171
response = test_client.get(minimal_swagger_config.swagger_path)
172172
assert response.status_code == status_codes.HTTP_200_OK
173173
response = test_client.get(f"{minimal_swagger_config.service_static_path}/swagger-ui.css")

0 commit comments

Comments
 (0)