Skip to content

Commit c9d69bd

Browse files
Restore github app lookup tests
* Introduced in PR https://github.com/ansible/awx/pull/16058/changes then a later large merge from AAP back into devel removed the changes * This PR re-introduces the github app lookup migration rename tests with the migration names updated and the kind to namespace correction
1 parent a1c49bb commit c9d69bd

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

awx/main/migrations/0201_create_managed_creds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ class Migration(migrations.Migration):
2121
]
2222

2323
operations = [
24-
migrations.RunPython(setup_tower_managed_defaults),
25-
migrations.RunPython(setup_rbac_role_system_administrator),
24+
migrations.RunPython(setup_tower_managed_defaults, migrations.RunPython.noop),
25+
migrations.RunPython(setup_rbac_role_system_administrator, migrations.RunPython.noop),
2626
]

awx/main/migrations/0202_convert_controller_role_definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,5 @@ class Migration(migrations.Migration):
9898
]
9999

100100
operations = [
101-
migrations.RunPython(convert_controller_role_definitions),
101+
migrations.RunPython(convert_controller_role_definitions, migrations.RunPython.noop),
102102
]

awx/main/tests/functional/test_migrations.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,54 @@ def test_migrate_DAB_RBAC(self, migrator):
173173
assert Role.objects.filter(
174174
singleton_name='system_administrator', role_field='system_administrator'
175175
).exists(), "expected to find a system_administrator singleton role"
176+
177+
178+
@pytest.mark.django_db
179+
class TestGithubAppBug:
180+
"""
181+
Tests that `awx-manage createsuperuser` runs successfully after
182+
the `github_app` CredentialType kind is updated to `github_app_lookup`
183+
via the migration.
184+
"""
185+
186+
def test_after_github_app_kind_migration(self, migrator):
187+
"""
188+
Verifies that `createsuperuser` does not raise a KeyError
189+
after the 0202_squashed_deletions migration (which includes
190+
the `update_github_app_kind` logic) is applied.
191+
"""
192+
# 1. Apply migrations up to the point *before* the 0204_squashed_deletions migration.
193+
# This simulates the state where the problematic CredentialType might exist.
194+
# We use 0201_create_managed_creds as the direct predecessor.
195+
old_state = migrator.apply_tested_migration(('main', '0203_remove_team_of_teams'))
196+
197+
# Get the CredentialType model from the historical state.
198+
CredentialType = old_state.apps.get_model('main', 'CredentialType')
199+
200+
# Create a CredentialType with the old, problematic 'kind' value
201+
CredentialType.objects.create(
202+
name='Legacy GitHub App Credential',
203+
kind='external', # The old, problematic 'kind' value
204+
namespace='github_app', # The namespace that causes the KeyError in the registry lookup
205+
managed=True,
206+
created=now(),
207+
modified=now(),
208+
)
209+
210+
# Apply the migration that includes the fix (0204_squashed_deletions).
211+
new_state = migrator.apply_tested_migration(('main', '0204_squashed_deletions'))
212+
213+
# Verify that the CredentialType with the old 'kind' no longer exists
214+
# and the 'kind' has been updated to the new value.
215+
CredentialType = new_state.apps.get_model('main', 'CredentialType') # Get CredentialType model from the new state
216+
217+
# Assertion 1: The CredentialType with the old 'github_app' kind should no longer exist.
218+
assert not CredentialType.objects.filter(
219+
kind='github_app'
220+
).exists(), "CredentialType with old 'github_app' kind should no longer exist after migration."
221+
222+
# Assertion 2: The CredentialType should now exist with the new 'github_app_lookup' kind
223+
# and retain its original name.
224+
assert CredentialType.objects.filter(
225+
namespace='github_app_lookup', name='Legacy GitHub App Credential'
226+
).exists(), "CredentialType should be updated to 'github_app_lookup' and retain its name."

0 commit comments

Comments
 (0)