Skip to content

Commit

Permalink
Renaming test fixtures
Browse files Browse the repository at this point in the history
By including the name databroker it is easier to understand what they are doing
  • Loading branch information
erikbosch committed Nov 28, 2024
1 parent 7272514 commit 50c1c46
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions kuksa-client/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def val_servicer_v2_fixture(mocker):
return servicer_v2


@pytest_asyncio.fixture(name="val_server", scope="function")
@pytest_asyncio.fixture(name="mocked_databroker", scope="function")
async def val_server_fixture(unused_tcp_port, val_servicer_v1, val_servicer_v2):
server = grpc.aio.server()
val_v1.add_VALServicer_to_server(val_servicer_v1, server)
Expand All @@ -66,7 +66,7 @@ async def val_server_fixture(unused_tcp_port, val_servicer_v1, val_servicer_v2):
await server.stop(grace=2.0)


@pytest_asyncio.fixture(name="secure_val_server", scope="function")
@pytest_asyncio.fixture(name="secure_mocked_databroker", scope="function")
async def secure_val_server_fixture(
unused_tcp_port, resources_path, val_servicer_v1, val_servicer_v2
):
Expand Down
48 changes: 24 additions & 24 deletions kuksa-client/tests/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def test_to_dict(self, entry, fields, update_dict):
@pytest.mark.asyncio
class TestVSSClient:

@pytest.mark.usefixtures("secure_val_server")
@pytest.mark.usefixtures("secure_mocked_databroker")
async def test_secure_connection(
self, unused_tcp_port, resources_path, val_servicer_v1
):
Expand Down Expand Up @@ -745,7 +745,7 @@ async def subscribe_response_stream(**kwargs):
'Vehicle.Chassis.Height': Metadata(entry_type=EntryType.ATTRIBUTE),
}

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_get_some_entries(self, unused_tcp_port, val_servicer_v1):
val_servicer_v1.Get.return_value = val_v1.GetResponse(
entries=[
Expand Down Expand Up @@ -948,7 +948,7 @@ async def test_get_some_entries(self, unused_tcp_port, val_servicer_v1):
).entries
)

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_get_no_entries_requested(self, unused_tcp_port, val_servicer_v1):
val_servicer_v1.Get.side_effect = generate_error(
grpc.StatusCode.INVALID_ARGUMENT, "No datapoints requested"
Expand All @@ -964,7 +964,7 @@ async def test_get_no_entries_requested(self, unused_tcp_port, val_servicer_v1):
}, errors=[]).args
assert val_servicer_v1.Get.call_args[0][0] == val_v1.GetRequest()

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_get_unset_entries(self, unused_tcp_port, val_servicer_v1):
val_servicer_v1.Get.return_value = val_v1.GetResponse(
entries=[
Expand All @@ -982,7 +982,7 @@ async def test_get_unset_entries(self, unused_tcp_port, val_servicer_v1):
assert entries == [DataEntry('Vehicle.Speed'), DataEntry(
'Vehicle.ADAS.ABS.IsActive')]

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_get_nonexistent_entries(self, unused_tcp_port, val_servicer_v1):
error = types_v1.Error(
code=404, reason="not_found", message="Does.Not.Exist not found"
Expand All @@ -998,7 +998,7 @@ async def test_get_nonexistent_entries(self, unused_tcp_port, val_servicer_v1):
View.CURRENT_VALUE, (Field.VALUE,)),
))

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_set_some_updates_v1(self, unused_tcp_port, val_servicer_v1):
val_servicer_v1.Get.return_value = val_v1.GetResponse(
entries=(
Expand Down Expand Up @@ -1234,7 +1234,7 @@ async def test_set_some_updates_v1(self, unused_tcp_port, val_servicer_v1):
).updates
)

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_set_some_updates_v2(
self, unused_tcp_port, val_servicer_v2, val_servicer_v1
):
Expand Down Expand Up @@ -1313,7 +1313,7 @@ async def test_set_some_updates_v2(
):
assert actual_request == expected_request

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_set_some_updates_v2_target(
self, unused_tcp_port, val_servicer_v2, val_servicer_v1
):
Expand Down Expand Up @@ -1358,7 +1358,7 @@ async def test_set_some_updates_v2_target(
assert val_servicer_v1.Get.call_count == 1
assert val_servicer_v2.PublishValue.call_count == 0

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_set_no_updates_provided(
self, unused_tcp_port, val_servicer_v1, val_servicer_v2
):
Expand Down Expand Up @@ -1399,7 +1399,7 @@ async def test_set_no_updates_provided(
assert val_servicer_v1.Get.call_count == 0
assert val_servicer_v2.PublishValue.call_count == 0

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_set_nonexistent_entries_v1(self, unused_tcp_port, val_servicer_v1):
error = types_v1.Error(
code=404, reason="not_found", message="Does.Not.Exist not found"
Expand Down Expand Up @@ -1445,7 +1445,7 @@ async def test_set_nonexistent_entries_v1(self, unused_tcp_port, val_servicer_v1
) # Get should'nt have been called again
assert val_servicer_v1.Set.call_count == 1

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_set_nonexistent_entries_v2(
self, unused_tcp_port, val_servicer_v2, val_servicer_v1
):
Expand Down Expand Up @@ -1496,7 +1496,7 @@ async def test_set_nonexistent_entries_v2(
) # Get should'nt have been called again
assert val_servicer_v2.PublishValue.call_count == 1

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_authorize_successful(self, unused_tcp_port, val_servicer_v1):
val_servicer_v1.GetServerInfo.return_value = val_v1.GetServerInfoResponse(
name="test_server", version="1.2.3"
Expand Down Expand Up @@ -1531,7 +1531,7 @@ async def test_authorize_successful(self, unused_tcp_port, val_servicer_v1):
assert client.authorization_header == bearer
assert success == "Authenticated"

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_authorize_unsuccessful(self, unused_tcp_port, val_servicer_v1):
val_servicer_v1.GetServerInfo.side_effect = generate_error(
grpc.StatusCode.UNAUTHENTICATED,
Expand All @@ -1542,7 +1542,7 @@ async def test_authorize_unsuccessful(self, unused_tcp_port, val_servicer_v1):
await client.authorize(token='')
assert client.authorization_header is None

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_subscribe_some_entries_v1(
self, mocker, unused_tcp_port, val_servicer_v1
):
Expand Down Expand Up @@ -1734,7 +1734,7 @@ async def test_subscribe_some_entries_v1(
],
]

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_subscribe_some_entries_v2(
self, mocker, unused_tcp_port, val_servicer_v2
):
Expand Down Expand Up @@ -1846,7 +1846,7 @@ async def test_subscribe_some_entries_v2(
],
]

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_subscribe_some_entries_v2_target(
self, mocker, unused_tcp_port, val_servicer_v2
):
Expand Down Expand Up @@ -1879,7 +1879,7 @@ async def test_subscribe_some_entries_v2_target(

assert not actual_responses

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_subscribe_no_entries_requested(
self, mocker, unused_tcp_port, val_servicer_v1, val_servicer_v2
):
Expand All @@ -1903,7 +1903,7 @@ async def test_subscribe_no_entries_requested(
async for _ in client.subscribe(entries=(), try_v2=True):
pass

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_subscribe_nonexistent_entries(
self, mocker, unused_tcp_port, val_servicer_v1, val_servicer_v2
):
Expand Down Expand Up @@ -1939,7 +1939,7 @@ async def test_subscribe_nonexistent_entries(
):
pass

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_get_server_info(self, unused_tcp_port, val_servicer_v1):
val_servicer_v1.GetServerInfo.return_value = val_v1.GetServerInfoResponse(
name="test_server", version="1.2.3"
Expand All @@ -1949,7 +1949,7 @@ async def test_get_server_info(self, unused_tcp_port, val_servicer_v1):
assert server_info == ServerInfo(
name='test_server', version='1.2.3')

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_get_server_info_unavailable(self, unused_tcp_port, val_servicer_v1):
val_servicer_v1.GetServerInfo.side_effect = generate_error(
grpc.StatusCode.UNAVAILABLE, "Unavailable"
Expand All @@ -1962,7 +1962,7 @@ async def test_get_server_info_unavailable(self, unused_tcp_port, val_servicer_v
@pytest.mark.asyncio
class TestSubscriberManager:

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_add_subscriber_v1(self, mocker, unused_tcp_port, val_servicer_v1):
async with VSSClient('127.0.0.1', unused_tcp_port, ensure_startup_connection=False) as client:
subscriber_manager = SubscriberManager(client)
Expand Down Expand Up @@ -2047,7 +2047,7 @@ async def test_add_subscriber_v1(self, mocker, unused_tcp_port, val_servicer_v1)
],
]

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_remove_subscriber_v1(self, mocker, unused_tcp_port, val_servicer_v1):
async with VSSClient(
"127.0.0.1", unused_tcp_port, ensure_startup_connection=False
Expand Down Expand Up @@ -2095,7 +2095,7 @@ async def test_remove_subscriber_v1(self, mocker, unused_tcp_port, val_servicer_
exc_info.value.args[0] == f"Could not find subscription {str(sub_uid)}"
)

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_add_subscriber_v2(self, mocker, unused_tcp_port, val_servicer_v2):
_entries: Dict[str, types_v2.Datapoint] = {
"Vehicle.Speed": types_v2.Datapoint(
Expand Down Expand Up @@ -2165,7 +2165,7 @@ async def test_add_subscriber_v2(self, mocker, unused_tcp_port, val_servicer_v2)
],
]

@pytest.mark.usefixtures("val_server")
@pytest.mark.usefixtures("mocked_databroker")
async def test_remove_subscriber_v2(self, mocker, unused_tcp_port, val_servicer_v2):
async with VSSClient(
"127.0.0.1", unused_tcp_port, ensure_startup_connection=False
Expand Down

0 comments on commit 50c1c46

Please sign in to comment.