diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 3553fac..221f477 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -15,7 +15,7 @@ jobs: test: strategy: matrix: - version: ["3.9", "3.10", "3.11", "3.12", "3.13"] + version: ["3.10", "3.11", "3.12", "3.13"] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: diff --git a/pyproject.toml b/pyproject.toml index 66d7c51..d41ac1a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,7 +99,7 @@ exclude = ["migrations"] # Pydantic plugin causes some issues: https://github.com/pydantic/pydantic-settings/issues/403 #plugins = "pydantic.mypy,strawberry.ext.mypy_plugin" plugins = "strawberry.ext.mypy_plugin" -python_version = "3.9" +python_version = "3.10" [[tool.mypy.overrides]] module = [ diff --git a/src/http_app/routes/hello.py b/src/http_app/routes/hello.py index 678b92e..975b4ed 100644 --- a/src/http_app/routes/hello.py +++ b/src/http_app/routes/hello.py @@ -10,4 +10,8 @@ @router.get("/", response_class=HTMLResponse, include_in_schema=True) async def hello(request: Request, jwt_token=Security(decode_jwt)): - return templates.TemplateResponse("hello.html", {"request": request, "token_payload": jwt_token}) + return templates.TemplateResponse( + name="hello.html", + request=request, + context={"token_payload": jwt_token}, + ) diff --git a/tests/common/test_asyncapi.py b/tests/common/test_asyncapi.py index fdb7bc9..90048f9 100644 --- a/tests/common/test_asyncapi.py +++ b/tests/common/test_asyncapi.py @@ -28,7 +28,7 @@ def reset_asyncapi_state(): # Test message models -class TestMessage(BaseModel): +class SomeTestMessage(BaseModel): content: str timestamp: int @@ -103,20 +103,23 @@ def test_register_channel_operation(reset_asyncapi_state): register_channel(address="test/topic", id=channel_id) register_channel_operation( - channel_id=channel_id, operation_type=operation_type, messages=[TestMessage], operation_name="test-operation" + channel_id=channel_id, + operation_type=operation_type, + messages=[SomeTestMessage], + operation_name="test-operation", ) schema = get_schema() assert "test-operation" in schema.operations assert schema.operations["test-operation"].action == operation_type assert schema.operations["test-operation"].channel.ref == f"#/channels/{channel_id}" - assert TestMessage.__name__ in schema.components.schemas + assert SomeTestMessage.__name__ in schema.components.schemas def test_register_channel_operation_invalid_channel(reset_asyncapi_state): """Test channel operation registration with invalid channel""" with pytest.raises(ValueError, match="Channel non-existent does not exist"): - register_channel_operation(channel_id="non-existent", operation_type="receive", messages=[TestMessage]) + register_channel_operation(channel_id="non-existent", operation_type="receive", messages=[SomeTestMessage]) def test_multiple_messages_registration(reset_asyncapi_state): @@ -124,10 +127,12 @@ def test_multiple_messages_registration(reset_asyncapi_state): channel_id = "test-channel" register_channel(address="test/topic", id=channel_id) - register_channel_operation(channel_id=channel_id, operation_type="send", messages=[TestMessage, AnotherTestMessage]) + register_channel_operation( + channel_id=channel_id, operation_type="send", messages=[SomeTestMessage, AnotherTestMessage] + ) schema = get_schema() - assert TestMessage.__name__ in schema.components.schemas + assert SomeTestMessage.__name__ in schema.components.schemas assert AnotherTestMessage.__name__ in schema.components.schemas - assert TestMessage.__name__ in schema.channels[channel_id].messages + assert SomeTestMessage.__name__ in schema.channels[channel_id].messages assert AnotherTestMessage.__name__ in schema.channels[channel_id].messages diff --git a/tests/common/test_tracing.py b/tests/common/test_tracing.py index 91f67d7..4009c81 100644 --- a/tests/common/test_tracing.py +++ b/tests/common/test_tracing.py @@ -43,7 +43,6 @@ def add_nums(a, b): mock_span.set_attribute.assert_any_call("function.result", "5") -@pytest.mark.asyncio async def test_async_function_default_params(mock_tracer): """ Test an asynchronous function with default decorator parameters. @@ -129,7 +128,6 @@ def sync_func(a, b): assert call("function.result") not in mock_span.set_attribute.call_args_list -@pytest.mark.asyncio async def test_disable_result_in_span(mock_tracer): """ Test an asynchronous function with `add_result_to_span` set to False. diff --git a/tests/http_app/routes/ws/test_chat.py b/tests/http_app/routes/ws/test_chat.py index 209a31e..fc3bb76 100644 --- a/tests/http_app/routes/ws/test_chat.py +++ b/tests/http_app/routes/ws/test_chat.py @@ -1,3 +1,5 @@ +from unittest.mock import patch + import pytest from fastapi.testclient import TestClient @@ -15,44 +17,49 @@ def connection_manager(): def test_websocket_connection(test_client): - with test_client.websocket_connect("/ws/chat/1") as websocket: - websocket.send_text("Hello!") - data = websocket.receive_text() + manager = ConnectionManager() + with patch("http_app.routes.ws.chat.manager", manager): + with test_client.websocket_connect("/ws/chat/1") as websocket: + websocket.send_text("Hello!") + data = websocket.receive_text() - assert data == "You wrote: Hello!" - broadcast = websocket.receive_text() - assert broadcast == "Client #1 says: Hello!" + assert data == "You wrote: Hello!" + broadcast = websocket.receive_text() + assert broadcast == "Client #1 says: Hello!" def test_multiple_clients(test_client): - with test_client.websocket_connect("/ws/chat/1") as websocket1: - with test_client.websocket_connect("/ws/chat/2") as websocket2: - # Client 1 sends message - websocket1.send_text("Hello from client 1") + manager = ConnectionManager() + with patch("http_app.routes.ws.chat.manager", manager): + with test_client.websocket_connect("/ws/chat/1") as websocket1: + with test_client.websocket_connect("/ws/chat/2") as websocket2: + # Client 1 sends message + websocket1.send_text("Hello from client 1") - # Client 1 receives personal message - data1 = websocket1.receive_text() - assert data1 == "You wrote: Hello from client 1" + # Client 1 receives personal message + data1 = websocket1.receive_text() + assert data1 == "You wrote: Hello from client 1" - # Both clients receive broadcast - broadcast1 = websocket1.receive_text() - broadcast2 = websocket2.receive_text() - assert broadcast1 == "Client #1 says: Hello from client 1" - assert broadcast2 == "Client #1 says: Hello from client 1" + # Both clients receive broadcast + broadcast1 = websocket1.receive_text() + broadcast2 = websocket2.receive_text() + assert broadcast1 == "Client #1 says: Hello from client 1" + assert broadcast2 == "Client #1 says: Hello from client 1" def test_client_disconnect(test_client): - with test_client.websocket_connect("/ws/chat/1") as websocket1: - with test_client.websocket_connect("/ws/chat/2") as websocket2: - # Close first client - websocket1.close() + manager = ConnectionManager() + with patch("http_app.routes.ws.chat.manager", manager): + with test_client.websocket_connect("/ws/chat/1") as websocket1: + with test_client.websocket_connect("/ws/chat/2") as websocket2: + # Close first client + websocket1.close() - # Second client should receive disconnect message - disconnect_message = websocket2.receive_text() - assert disconnect_message == "Client #1 left the chat" + # Second client should receive disconnect message + disconnect_message = websocket2.receive_text() + assert disconnect_message == "Client #1 left the chat" -@pytest.mark.asyncio async def test_connection_manager(): manager = ConnectionManager()