Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
FabriciaDinizRH authored and jpramos123 committed Dec 5, 2024
1 parent 3794c10 commit 279ee52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
13 changes: 12 additions & 1 deletion tests/helpers/mq_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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",
Expand Down
19 changes: 17 additions & 2 deletions tests/test_api_hosts_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,17 +587,32 @@ 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,
notification_event_producer,
chunk_size,
identity=None,
control_rule=None,
is_manual_delete=False,
is_manual_delete=is_manual_delete,
):
return cls(
hosts_ids_to_delete,
Expand Down

0 comments on commit 279ee52

Please sign in to comment.