Skip to content

Commit dcab912

Browse files
authored
test: connect the credentials to correct objects (#873)
1 parent 7e84271 commit dcab912

File tree

5 files changed

+85
-48
lines changed

5 files changed

+85
-48
lines changed

tests/integration/api/conftest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ def check_permission_mock():
100100
@pytest.fixture
101101
def default_de(
102102
default_organization: models.Organization,
103-
default_eda_credential: models.EdaCredential,
103+
default_registry_credential: models.EdaCredential,
104104
) -> models.DecisionEnvironment:
105105
"""Return a default DE."""
106106
return models.DecisionEnvironment.objects.create(
107107
name="default_de",
108108
image_url="quay.io/ansible/ansible-rulebook:latest",
109109
description="Default DE",
110-
eda_credential=default_eda_credential,
110+
eda_credential=default_registry_credential,
111111
organization=default_organization,
112112
)
113113

@@ -135,8 +135,8 @@ def default_user_awx_token(default_user: models.User):
135135

136136
@pytest.fixture
137137
def default_project(
138-
default_vault_credential: models.EdaCredential,
139-
default_eda_credential: models.EdaCredential,
138+
default_gpg_credential: models.EdaCredential,
139+
default_scm_credential: models.EdaCredential,
140140
default_organization: models.Organization,
141141
) -> models.Project:
142142
"""Return a default Project."""
@@ -145,8 +145,8 @@ def default_project(
145145
description="Default Project",
146146
url="https://git.example.com/acme/project-01",
147147
git_hash="684f62df18ce5f8d5c428e53203b9b975426eed0",
148-
eda_credential=default_eda_credential,
149-
signature_validation_credential=default_vault_credential,
148+
eda_credential=default_scm_credential,
149+
signature_validation_credential=default_gpg_credential,
150150
scm_branch="main",
151151
proxy="http://user:[email protected]",
152152
organization=default_organization,
@@ -508,7 +508,7 @@ def default_activation(
508508
default_extra_var_data: str,
509509
default_organization: models.Organization,
510510
default_user: models.User,
511-
default_eda_credential: models.EdaCredential,
511+
default_vault_credential: models.EdaCredential,
512512
) -> models.Activation:
513513
"""Return a default Activation"""
514514
activation = models.Activation.objects.create(
@@ -522,7 +522,7 @@ def default_activation(
522522
user=default_user,
523523
log_level="debug",
524524
)
525-
activation.eda_credentials.add(default_eda_credential)
525+
activation.eda_credentials.add(default_vault_credential)
526526
return activation
527527

528528

tests/integration/api/test_decision_environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_list_decision_environments(
2121

2222
@pytest.mark.django_db
2323
def test_create_decision_environment(
24-
default_eda_credential: models.EdaCredential,
24+
default_registry_credential: models.EdaCredential,
2525
default_organization: models.Organization,
2626
client: APIClient,
2727
):
@@ -30,7 +30,7 @@ def test_create_decision_environment(
3030
"description": "desc here",
3131
"image_url": "registry.com/img1:tag1",
3232
"organization_id": default_organization.id,
33-
"eda_credential_id": default_eda_credential.id,
33+
"eda_credential_id": default_registry_credential.id,
3434
}
3535
response = client.post(
3636
f"{api_url_v1}/decision-environments/", data=data_in

tests/integration/api/test_eda_credential.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,21 @@ def test_retrieve_eda_credential(
166166
@pytest.mark.django_db
167167
def test_list_eda_credentials(
168168
client: APIClient,
169-
default_eda_credential: models.EdaCredential,
169+
default_scm_credential: models.EdaCredential,
170170
default_vault_credential: models.EdaCredential,
171-
managed_eda_credential: models.EdaCredential,
171+
managed_registry_credential: models.EdaCredential,
172172
):
173173
response = client.get(f"{api_url_v1}/eda-credentials/")
174174
assert response.status_code == status.HTTP_200_OK
175175
assert len(response.data["results"]) == 2
176-
assert response.data["results"][0]["name"] == default_eda_credential.name
176+
assert response.data["results"][0]["name"] == default_scm_credential.name
177177
assert response.data["results"][1]["name"] == default_vault_credential.name
178178

179179

180180
@pytest.mark.django_db
181181
def test_list_eda_credentials_with_kind_filter(
182182
client: APIClient,
183-
default_eda_credential: models.EdaCredential,
183+
default_registry_credential: models.EdaCredential,
184184
default_scm_credential: models.EdaCredential,
185185
):
186186
response = client.get(
@@ -210,7 +210,7 @@ def test_list_eda_credentials_with_kind_filter(
210210
)
211211
assert len(response.data["results"]) == 2
212212

213-
name_prefix = default_eda_credential.name[0]
213+
name_prefix = default_registry_credential.name[0]
214214
response = client.get(
215215
f"{api_url_v1}/eda-credentials/?credential_type__kind=scm"
216216
f"&credential_type__kind=registry&name={name_prefix}",
@@ -220,7 +220,7 @@ def test_list_eda_credentials_with_kind_filter(
220220

221221
@pytest.mark.django_db
222222
def test_list_eda_credentials_filter_credential_type_id(
223-
default_eda_credential: models.EdaCredential,
223+
default_registry_credential: models.EdaCredential,
224224
default_scm_credential: models.EdaCredential,
225225
client: APIClient,
226226
preseed_credential_types,
@@ -256,17 +256,20 @@ def test_list_eda_credentials_filter_credential_type_id(
256256

257257
@pytest.mark.django_db
258258
def test_list_eda_credentials_filter_name(
259-
default_eda_credential: models.EdaCredential,
259+
default_registry_credential: models.EdaCredential,
260260
default_scm_credential: models.EdaCredential,
261261
client: APIClient,
262262
preseed_credential_types,
263263
):
264264
response = client.get(
265-
f"{api_url_v1}/eda-credentials/?name={default_eda_credential.name}"
265+
f"{api_url_v1}/eda-credentials/"
266+
f"?name={default_registry_credential.name}"
266267
)
267268
assert response.status_code == status.HTTP_200_OK
268269
assert len(response.data["results"]) == 1
269-
assert response.data["results"][0]["name"] == default_eda_credential.name
270+
assert (
271+
response.data["results"][0]["name"] == default_registry_credential.name
272+
)
270273

271274
response = client.get(
272275
f"{api_url_v1}/eda-credentials/?name={default_scm_credential.name}"
@@ -467,30 +470,13 @@ def test_retrieve_eda_credential_with_refs(
467470
assert response.data["references"] is not None
468471
references = response.data["references"]
469472

470-
assert len(references) == 3
473+
assert len(references) == 1
471474
references[0] = {
472475
"type": "Activation",
473476
"id": default_activation.id,
474477
"name": default_activation.name,
475478
"url": f"api/eda/v1/activations/{default_activation.id}/",
476479
}
477-
references[1] = (
478-
{
479-
"type": "DecisionEnvironment",
480-
"id": default_activation.decision_environment.id,
481-
"name": default_activation.decision_environment.name,
482-
"url": (
483-
"api/eda/v1/decision_environments/"
484-
f"{default_activation.decision_environment.id}/"
485-
),
486-
},
487-
)
488-
references[1] = {
489-
"type": "Project",
490-
"id": default_activation.project.id,
491-
"name": default_activation.project.name,
492-
"url": (f"api/eda/v1/projects/{default_activation.project.id}/"),
493-
}
494480
else:
495481
assert response.data["references"] is None
496482

tests/integration/api/test_project.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ def test_update_project_with_400(
352352
@pytest.mark.django_db
353353
def test_partial_update_project(
354354
new_project: models.Project,
355-
default_eda_credential: models.EdaCredential,
355+
default_scm_credential: models.EdaCredential,
356+
default_gpg_credential: models.EdaCredential,
356357
client: APIClient,
357358
):
358359
assert new_project.eda_credential_id is None
@@ -361,8 +362,8 @@ def test_partial_update_project(
361362

362363
new_data = {
363364
"name": "new-project-updated",
364-
"eda_credential_id": default_eda_credential.id,
365-
"signature_validation_credential_id": default_eda_credential.id,
365+
"eda_credential_id": default_scm_credential.id,
366+
"signature_validation_credential_id": default_gpg_credential.id,
366367
"scm_branch": "main",
367368
"scm_refspec": "ref1",
368369
"verify_ssl": True,
@@ -379,7 +380,7 @@ def test_partial_update_project(
379380
assert new_project.eda_credential.id == new_data["eda_credential_id"]
380381
assert (
381382
new_project.signature_validation_credential.id
382-
== new_data["eda_credential_id"]
383+
== new_data["signature_validation_credential_id"]
383384
)
384385
assert new_project.verify_ssl is new_data["verify_ssl"]
385386

tests/integration/conftest.py

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,38 @@
5555
]
5656
}
5757

58+
DUMMY_GPG_KEY = """
59+
-----BEGIN PGP PUBLIC KEY BLOCK-----
60+
61+
mQINBGYxK8IBEACzO/jIqIvEPsIE4xUCRC2WKiyzlD2rEmS/MYg9TMBYTVISrkGF
62+
WfcQE0hPYU5qFeBzsr3qa/AfQobK+sv545QblAbNLINRdoaWnDMwVO+gLeVhrhbv
63+
V2c7kwBe6ahQNy7cK/fh0OilNOwTC9V+HyHO/ZpUm5dniny+R4ScNiVtkegfg7mh
64+
dDiFgAKOLgxElPUJiD/crnIqAWn2OAAqKb1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aU27bMP0575IDtgRYa/p7J1M4BqNUicyelzbeCeSBd6NEyraU
81+
c/deAZFD1MviBzFnbA5yXmxycbiEBmfpypfrsN8k/i4OU+bgZ2GgTLV3TcQcVulh
82+
Z9yJGOc2CcGW9+bCPWOtxzb6ENAv4CmMyL9BmaXKYKXrKKOFnFgjVZU/SqsURoOD
83+
FejSpTMyKeMS174YVm0qh7xw7nX1ph5mibHsS7sCfZCNywQfl91/hpalty7OeXqY
84+
drC6WsDeShPiZlJT47AJgRfEMkZlA6DumlLikkbdCb4Mty2EhaGJ13WCGOzJ3z3k
85+
RMVE39lIPjN2AKyK
86+
=MlEN
87+
-----END PGP PUBLIC KEY BLOCK-----
88+
"""
89+
5890

5991
# fixture for a running redis server
6092
@pytest.fixture
@@ -122,17 +154,17 @@ def user_credential_type(
122154

123155

124156
@pytest.fixture
125-
def default_eda_credential(
157+
def default_registry_credential(
126158
default_organization: models.Organization,
127159
preseed_credential_types,
128160
) -> models.EdaCredential:
129-
"""Return a default Credential"""
161+
"""Return a default Container Registry Credential"""
130162
registry_credential_type = models.CredentialType.objects.get(
131163
name=enums.DefaultCredentialType.REGISTRY
132164
)
133165
return models.EdaCredential.objects.create(
134166
name="default-eda-credential",
135-
description="Default EDA Credential",
167+
description="Default Registry Credential",
136168
credential_type=registry_credential_type,
137169
inputs=inputs_to_store(
138170
{"username": "dummy-user", "password": "dummy-password"}
@@ -171,8 +203,8 @@ def default_scm_credential(
171203
name=enums.DefaultCredentialType.SOURCE_CONTROL
172204
)
173205
return models.EdaCredential.objects.create(
174-
name="managed-eda-credential",
175-
description="Default EDA Credential",
206+
name="managed-scm-credential",
207+
description="Default SCM Credential",
176208
credential_type=scm_credential_type,
177209
inputs=inputs_to_store(
178210
{"username": "dummy-user", "password": "dummy-password"}
@@ -182,7 +214,7 @@ def default_scm_credential(
182214

183215

184216
@pytest.fixture
185-
def managed_eda_credential(
217+
def managed_registry_credential(
186218
default_organization: models.Organization,
187219
preseed_credential_types,
188220
) -> models.EdaCredential:
@@ -192,7 +224,7 @@ def managed_eda_credential(
192224
)
193225
return models.EdaCredential.objects.create(
194226
name="managed-eda-credential",
195-
description="Managed EDA Credential",
227+
description="Managed Registry Credential",
196228
credential_type=scm_credential_type,
197229
inputs=inputs_to_store(
198230
{"username": "dummy-user", "password": "dummy-password"}
@@ -264,3 +296,21 @@ def preseed_credential_types(
264296
) -> list[models.CredentialType]:
265297
"""Preseed Credential Types."""
266298
return populate_credential_types(CREDENTIAL_TYPES)
299+
300+
301+
@pytest.fixture
302+
def default_gpg_credential(
303+
default_organization: models.Organization,
304+
preseed_credential_types,
305+
) -> models.EdaCredential:
306+
"""Return a default GPG Credential"""
307+
gpg_credential_type = models.CredentialType.objects.get(
308+
name=enums.DefaultCredentialType.GPG
309+
)
310+
return models.EdaCredential.objects.create(
311+
name="default-gpg-credential",
312+
description="Default GPG Credential",
313+
credential_type=gpg_credential_type,
314+
inputs=inputs_to_store({"gpg_public_key": DUMMY_GPG_KEY}),
315+
organization=default_organization,
316+
)

0 commit comments

Comments
 (0)