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

feat: add tests for project update service acc credentials #15756

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions awx/main/tests/unit/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,37 @@
assert env['FOO'] == 'BAR'


class TestProjectUpdateServiceAccountCredentials(TestJobExecution):
@pytest.fixture
def project_update(self):
project_update = ProjectUpdate(

Check warning on line 1110 in awx/main/tests/unit/test_tasks.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/unit/test_tasks.py#L1110

Added line #L1110 was not covered by tests
pk=1,
project=Project(pk=1, organization=Organization(pk=1)),
)
project_update.websocket_emit_status = mock.Mock()
return project_update

Check warning on line 1115 in awx/main/tests/unit/test_tasks.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/unit/test_tasks.py#L1114-L1115

Added lines #L1114 - L1115 were not covered by tests

def test_service_account_credentials(self, project_update, mock_me):
expected_id = '4ns1bl3'
expected_secret = 'w0rks-rul3s'

Check warning on line 1119 in awx/main/tests/unit/test_tasks.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/unit/test_tasks.py#L1118-L1119

Added lines #L1118 - L1119 were not covered by tests

task = jobs.RunProjectUpdate()
insights = CredentialType.defaults['insights']()
project_update.credential = Credential(pk=1, credential_type=insights, inputs={'client_id': expected_id, 'client_secret': expected_secret})
project_update.credential.inputs['client_secret'] = encrypt_field(project_update.credential, 'client_secret')

Check warning on line 1124 in awx/main/tests/unit/test_tasks.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/unit/test_tasks.py#L1121-L1124

Added lines #L1121 - L1124 were not covered by tests

passwords = task.build_passwords(project_update, {})
password_prompts = task.get_password_prompts(passwords)
expect_passwords = task.create_expect_passwords_data_struct(password_prompts, passwords)
cred_list = task.build_credentials_list(project_update)

Check warning on line 1129 in awx/main/tests/unit/test_tasks.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/unit/test_tasks.py#L1126-L1129

Added lines #L1126 - L1129 were not covered by tests

assert expected_id in expect_passwords.values()
assert expected_secret in expect_passwords.values()

Check warning on line 1132 in awx/main/tests/unit/test_tasks.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/unit/test_tasks.py#L1131-L1132

Added lines #L1131 - L1132 were not covered by tests

assert len(cred_list) == 1
assert 'client_id' in cred_list[0].inputs

Check warning on line 1135 in awx/main/tests/unit/test_tasks.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/unit/test_tasks.py#L1134-L1135

Added lines #L1134 - L1135 were not covered by tests


class TestInventoryUpdateCredentials(TestJobExecution):
@pytest.fixture
def inventory_update(self, execution_environment):
Expand Down
Loading