-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
galaxy_ng/app/migrations/0048_update_collection_remote_rhcertified_url.py
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,29 @@ | ||
from django.db import migrations | ||
|
||
def update_collection_remote_rhcertified_url(apps, schema_editor): | ||
""" | ||
Updates the existing collection remote `rh-certified` url field | ||
to add `content/published/`. | ||
""" | ||
|
||
CollectionRemote = apps.get_model('ansible', 'CollectionRemote') | ||
|
||
rh_remote = CollectionRemote.objects.filter(name='rh-certified').first() | ||
|
||
if rh_remote and rh_remote.url == 'https://console.redhat.com/api/automation-hub/': | ||
rh_remote.url = rh_remote.url.replace('https://console.redhat.com/api/automation-hub/', 'https://console.redhat.com/api/automation-hub/content/published/') | ||
rh_remote.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('galaxy', '0047_update_role_search_vector_trigger'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=update_collection_remote_rhcertified_url, | ||
reverse_code=migrations.RunPython.noop | ||
) | ||
] |
38 changes: 38 additions & 0 deletions
38
galaxy_ng/tests/unit/migrations/test_0048_update_collection_remote_rhcertified_url.py
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,38 @@ | ||
from importlib import import_module | ||
|
||
from django.db import connection | ||
from django.test import TestCase | ||
from django.apps import apps | ||
|
||
from pulp_ansible.app.models import CollectionRemote | ||
|
||
|
||
class TestRemoteRHCertifiedCollectionURL(TestCase): | ||
|
||
def _run_migration(self): | ||
migration = import_module("galaxy_ng.app.migrations.0048_update_collection_remote_rhcertified_url") | ||
migration.update_collection_remote_rhcertified_url(apps, connection.schema_editor()) | ||
|
||
def test_correct_url_update_after_migration(self): | ||
url = 'https://console.redhat.com/api/automation-hub/' | ||
CollectionRemote.objects.filter(name="rh-certified").update(url=url) | ||
|
||
remote = CollectionRemote.objects.get(name='rh-certified') | ||
self.assertEqual(remote.url, url) | ||
|
||
self._run_migration() | ||
|
||
remote.refresh_from_db() | ||
self.assertEqual(remote.url, 'https://console.redhat.com/api/automation-hub/content/published/') | ||
|
||
def test_no_url_change_after_migration(self): | ||
url = 'https://console.redhat.com/api/automation-hub/content/1237261-synclist/' | ||
CollectionRemote.objects.filter(name="rh-certified").update(url=url) | ||
|
||
remote = CollectionRemote.objects.get(name='rh-certified') | ||
self.assertEqual(remote.url, url) | ||
|
||
self._run_migration() | ||
|
||
remote.refresh_from_db() | ||
self.assertEqual(remote.url, url) |