fix a bug which caused v1 cred backwards-compat to apply to v2 requests

see: https://github.com/ansible/ansible-tower/issues/7793
This commit is contained in:
Ryan Petrello 2017-11-28 13:05:13 -05:00
parent 7accac2f63
commit 26845642f0
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777
2 changed files with 11 additions and 3 deletions

View File

@ -2127,7 +2127,7 @@ class CredentialSerializer(BaseSerializer):
def to_internal_value(self, data):
# TODO: remove when API v1 is removed
if 'credential_type' not in data:
if 'credential_type' not in data and self.version == 1:
# If `credential_type` is not provided, assume the payload is a
# v1 credential payload that specifies a `kind` and a flat list
# of field values

View File

@ -588,7 +588,7 @@ def test_create_org_credential_as_admin(post, organization, org_admin, credentia
params['name'] = 'Some name'
params['organization'] = organization.id
response = post(
reverse('api:credential_list'),
reverse('api:credential_list', kwargs={'version': version}),
params,
org_admin
)
@ -604,7 +604,7 @@ def test_credential_detail(post, get, organization, org_admin, credentialtype_ss
params['name'] = 'Some name'
params['organization'] = organization.id
response = post(
reverse('api:credential_list'),
reverse('api:credential_list', kwargs={'version': version}),
params,
org_admin
)
@ -1467,6 +1467,14 @@ def test_credential_type_mutability(patch, organization, admin, credentialtype_s
'as it may break the functionality of the resources using it.']
assert response.data['credential_type'] == expected
response = patch(
reverse('api:credential_detail', kwargs={'version': 'v2', 'pk': cred.pk}),
{'name': 'Worst credential ever'},
admin
)
assert response.status_code == 200
assert Credential.objects.get(pk=cred.pk).name == 'Worst credential ever'
related_obj.delete()
response = _change_credential_type()
assert response.status_code == 200