-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add command for Edge V2 migration (#4415)
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class EdgeAPIAppConfig(AppConfig): | ||
name = "edge_api" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from typing import Any | ||
|
||
from django.core.management import BaseCommand | ||
|
||
from projects.models import EdgeV2MigrationStatus, Project | ||
from projects.tasks import migrate_project_environments_to_v2 | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, *args: Any, **options: Any) -> str | None: | ||
for project_id in Project.objects.filter( | ||
edge_v2_migration_status__in=( | ||
EdgeV2MigrationStatus.NOT_STARTED, | ||
EdgeV2MigrationStatus.INCOMPLETE, | ||
) | ||
).values_list("id", flat=True): | ||
migrate_project_environments_to_v2(project_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.core.management import call_command | ||
from pytest_mock import MockerFixture | ||
|
||
from projects.models import EdgeV2MigrationStatus, Project | ||
|
||
|
||
def test_migrate_to_edge_v2__new_projects__dont_migrate( | ||
mocker: MockerFixture, project: Project | ||
) -> None: | ||
# Given | ||
# unmigrated projects are present | ||
unmigrated_projects = Project.objects.bulk_create( | ||
[ | ||
Project( | ||
name="edge_v2_not_started", | ||
organisation=project.organisation, | ||
edge_v2_migration_status=EdgeV2MigrationStatus.NOT_STARTED, | ||
), | ||
Project( | ||
name="edge_v2_incomplete", | ||
organisation=project.organisation, | ||
edge_v2_migration_status=EdgeV2MigrationStatus.INCOMPLETE, | ||
), | ||
], | ||
) | ||
|
||
migrate_project_environments_to_v2_mock = mocker.patch( | ||
"edge_api.management.commands.migrate_to_edge_v2.migrate_project_environments_to_v2", | ||
autospec=True, | ||
) | ||
|
||
# When | ||
call_command("migrate_to_edge_v2") | ||
|
||
# Then | ||
# unmigrated projects were migrated | ||
migrate_project_environments_to_v2_mock.assert_has_calls( | ||
[mocker.call(project.id) for project in unmigrated_projects] | ||
) | ||
# the migrated `project` was not redundantly migrated | ||
migrate_project_environments_to_v2_mock.call_count == len(unmigrated_projects) |