Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add pagerduty migrator test + fix linting #5378

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tools/migrators/lib/pagerduty/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 27 additions & 0 deletions tools/migrators/lib/tests/pagerduty/test_migrate.py
Original file line number Diff line number Diff line change
@@ -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()
Loading