UT: Add test_invalid_values()
This commit is contained in:
parent
be9889c9d1
commit
031fce9fd8
|
@ -15,7 +15,14 @@ PARAMETRIZED_PARAMETER_VALUES = [
|
|||
]
|
||||
|
||||
|
||||
def build_credential_dict(credential_component_type: CredentialComponentType, key: str, value: str):
|
||||
|
||||
|
||||
INVALID_VALUES = {
|
||||
CredentialComponentType.USERNAME: (None, 1, 2.0),
|
||||
CredentialComponentType.PASSWORD: (None, 1, 2.0),
|
||||
}
|
||||
|
||||
def build_component_dict(credential_component_type: CredentialComponentType, key: str, value: str):
|
||||
return {"credential_type": credential_component_type.name, key: value}
|
||||
|
||||
|
||||
|
@ -30,7 +37,7 @@ def test_credential_component_serialize(
|
|||
|
||||
serialized_object = schema.dump(constructed_object)
|
||||
|
||||
assert serialized_object == build_credential_dict(credential_component_type, key, value)
|
||||
assert serialized_object == build_component_dict(credential_component_type, key, value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(PARAMETRIZED_PARAMETER_NAMES, PARAMETRIZED_PARAMETER_VALUES)
|
||||
|
@ -38,7 +45,7 @@ def test_credential_component_deserialize(
|
|||
credential_component_class, schema_class, credential_component_type, key, value
|
||||
):
|
||||
schema = schema_class()
|
||||
credential_dict = build_credential_dict(credential_component_type, key, value)
|
||||
credential_dict = build_component_dict(credential_component_type, key, value)
|
||||
expected_deserialized_object = credential_component_class(value)
|
||||
|
||||
deserialized_object = credential_component_class(**schema.load(credential_dict))
|
||||
|
@ -50,7 +57,7 @@ def test_credential_component_deserialize(
|
|||
def test_invalid_credential_type(
|
||||
credential_component_class, schema_class, credential_component_type, key, value
|
||||
):
|
||||
invalid_component_dict = build_credential_dict(credential_component_type, key, value)
|
||||
invalid_component_dict = build_component_dict(credential_component_type, key, value)
|
||||
invalid_component_dict["credential_type"] = "INVALID"
|
||||
schema = schema_class()
|
||||
|
||||
|
@ -62,7 +69,7 @@ def test_invalid_credential_type(
|
|||
def test_encorrect_credential_type(
|
||||
credential_component_class, schema_class, credential_component_type, key, value
|
||||
):
|
||||
incorrect_component_dict = build_credential_dict(credential_component_type, key, value)
|
||||
incorrect_component_dict = build_component_dict(credential_component_type, key, value)
|
||||
incorrect_component_dict["credential_type"] = (
|
||||
CredentialComponentType.USERNAME.name
|
||||
if credential_component_type != CredentialComponentType.USERNAME
|
||||
|
@ -72,3 +79,14 @@ def test_encorrect_credential_type(
|
|||
|
||||
with pytest.raises(ValidationError):
|
||||
credential_component_class(**schema.load(incorrect_component_dict))
|
||||
|
||||
@pytest.mark.parametrize(PARAMETRIZED_PARAMETER_NAMES, PARAMETRIZED_PARAMETER_VALUES)
|
||||
def test_invalid_values(
|
||||
credential_component_class, schema_class, credential_component_type, key, value
|
||||
):
|
||||
schema = schema_class()
|
||||
|
||||
for invalid_value in INVALID_VALUES[credential_component_type]:
|
||||
component_dict = build_component_dict(credential_component_type, key, invalid_value)
|
||||
with pytest.raises(ValidationError):
|
||||
credential_component_class(**schema.load(component_dict))
|
||||
|
|
Loading…
Reference in New Issue