38
38
39
39
40
40
@pytest .mark .parametrize (
41
- "inputs" , [{}, {"username" : "adam" , "password" : "secret" }]
41
+ ("inputs" , "status_code" , "status_message" ),
42
+ [
43
+ (
44
+ {"username" : "adam" , "password" : "secret" },
45
+ status .HTTP_201_CREATED ,
46
+ None ,
47
+ ),
48
+ (
49
+ {"username" : "adam" , "password" : "secret" , "invalid_key" : "bad" },
50
+ status .HTTP_400_BAD_REQUEST ,
51
+ None ,
52
+ ),
53
+ ],
42
54
)
43
55
@pytest .mark .django_db
44
56
def test_create_eda_credential (
45
57
admin_client : APIClient ,
46
58
credential_type : models .CredentialType ,
47
59
inputs ,
60
+ status_code ,
61
+ status_message ,
48
62
):
49
63
data_in = {
50
64
"name" : "eda-credential" ,
@@ -54,9 +68,15 @@ def test_create_eda_credential(
54
68
response = admin_client .post (
55
69
f"{ api_url_v1 } /eda-credentials/" , data = data_in
56
70
)
57
- assert response .status_code == status .HTTP_201_CREATED
58
- assert response .data ["name" ] == "eda-credential"
59
- assert response .data ["managed" ] is False
71
+ assert response .status_code == status_code
72
+ if status_code == status .HTTP_201_CREATED :
73
+ assert response .data ["name" ] == "eda-credential"
74
+ assert response .data ["managed" ] is False
75
+ else :
76
+ assert (
77
+ "Input keys {'invalid_key'} are not defined in the schema"
78
+ in response .data ["inputs" ][0 ]
79
+ )
60
80
61
81
62
82
@pytest .mark .parametrize (
@@ -101,27 +121,6 @@ def test_create_eda_credential_with_gpg_key_data(
101
121
assert status_message in response .data .get ("inputs.gpg_public_key" , "" )
102
122
103
123
104
- @pytest .mark .django_db
105
- def test_create_eda_credential_with_type (
106
- admin_client : APIClient , credential_type : models .CredentialType
107
- ):
108
- data_in = {
109
- "name" : "eda-credential" ,
110
- "inputs" : {"username" : "adam" , "password" : "secret" },
111
- "credential_type_id" : credential_type .id ,
112
- }
113
- response = admin_client .post (
114
- f"{ api_url_v1 } /eda-credentials/" , data = data_in
115
- )
116
- assert response .status_code == status .HTTP_201_CREATED
117
- assert response .data ["name" ] == "eda-credential"
118
- assert response .data ["managed" ] is False
119
- assert response .data ["inputs" ] == {
120
- "password" : "$encrypted$" ,
121
- "username" : "adam" ,
122
- }
123
-
124
-
125
124
@pytest .mark .parametrize (
126
125
("credential_type" , "status_code" , "key" , "error_message" ),
127
126
[
@@ -366,6 +365,33 @@ def test_partial_update_eda_credential_without_inputs(
366
365
}
367
366
368
367
368
+ @pytest .mark .django_db
369
+ def test_partial_update_eda_credential_with_invalid_inputs (
370
+ admin_client : APIClient , credential_type : models .CredentialType
371
+ ):
372
+ obj = models .EdaCredential .objects .create (
373
+ name = "eda-credential" ,
374
+ inputs = {"username" : "adam" , "password" : "secret" },
375
+ credential_type_id = credential_type .id ,
376
+ managed = True ,
377
+ )
378
+ data = {
379
+ "inputs" : {
380
+ "username" : "bearny" ,
381
+ "password" : "demo" ,
382
+ "invalid_key" : "bad" ,
383
+ }
384
+ }
385
+ response = admin_client .patch (
386
+ f"{ api_url_v1 } /eda-credentials/{ obj .id } /" , data = data
387
+ )
388
+ assert response .status_code == status .HTTP_400_BAD_REQUEST
389
+ assert (
390
+ "Input keys {'invalid_key'} are not defined in the schema"
391
+ in response .data ["inputs" ][0 ]
392
+ )
393
+
394
+
369
395
@pytest .mark .parametrize (
370
396
("credential_type" , "inputs" ),
371
397
[
0 commit comments