Skip to content

Commit

Permalink
Updated the unit test settings for consistency between github actions…
Browse files Browse the repository at this point in the history
… and local environments
  • Loading branch information
robertbetts committed Sep 28, 2023
1 parent 631d531 commit 8247b70
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 84 deletions.
45 changes: 23 additions & 22 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,35 @@ def test_settings():
}
end_time = datetime.datetime.utcnow()
logging.info(
f"Test summary:\n"
f"TEST SESSION SUMMARY:\n"
f"start_time: {start_time}\n"
f"end_time: {end_time}\n"
f"duration: {end_time - start_time}"
)


@pytest.fixture(scope="session")
def test_rmq_url(test_settings):
def rmq_settings(test_settings):
logging.debug("Setting up RabbitMQ test instance")
vhost = f"pytest-{secrets.token_hex(8)}"

if IN_GITHUB_ACTIONS:
rmq_url = build_amqp_url(
settings = dict(
host=test_settings["host"],
port=test_settings["port"],
username=test_settings["username"],
password=test_settings["password"],
vhost=vhost,
)
else:
rmq_url = {
"username": "guest",
"password": "guest",
"host": "localhost",
"port": 5672,
"vhost": vhost,
"verify": False,
}
settings = dict(
username="guest",
password="guest",
host="localhost",
port=5672,
vhost=vhost,
verify=False,
)

api_url = build_rmq_api_url(
scheme=test_settings["api_scheme"],
Expand All @@ -98,15 +99,15 @@ def test_rmq_url(test_settings):
password=test_settings["password"],
)

create_virtual_host(api_url, rmq_url)
create_virtual_host(api_url, settings)

def message_callback(*args, **kwargs): # pragma: no cover
pass

transport_settings = dict(
service_name=test_settings["service_name"],
instance_id=uuid4().hex,
amqp_url=rmq_url,
amqp_url=settings,
rpc_exchange=test_settings["rpc_exchange"],
events_exchange=test_settings["events_exchange"],
dl_exchange=test_settings["dl_exchange"],
Expand All @@ -119,15 +120,15 @@ def message_callback(*args, **kwargs): # pragma: no cover
transport = RMQTransport(**transport_settings)

configure_nuropb_rmq(
rmq_url=rmq_url,
rmq_url=settings,
events_exchange=transport.events_exchange,
rpc_exchange=transport.rpc_exchange,
dl_exchange=transport._dl_exchange,
dl_queue=transport._dl_queue,
)
yield rmq_url
yield settings
logging.debug("Shutting down RabbitMQ test instance")
delete_virtual_host(api_url, rmq_url)
delete_virtual_host(api_url, settings)


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -177,8 +178,8 @@ def message_callback(*args, **kwargs): # pragma: no cover
dl_queue=transport._dl_queue,
)
yield rmq_url
# logging.debug("Shutting down RabbitMQ test instance")
# delete_virtual_host(api_url, rmq_url)
logging.debug("Shutting down RabbitMQ test instance")
delete_virtual_host(api_url, rmq_url)


@pytest.fixture(scope="session")
Expand All @@ -202,7 +203,7 @@ def service_instance():


@pytest_asyncio.fixture(scope="function")
async def test_mesh_service(test_settings, test_rmq_url, service_instance):
async def test_mesh_service(test_settings, rmq_settings, service_instance):
service_name = test_settings["service_name"]
instance_id = uuid4().hex
transport_settings = dict(
Expand All @@ -216,7 +217,7 @@ async def test_mesh_service(test_settings, test_rmq_url, service_instance):
service_name=service_name,
instance_id=instance_id,
service_instance=service_instance,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=transport_settings,
Expand All @@ -227,7 +228,7 @@ async def test_mesh_service(test_settings, test_rmq_url, service_instance):


@pytest_asyncio.fixture(scope="function")
async def test_mesh_client(test_rmq_url, test_settings, test_mesh_service):
async def test_mesh_client(rmq_settings, test_settings, test_mesh_service):
instance_id = uuid4().hex
settings = test_mesh_service.transport.rmq_configuration
client_transport_settings = dict(
Expand All @@ -237,7 +238,7 @@ async def test_mesh_client(test_rmq_url, test_settings, test_mesh_service):
)
client_api = RMQAPI(
instance_id=instance_id,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange=settings["rpc_exchange"],
events_exchange=settings["events_exchange"],
transport_settings=client_transport_settings,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_api_async_service_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.mark.asyncio
async def test_async_service_methods(test_settings, test_rmq_url, service_instance):
async def test_async_service_methods(test_settings, rmq_settings, service_instance):
service_name = test_settings["service_name"]
instance_id = uuid4().hex
transport_settings = dict(
Expand All @@ -23,7 +23,7 @@ async def test_async_service_methods(test_settings, test_rmq_url, service_instan
service_name=service_name,
instance_id=instance_id,
service_instance=service_instance,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=transport_settings,
Expand All @@ -41,7 +41,7 @@ async def test_async_service_methods(test_settings, test_rmq_url, service_instan
)
client_api = RMQAPI(
instance_id=instance_id,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=client_transport_settings,
Expand Down
30 changes: 15 additions & 15 deletions tests/test_api_service_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@pytest.mark.asyncio
async def test_request_response_fail(test_settings, test_rmq_url, service_instance):
async def test_request_response_fail(test_settings, rmq_settings, service_instance):
service_name = test_settings["service_name"]
instance_id = uuid4().hex
transport_settings = dict(
Expand All @@ -24,7 +24,7 @@ async def test_request_response_fail(test_settings, test_rmq_url, service_instan
service_name=service_name,
instance_id=instance_id,
service_instance=service_instance,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=transport_settings,
Expand All @@ -42,7 +42,7 @@ async def test_request_response_fail(test_settings, test_rmq_url, service_instan
)
client_api = RMQAPI(
instance_id=instance_id,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=client_transport_settings,
Expand Down Expand Up @@ -86,7 +86,7 @@ async def test_request_response_fail(test_settings, test_rmq_url, service_instan


@pytest.mark.asyncio
async def test_request_response_pass(test_settings, test_rmq_url, service_instance):
async def test_request_response_pass(test_settings, rmq_settings, service_instance):
service_name = test_settings["service_name"]
instance_id = uuid4().hex
transport_settings = dict(
Expand All @@ -100,7 +100,7 @@ async def test_request_response_pass(test_settings, test_rmq_url, service_instan
service_name=service_name,
instance_id=instance_id,
service_instance=service_instance,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=transport_settings,
Expand All @@ -117,7 +117,7 @@ async def test_request_response_pass(test_settings, test_rmq_url, service_instan
)
client_api = RMQAPI(
instance_id=instance_id,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=client_transport_settings,
Expand Down Expand Up @@ -150,7 +150,7 @@ async def test_request_response_pass(test_settings, test_rmq_url, service_instan


@pytest.mark.asyncio
async def test_request_response_success(test_settings, test_rmq_url, service_instance):
async def test_request_response_success(test_settings, rmq_settings, service_instance):
service_name = test_settings["service_name"]
instance_id = uuid4().hex
transport_settings = dict(
Expand All @@ -164,7 +164,7 @@ async def test_request_response_success(test_settings, test_rmq_url, service_ins
service_name=service_name,
instance_id=instance_id,
service_instance=service_instance,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=transport_settings,
Expand All @@ -181,7 +181,7 @@ async def test_request_response_success(test_settings, test_rmq_url, service_ins
)
client_api = RMQAPI(
instance_id=instance_id,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=client_transport_settings,
Expand Down Expand Up @@ -215,7 +215,7 @@ async def test_request_response_success(test_settings, test_rmq_url, service_ins

@pytest.mark.asyncio
async def test_request_response_call_again(
test_settings, test_rmq_url, service_instance
test_settings, rmq_settings, service_instance
):
service_name = test_settings["service_name"]
instance_id = uuid4().hex
Expand All @@ -230,7 +230,7 @@ async def test_request_response_call_again(
service_name=service_name,
instance_id=instance_id,
service_instance=service_instance,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=transport_settings,
Expand All @@ -247,7 +247,7 @@ async def test_request_response_call_again(
)
client_api = RMQAPI(
instance_id=instance_id,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=client_transport_settings,
Expand Down Expand Up @@ -281,7 +281,7 @@ async def test_request_response_call_again(

@pytest.mark.asyncio
async def test_request_response_call_again_loop_fail(
test_settings, test_rmq_url, service_instance
test_settings, rmq_settings, service_instance
):
service_name = test_settings["service_name"]
instance_id = uuid4().hex
Expand All @@ -296,7 +296,7 @@ async def test_request_response_call_again_loop_fail(
service_name=service_name,
instance_id=instance_id,
service_instance=service_instance,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=transport_settings,
Expand All @@ -313,7 +313,7 @@ async def test_request_response_call_again_loop_fail(
)
client_api = RMQAPI(
instance_id=instance_id,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=client_transport_settings,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@pytest.mark.asyncio
async def test_request_response_pass(test_settings, test_rmq_url, service_instance):
async def test_request_response_pass(test_settings, rmq_settings, service_instance):
instance_id = uuid4().hex
client_transport_settings = dict(
dl_exchange=test_settings["dl_exchange"],
Expand All @@ -19,7 +19,7 @@ async def test_request_response_pass(test_settings, test_rmq_url, service_instan
)
client_api = RMQAPI(
instance_id=instance_id,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange="test_rpc_exchange",
events_exchange="test_events_exchange",
transport_settings=client_transport_settings,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_message_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@pytest.mark.asyncio
async def test_call_self(test_settings, test_rmq_url, service_instance):
async def test_call_self(test_settings, rmq_settings, service_instance):
""" Currently this test passes, as there is no check for the service name in the request method.
Restricting the service name to be different from the service name of the service instance is
under consideration for a future release.
Expand All @@ -26,7 +26,7 @@ async def test_call_self(test_settings, test_rmq_url, service_instance):
service_name=service_instance.service_name,
instance_id=service_instance.instance_id,
service_instance=service_instance,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange=test_settings["rpc_exchange"],
events_exchange=test_settings["events_exchange"],
transport_settings=transport_settings,
Expand Down Expand Up @@ -59,7 +59,7 @@ async def test_call_self(test_settings, test_rmq_url, service_instance):


@pytest.mark.asyncio
async def test_subscribe_to_events_from_self(test_settings, test_rmq_url, service_instance):
async def test_subscribe_to_events_from_self(test_settings, rmq_settings, service_instance):
""" Currently this test passes, as there is no check to restrict binding to the service queue
for events that originate from the service.
This restriction is under consideration for a future release.
Expand All @@ -85,7 +85,7 @@ def handle_event(topic, event, target, context):
service_name=service_instance.service_name,
instance_id=service_instance.instance_id,
service_instance=service_instance,
amqp_url=test_rmq_url,
amqp_url=rmq_settings,
rpc_exchange=test_settings["rpc_exchange"],
events_exchange=test_settings["events_exchange"],
transport_settings=transport_settings,
Expand Down
Loading

0 comments on commit 8247b70

Please sign in to comment.