mirror of
https://github.com/ansible/awx.git
synced 2026-03-10 05:59:28 -02:30
Merge pull request #6416 from ryanpetrello/fix-6414
fix a 500 error in `/api/v1/credentials/` backwards compat
This commit is contained in:
@@ -2045,6 +2045,8 @@ class CredentialSerializer(BaseSerializer):
|
|||||||
# CredentialType based on the provided values
|
# CredentialType based on the provided values
|
||||||
kind = data.get('kind', 'ssh')
|
kind = data.get('kind', 'ssh')
|
||||||
credential_type = CredentialType.from_v1_kind(kind, data)
|
credential_type = CredentialType.from_v1_kind(kind, data)
|
||||||
|
if credential_type is None:
|
||||||
|
raise serializers.ValidationError({"kind": _('"%s" is not a valid choice' % kind)})
|
||||||
data['credential_type'] = credential_type.pk
|
data['credential_type'] = credential_type.pk
|
||||||
value = OrderedDict(
|
value = OrderedDict(
|
||||||
{'credential_type': credential_type}.items() +
|
{'credential_type': credential_type}.items() +
|
||||||
|
|||||||
@@ -619,6 +619,22 @@ def test_list_cannot_order_by_encrypted_field(post, get, organization, org_admin
|
|||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_v1_credential_kind_validity(get, post, organization, admin, credentialtype_ssh):
|
||||||
|
params = {
|
||||||
|
'name': 'Best credential ever',
|
||||||
|
'organization': organization.id,
|
||||||
|
'kind': 'nonsense'
|
||||||
|
}
|
||||||
|
response = post(
|
||||||
|
reverse('api:credential_list', kwargs={'version': 'v1'}),
|
||||||
|
params,
|
||||||
|
admin
|
||||||
|
)
|
||||||
|
assert response.status_code == 400
|
||||||
|
assert response.data['kind'] == ['"nonsense" is not a valid choice']
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_inputs_cannot_contain_extra_fields(get, post, organization, admin, credentialtype_ssh):
|
def test_inputs_cannot_contain_extra_fields(get, post, organization, admin, credentialtype_ssh):
|
||||||
params = {
|
params = {
|
||||||
|
|||||||
Reference in New Issue
Block a user