Skip to content

Commit

Permalink
add new migration and test
Browse files Browse the repository at this point in the history
  • Loading branch information
drodowic committed Jan 16, 2024
1 parent 7ff26e1 commit 812612f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
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
@@ -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)

0 comments on commit 812612f

Please sign in to comment.