From 2503eafdc6eb15250dd3546be98e9f006b184e40 Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Thu, 19 Dec 2024 06:03:54 -0500 Subject: [PATCH] chore: add pagerduty migrator test + fix linting (#5378) --- tools/migrators/lib/pagerduty/migrate.py | 4 ++- .../lib/tests/pagerduty/test_migrate.py | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tools/migrators/lib/tests/pagerduty/test_migrate.py diff --git a/tools/migrators/lib/pagerduty/migrate.py b/tools/migrators/lib/pagerduty/migrate.py index 950fa1046..68d5652ec 100644 --- a/tools/migrators/lib/pagerduty/migrate.py +++ b/tools/migrators/lib/pagerduty/migrate.py @@ -151,7 +151,9 @@ def migrate() -> None: migrate_notification_rules(user) print(TAB + format_user(user)) else: - print("▶ Skipping migrating user notification rules as MIGRATE_USERS is false...") + print( + "▶ Skipping migrating user notification rules as MIGRATE_USERS is false..." + ) print("▶ Migrating schedules...") for schedule in schedules: diff --git a/tools/migrators/lib/tests/pagerduty/test_migrate.py b/tools/migrators/lib/tests/pagerduty/test_migrate.py new file mode 100644 index 000000000..6a7b42edd --- /dev/null +++ b/tools/migrators/lib/tests/pagerduty/test_migrate.py @@ -0,0 +1,27 @@ +from unittest.mock import call, patch + +from lib.pagerduty.migrate import migrate + + +@patch("lib.pagerduty.migrate.MIGRATE_USERS", False) +@patch("lib.pagerduty.migrate.APISession") +@patch("lib.pagerduty.migrate.OnCallAPIClient") +def test_users_are_skipped_when_migrate_users_is_false( + MockOnCallAPIClient, MockAPISession +): + mock_session = MockAPISession.return_value + mock_session.list_all.return_value = [] + mock_oncall_client = MockOnCallAPIClient.return_value + + migrate() + + # Assert no user-related fetching or migration occurs + assert mock_session.list_all.call_args_list == [ + call("schedules", params={"include[]": "schedule_layers", "time_zone": "UTC"}), + call("escalation_policies"), + call("services", params={"include[]": "integrations"}), + call("vendors"), + # no user notification rules fetching + ] + + mock_oncall_client.list_users_with_notification_rules.assert_not_called()