mirror of
https://github.com/ansible/awx.git
synced 2026-02-22 05:30:18 -03:30
@@ -1,11 +1,13 @@
|
||||
# Copyright (c) 2017 Ansible by Red Hat
|
||||
# All Rights Reserved.
|
||||
|
||||
import itertools
|
||||
|
||||
import pytest
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from awx.main.utils import decrypt_field
|
||||
from awx.main.models import Credential, CredentialType
|
||||
from awx.main.models import Credential, CredentialType, V1Credential
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
@@ -245,6 +247,31 @@ def test_ssh_key_data_validation(organization, kind, ssh_key_data, ssh_key_unloc
|
||||
assert e.type in (ValidationError, serializers.ValidationError)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize('become_method, valid', zip(
|
||||
dict(V1Credential.FIELDS['become_method'].choices).keys(),
|
||||
itertools.repeat(True)
|
||||
) + [('invalid-choice', False)])
|
||||
def test_choices_validity(become_method, valid, organization):
|
||||
inputs = {'become_method': become_method}
|
||||
cred_type = CredentialType.defaults['ssh']()
|
||||
cred_type.save()
|
||||
cred = Credential(
|
||||
credential_type=cred_type,
|
||||
name="Best credential ever",
|
||||
inputs=inputs,
|
||||
organization=organization
|
||||
)
|
||||
cred.save()
|
||||
|
||||
if valid:
|
||||
cred.full_clean()
|
||||
else:
|
||||
with pytest.raises(serializers.ValidationError) as e:
|
||||
cred.full_clean()
|
||||
assert "'%s' is not one of" % become_method in str(e)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_credential_encryption(organization_factory, credentialtype_ssh):
|
||||
org = organization_factory('test').organization
|
||||
|
||||
Reference in New Issue
Block a user