mirror of
https://github.com/ansible/awx.git
synced 2026-03-28 22:35:08 -02:30
More accurate test to check validation of bad data
This commit is contained in:
@@ -1651,12 +1651,6 @@ class CredentialSerializerCreate(CredentialSerializer):
|
|||||||
fields = ('*', 'user', 'team', 'organization')
|
fields = ('*', 'user', 'team', 'organization')
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
'''
|
|
||||||
Special cases are processed for creating a credential. Fields of
|
|
||||||
user, team, and organization are allowed, and if given, roles are
|
|
||||||
automatically created for these. This is only used for list-create
|
|
||||||
view.
|
|
||||||
'''
|
|
||||||
# Remove the user, team, and organization processed in view
|
# Remove the user, team, and organization processed in view
|
||||||
for field in ['user', 'team', 'organization']:
|
for field in ['user', 'team', 'organization']:
|
||||||
validated_data.pop(field, None)
|
validated_data.pop(field, None)
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ def test_create_user_credential_via_credentials_list(post, get, alice):
|
|||||||
assert response.data['count'] == 1
|
assert response.data['count'] == 1
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_credential_validation_error_with_bad_user(post, alice):
|
def test_credential_validation_error_with_bad_user(post, admin):
|
||||||
response = post(reverse('api:credential_list'), {
|
response = post(reverse('api:credential_list'), {
|
||||||
'user': 'asdf',
|
'user': 'asdf',
|
||||||
'name': 'Some name',
|
'name': 'Some name',
|
||||||
'username': 'someusername'
|
'username': 'someusername'
|
||||||
}, alice)
|
}, admin)
|
||||||
assert response.status_code == 403
|
assert response.status_code == 400
|
||||||
assert response.data['detail'] == 'You do not have permission to perform this action.'
|
assert response.data['user'][0] == 'Incorrect type. Expected pk value, received unicode.'
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_create_user_credential_via_user_credentials_list(post, get, alice):
|
def test_create_user_credential_via_user_credentials_list(post, get, alice):
|
||||||
|
|||||||
Reference in New Issue
Block a user