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

[PR #2032/5b846b5c backport][stable-4.9] Update remote rh-certified default url #2077

Open
wants to merge 1 commit into
base: stable-4.9
Choose a base branch
from
Open
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
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
)
]
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
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)
Loading