From ea134140a28c27299206fda338d88e40a41726e6 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Wed, 20 Nov 2024 05:30:00 -0500 Subject: [PATCH] Add tests for new Credential private api class --- .../_temporary_private_credential_api_test.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/_temporary_private_credential_api_test.py diff --git a/tests/_temporary_private_credential_api_test.py b/tests/_temporary_private_credential_api_test.py new file mode 100644 index 00000000..78c72fc7 --- /dev/null +++ b/tests/_temporary_private_credential_api_test.py @@ -0,0 +1,55 @@ +"""Tests for the temporarily hosted private credential structure.""" + +import pytest + +from awx_plugins.interfaces._temporary_private_credential_api import ( + Credential, + GenericOptionalPrimitiveType, +) + + +def test_credential_instantiation() -> None: + """Check that credential type can be instantiated.""" + assert Credential() + + +@pytest.mark.parametrize( + ('inputs', 'key', 'expected'), + ( + pytest.param({'foo': 'bar'}, 'foo', 'bar', id='key-present'), + pytest.param({'foo1': 'bar1'}, 'baz', None, id='key-missing'), + ), +) +def test_credential_get_input( + inputs: dict[str, GenericOptionalPrimitiveType], + key: str, + expected: str, +) -> None: + """Check that get_input operates on the dict we provided.""" + assert Credential(inputs=inputs).get_input(key) is expected + + +@pytest.mark.parametrize( + ('inputs', 'key', 'expected'), + ( + pytest.param( + {'foo2': 'bar2'}, + 'foo2', + True, # noqa: WPS425 + id='key-present', + ), + pytest.param( + {'foo3': 'bar3'}, + 'baz', + False, # noqa: WPS425 + id='key-missing', + ), + ), +) +def test_credential_has_input( + inputs: dict[str, GenericOptionalPrimitiveType], + key: str, + expected: bool, +) -> None: + """Check that has_input behaves like dict in operator.""" + assert Credential(inputs=inputs).has_input(key) is expected