refactor: rename request parameter to proto_request in gRPC test methods for improved clarity.
This commit is contained in:
@@ -719,7 +719,7 @@ class TestAnnotationInvalidIds:
|
||||
"""Tests for invalid ID handling across annotation RPCs."""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("method_name", "request"),
|
||||
("method_name", "proto_request"),
|
||||
_INVALID_ID_TEST_CASES,
|
||||
ids=[
|
||||
"add_annotation",
|
||||
@@ -734,14 +734,14 @@ class TestAnnotationInvalidIds:
|
||||
mock_annotations_repo: AsyncMock,
|
||||
mock_grpc_context: MagicMock,
|
||||
method_name: str,
|
||||
request: object,
|
||||
proto_request: object,
|
||||
) -> None:
|
||||
"""Annotation RPCs should abort on invalid IDs."""
|
||||
servicer = MockServicerHost(mock_annotations_repo)
|
||||
method = getattr(servicer, method_name)
|
||||
|
||||
with pytest.raises(AssertionError, match="Unreachable"):
|
||||
await method(request, mock_grpc_context)
|
||||
await method(proto_request, mock_grpc_context)
|
||||
|
||||
mock_grpc_context.abort.assert_called_once()
|
||||
|
||||
|
||||
@@ -537,7 +537,7 @@ class TestEntityNotFound:
|
||||
return MockServicerHost(mock_entities_repo, mock_meetings_repo)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("method_name", "request"),
|
||||
("method_name", "proto_request"),
|
||||
[
|
||||
pytest.param(
|
||||
"UpdateEntity",
|
||||
@@ -564,14 +564,14 @@ class TestEntityNotFound:
|
||||
mock_entities_repo: AsyncMock,
|
||||
mock_grpc_context: MagicMock,
|
||||
method_name: str,
|
||||
request: object,
|
||||
proto_request: object,
|
||||
) -> None:
|
||||
"""Entity operations abort when entity does not exist."""
|
||||
mock_entities_repo.get.return_value = None
|
||||
|
||||
method = getattr(servicer, method_name)
|
||||
with pytest.raises(AssertionError, match="Unreachable"):
|
||||
await method(request, mock_grpc_context)
|
||||
await method(proto_request, mock_grpc_context)
|
||||
|
||||
mock_grpc_context.abort.assert_called_once()
|
||||
|
||||
|
||||
@@ -469,7 +469,7 @@ class TestMeetingNotFound:
|
||||
meetings_repo.delete.return_value = False
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("method_name", "request", "configure"),
|
||||
("method_name", "proto_request", "configure"),
|
||||
[
|
||||
pytest.param(
|
||||
"StopMeeting",
|
||||
@@ -497,7 +497,7 @@ class TestMeetingNotFound:
|
||||
meeting_mixin_meetings_repo: AsyncMock,
|
||||
mock_grpc_context: MagicMock,
|
||||
method_name: str,
|
||||
request: object,
|
||||
proto_request: object,
|
||||
configure: Callable[[AsyncMock], None],
|
||||
) -> None:
|
||||
"""Meeting operations abort with NOT_FOUND for missing meetings."""
|
||||
@@ -505,7 +505,7 @@ class TestMeetingNotFound:
|
||||
|
||||
method = getattr(meeting_mixin_servicer, method_name)
|
||||
with pytest.raises(AssertionError, match="Unreachable"):
|
||||
await method(request, mock_grpc_context)
|
||||
await method(proto_request, mock_grpc_context)
|
||||
|
||||
mock_grpc_context.abort.assert_called_once()
|
||||
|
||||
@@ -832,7 +832,7 @@ class TestInvalidMeetingIds:
|
||||
"""Tests for invalid meeting id handling across operations."""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("method_name", "request"),
|
||||
("method_name", "proto_request"),
|
||||
[
|
||||
pytest.param(
|
||||
"StopMeeting",
|
||||
@@ -856,11 +856,11 @@ class TestInvalidMeetingIds:
|
||||
meeting_mixin_servicer: MeetingServicerProtocol,
|
||||
mock_grpc_context: MagicMock,
|
||||
method_name: str,
|
||||
request: object,
|
||||
proto_request: object,
|
||||
) -> None:
|
||||
with pytest.raises(AssertionError, match="Unreachable"):
|
||||
method = getattr(meeting_mixin_servicer, method_name)
|
||||
await method(request, mock_grpc_context)
|
||||
await method(proto_request, mock_grpc_context)
|
||||
|
||||
mock_grpc_context.abort.assert_called_once()
|
||||
|
||||
|
||||
@@ -486,7 +486,7 @@ class TestOidcProviderNotFound:
|
||||
mock_service.registry.remove_provider = MagicMock(return_value=False)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("method_name", "request", "configure"),
|
||||
("method_name", "proto_request", "configure"),
|
||||
[
|
||||
pytest.param(
|
||||
"GetOidcProvider",
|
||||
@@ -516,7 +516,7 @@ class TestOidcProviderNotFound:
|
||||
oidc_servicer: MockServicerHost,
|
||||
mock_grpc_context: MagicMock,
|
||||
method_name: str,
|
||||
request: object,
|
||||
proto_request: object,
|
||||
configure: Callable[[MagicMock], None],
|
||||
) -> None:
|
||||
"""OIDC provider operations abort when provider is missing."""
|
||||
@@ -527,7 +527,7 @@ class TestOidcProviderNotFound:
|
||||
|
||||
method = getattr(oidc_servicer, method_name)
|
||||
with pytest.raises(AssertionError, match="Unreachable"):
|
||||
await method(request, mock_grpc_context)
|
||||
await method(proto_request, mock_grpc_context)
|
||||
|
||||
mock_grpc_context.abort.assert_called_once()
|
||||
|
||||
|
||||
@@ -479,7 +479,7 @@ class TestProjectNotFound:
|
||||
"""Tests for project RPCs returning NOT_FOUND."""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("method_name", "service_attr", "request"),
|
||||
("method_name", "service_attr", "proto_request"),
|
||||
_PROJECT_NOT_FOUND_TEST_CASES,
|
||||
ids=_PROJECT_NOT_FOUND_IDS,
|
||||
)
|
||||
@@ -490,14 +490,14 @@ class TestProjectNotFound:
|
||||
mock_grpc_context: MagicMock,
|
||||
method_name: str,
|
||||
service_attr: str,
|
||||
request: object,
|
||||
proto_request: object,
|
||||
) -> None:
|
||||
"""Project RPCs should abort when service returns None."""
|
||||
getattr(mockproject_service, service_attr).return_value = None
|
||||
|
||||
method = getattr(project_mixin_servicer, method_name)
|
||||
with pytest.raises(AssertionError, match="Unreachable"):
|
||||
await method(request, mock_grpc_context)
|
||||
await method(proto_request, mock_grpc_context)
|
||||
|
||||
mock_grpc_context.abort.assert_called_once()
|
||||
|
||||
|
||||
@@ -811,7 +811,7 @@ class TestNotFoundStatusCode:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
("call_method", "request", "label"),
|
||||
("call_method", "proto_request", "label"),
|
||||
[
|
||||
pytest.param(
|
||||
_call_start_sync,
|
||||
@@ -831,14 +831,14 @@ class TestNotFoundStatusCode:
|
||||
self,
|
||||
servicer_with_success: NoteFlowServicer,
|
||||
call_method: CallMethod,
|
||||
request: object,
|
||||
proto_request: object,
|
||||
label: str,
|
||||
) -> None:
|
||||
"""Sync operations abort with NOT_FOUND for missing IDs."""
|
||||
context = _DummyContext()
|
||||
|
||||
with pytest.raises(AssertionError, match="abort called"):
|
||||
await call_method(servicer_with_success, request, context)
|
||||
await call_method(servicer_with_success, proto_request, context)
|
||||
|
||||
assert context.aborted, f"Should abort for nonexistent {label}"
|
||||
assert context.abort_code == _get_status_code_not_found(), "Code should be NOT_FOUND"
|
||||
|
||||
@@ -500,7 +500,7 @@ class TestWebhookInvalidIds:
|
||||
"""Tests for invalid webhook_id handling."""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("method_name", "request"),
|
||||
("method_name", "proto_request"),
|
||||
[
|
||||
pytest.param(
|
||||
"UpdateWebhook",
|
||||
@@ -527,12 +527,12 @@ class TestWebhookInvalidIds:
|
||||
webhooks_servicer: MockServicerHost,
|
||||
mock_grpc_context: MagicMock,
|
||||
method_name: str,
|
||||
request: object,
|
||||
proto_request: object,
|
||||
) -> None:
|
||||
"""Webhook RPCs should reject invalid webhook_id values."""
|
||||
method = getattr(webhooks_servicer, method_name)
|
||||
with pytest.raises(AssertionError, match="Unreachable"):
|
||||
await method(request, mock_grpc_context)
|
||||
await method(proto_request, mock_grpc_context)
|
||||
|
||||
mock_grpc_context.abort.assert_called_once()
|
||||
|
||||
|
||||
@@ -438,7 +438,7 @@ class TestAnnotationErrors:
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("method_name", "request", "label"),
|
||||
("method_name", "proto_request", "label"),
|
||||
[
|
||||
pytest.param(
|
||||
"GetAnnotation",
|
||||
@@ -467,7 +467,7 @@ class TestAnnotationErrors:
|
||||
self,
|
||||
session_factory: async_sessionmaker[AsyncSession],
|
||||
method_name: str,
|
||||
request: object,
|
||||
proto_request: object,
|
||||
label: str,
|
||||
) -> None:
|
||||
"""Annotation operations should return NOT_FOUND when missing."""
|
||||
@@ -476,7 +476,7 @@ class TestAnnotationErrors:
|
||||
|
||||
method = getattr(servicer, method_name)
|
||||
with pytest.raises(grpc.RpcError, match=r".*"):
|
||||
await method(request, context)
|
||||
await method(proto_request, context)
|
||||
|
||||
assert context.abort_code == grpc.StatusCode.NOT_FOUND, (
|
||||
f"expected NOT_FOUND status code for {label} nonexistent annotation, got {context.abort_code}"
|
||||
|
||||
@@ -82,7 +82,7 @@ class TestInvalidInputHandling:
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("method_name", "request"),
|
||||
("method_name", "proto_request"),
|
||||
[
|
||||
pytest.param(
|
||||
"GetMeeting",
|
||||
@@ -100,14 +100,14 @@ class TestInvalidInputHandling:
|
||||
self,
|
||||
session_factory: async_sessionmaker[AsyncSession],
|
||||
method_name: str,
|
||||
request: object,
|
||||
proto_request: object,
|
||||
) -> None:
|
||||
servicer = NoteFlowServicer(session_factory=session_factory)
|
||||
context = MockContext()
|
||||
|
||||
with pytest.raises(grpc.RpcError, match=r".*"):
|
||||
method = getattr(servicer, method_name)
|
||||
await method(request, context)
|
||||
await method(proto_request, context)
|
||||
|
||||
assert context.abort_code == grpc.StatusCode.NOT_FOUND, (
|
||||
f"expected NOT_FOUND for nonexistent meeting, got {context.abort_code}"
|
||||
|
||||
Reference in New Issue
Block a user