diff --git a/galaxy_ng/app/migrations/0048_update_collection_remote_rhcertified_url.py b/galaxy_ng/app/migrations/0048_update_collection_remote_rhcertified_url.py new file mode 100644 index 0000000000..4ac7917c23 --- /dev/null +++ b/galaxy_ng/app/migrations/0048_update_collection_remote_rhcertified_url.py @@ -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 + ) + ] diff --git a/galaxy_ng/tests/unit/api/test_api_ui_collection_viewsets.py b/galaxy_ng/tests/unit/api/test_api_ui_collection_viewsets.py index ebd6a9efc7..dc2039927b 100644 --- a/galaxy_ng/tests/unit/api/test_api_ui_collection_viewsets.py +++ b/galaxy_ng/tests/unit/api/test_api_ui_collection_viewsets.py @@ -247,7 +247,7 @@ def setUp(self): super().setUp() self.remote_data = { "name": "rh-certified", - "url": "https://console.redhat.com/api/automation-hub/", + "url": "https://console.redhat.com/api/automation-hub/content/published/", } self.remote = CollectionRemote.objects.get(name=self.remote_data["name"]) self.repository = AnsibleRepository.objects.get(name=self.remote_data["name"]) diff --git a/galaxy_ng/tests/unit/migrations/test_0048_update_collection_remote_rhcertified_url.py b/galaxy_ng/tests/unit/migrations/test_0048_update_collection_remote_rhcertified_url.py new file mode 100644 index 0000000000..f44a5c19a3 --- /dev/null +++ b/galaxy_ng/tests/unit/migrations/test_0048_update_collection_remote_rhcertified_url.py @@ -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)