Skip to content

Commit

Permalink
Add tests for new Credential private api class
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismeyersfsu committed Nov 20, 2024
1 parent ea1a4d8 commit f509c74
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/awx_plugins/interfaces/_temporary_private_credential_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ class Credential:
Satisfies ManagedCredentialType inputs want(s).
"""

def __init__(self: 'Credential') -> None:
self._inputs: dict[str, GenericOptionalPrimitiveType] = {}
def __init__(
self: 'Credential',
inputs: dict[
str,
GenericOptionalPrimitiveType,
] | None = None,
) -> None:
self._inputs: dict[str, GenericOptionalPrimitiveType] = inputs or {}

def get_input(
self: 'Credential',
Expand Down
34 changes: 34 additions & 0 deletions tests/_temporary_private_credential_api_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Tests for the temporarily hosted private helpers."""

import pytest

from awx_plugins.interfaces._temporary_private_credential_api import Credential


def test_credential_instantiation() -> None:
"""Check that credential type can be instantiated."""
assert Credential()


@pytest.mark.parametrize(
('inputs', 'key', 'expected'),
(
({'foo': 'bar'}, 'foo', 'bar'),
({'foo': 'bar'}, 'baz', None)
)
)
def test_credential_get_input(inputs, key, expected) -> None:
"""Check that get_input operates on the dict we provided in the constructor."""
assert Credential(inputs=inputs).get_input(key) == expected


@pytest.mark.parametrize(
('inputs', 'key', 'expected'),
(
({'foo': 'bar'}, 'foo', True),
({'foo': 'bar'}, 'baz', False)
)
)
def test_credential_has_input(inputs, key, expected) -> None:
"""Check that has_input behaves like dict in operator."""
Credential(inputs=inputs).has_input(key) == expected

0 comments on commit f509c74

Please sign in to comment.