Skip to content

Commit 01293f1

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 fd84786 commit 01293f1

File tree

4 files changed

+55
-10
lines changed

4 files changed

+55
-10
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/migrations/0204_squashed_deletions.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
from awx.main.migrations._create_system_jobs import delete_clear_tokens_sjt
44

55

6-
# --- START of function merged from 0203_rename_github_app_kind.py ---
76
def update_github_app_kind(apps, schema_editor):
87
"""
9-
Updates the 'kind' field for CredentialType records
8+
Updates the 'namespace' field for CredentialType records
109
from 'github_app' to 'github_app_lookup'.
1110
This addresses a change in the entry point key for the GitHub App plugin.
1211
"""
@@ -15,9 +14,6 @@ def update_github_app_kind(apps, schema_editor):
1514
CredentialType.objects.using(db_alias).filter(namespace='github_app').update(namespace='github_app_lookup')
1615

1716

18-
# --- END of function merged from 0203_rename_github_app_kind.py ---
19-
20-
2117
class Migration(migrations.Migration):
2218
dependencies = [
2319
('main', '0203_remove_team_of_teams'),
@@ -118,7 +114,5 @@ class Migration(migrations.Migration):
118114
max_length=32,
119115
),
120116
),
121-
# --- START of operations merged from 0203_rename_github_app_kind.py ---
122117
migrations.RunPython(update_github_app_kind, migrations.RunPython.noop),
123-
# --- END of operations merged from 0203_rename_github_app_kind.py ---
124118
]

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 0204_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 0203_remove_team_of_teams 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 'namespace' value
201+
CredentialType.objects.create(
202+
name='Legacy GitHub App Credential',
203+
kind='external',
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+
namespace='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)