mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 01:21:21 +03:00
Merge pull request #6416 from ryanpetrello/fix-6414
fix a 500 error in `/api/v1/credentials/` backwards compat
This commit is contained in:
commit
f05a97e4ff
@ -2045,6 +2045,8 @@ class CredentialSerializer(BaseSerializer):
|
||||
# CredentialType based on the provided values
|
||||
kind = data.get('kind', 'ssh')
|
||||
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
|
||||
value = OrderedDict(
|
||||
{'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
|
||||
|
||||
|
||||
@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
|
||||
def test_inputs_cannot_contain_extra_fields(get, post, organization, admin, credentialtype_ssh):
|
||||
params = {
|
||||
|
Loading…
Reference in New Issue
Block a user