From 279ee52a730e18bf7d32cdf8f9749a6d46ec6168 Mon Sep 17 00:00:00 2001 From: Fabricia Diniz Date: Thu, 5 Dec 2024 10:46:34 +0000 Subject: [PATCH] add test --- tests/helpers/mq_utils.py | 13 ++++++++++++- tests/test_api_hosts_delete.py | 19 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/helpers/mq_utils.py b/tests/helpers/mq_utils.py index fd6e70c19e..5f60a592a4 100644 --- a/tests/helpers/mq_utils.py +++ b/tests/helpers/mq_utils.py @@ -104,7 +104,13 @@ def assert_mq_host_data(actual_id, actual_event, expected_results, host_keys_to_ def assert_delete_event_is_valid( - event_producer, host, timestamp, expected_request_id=None, expected_metadata=None, identity=USER_IDENTITY + event_producer, + host, + timestamp, + expected_request_id=None, + expected_metadata=None, + identity=USER_IDENTITY, + is_manual_delete=False, ): event = json.loads(event_producer.event) @@ -131,6 +137,11 @@ def assert_delete_event_is_valid( assert host.canonical_facts.get("insights_id") == event["insights_id"] + assert event["manual_delete"] == is_manual_delete + + if is_manual_delete: + assert event["subscription_manager_id"] is not None + assert event_producer.key == str(host.id) assert event_producer.headers == expected_headers( "delete", diff --git a/tests/test_api_hosts_delete.py b/tests/test_api_hosts_delete.py index 7f48b5da2e..bfcf6f88df 100644 --- a/tests/test_api_hosts_delete.py +++ b/tests/test_api_hosts_delete.py @@ -587,9 +587,24 @@ def test_postgres_delete_filtered_hosts_nomatch( assert response_data["results"][0]["id"] == not_deleted_host_id +def test_delete_with_ui_host( + db_create_host, api_delete_host, event_datetime_mock, event_producer_mock, notification_event_producer_mock +): + host = db_create_host(extra_data={"canonical_facts": {"subscription_manager_id": generate_uuid()}}) + headers = {"Host": "console.redhat.com"} + + response_status, _ = api_delete_host(host.id, extra_headers=headers) + + assert_response_status(response_status, expected_status=200) + + assert_delete_event_is_valid( + event_producer=event_producer_mock, host=host, timestamp=event_datetime_mock, is_manual_delete=True + ) + + class DeleteHostsMock: @classmethod - def create_mock(cls, hosts_ids_to_delete): + def create_mock(cls, hosts_ids_to_delete, is_manual_delete=False): def _constructor( select_query, event_producer, @@ -597,7 +612,7 @@ def _constructor( chunk_size, identity=None, control_rule=None, - is_manual_delete=False, + is_manual_delete=is_manual_delete, ): return cls( hosts_ids_to_delete,