示例#1
0
def test_resolve(mocker: MockFixture):
    ssm: s.SecretManager = MagicMock(spec=s.SecretManager)
    handshake: h.Handshake = h.Handshake(ssm=ssm)
    resolve: MagicMock = mocker.patch.object(ssm, "resolve")
    resolve.return_value = "expected"
    actual = handshake._resolve("key to resolve")
    assert "expected" == actual
示例#2
0
def test_get_uncached_none(mocker: MockFixture):
    handshake: h.Handshake = h.Handshake(cache={})

    resolve = mocker.patch.object(handshake, "_resolve")
    resolve.return_value = None

    with raises(h.UnableToAccessParameter):
        handshake._get("key to resolve")
示例#3
0
def _do_basic_get_test(mocker: MockFixture, expected: str, input: str, quote: bool):
    handshake: h.Handshake = h.Handshake(cache={})

    resolve = mocker.patch.object(handshake, "_resolve")
    resolve.return_value = input

    actual: str = handshake._get("key to resolve", quote=quote)
    assert actual == expected
示例#4
0
def test_clone_twice_resolves_once(mocker: MockFixture):
    paths: Dict = { "parameter": "SSM path (relative to profile namespace)" }
    _paths: MagicMock = mocker.patch.object(h, "_paths")
    _paths.return_value = paths
    ssm: s.SecretManager = MagicMock(spec=s.SecretManager)
    handshake: h.Handshake = h.Handshake(ssm=ssm)
    ssm.resolve.return_value = "resolved parameter value"
    handshake.clone()
    handshake.clone()
    ssm.resolve.assert_called_once_with("SSM path (relative to profile namespace)")
示例#5
0
def test_force_resolves_as_needed(mocker: MockFixture):
    paths: Dict = {
        "parameter 1": "cached",
        "parameter 2": "uncached"
    }
    _paths: MagicMock = mocker.patch.object(h, "_paths")
    _paths.return_value = paths
    ssm: s.SecretManager = MagicMock(spec=s.SecretManager)
    handshake: h.Handshake = h.Handshake(ssm=ssm)
    handshake._cache["cached"] = "cached value"
    handshake.clone()
    ssm.resolve.assert_called_once_with("uncached")
示例#6
0
def test_clone_omits_ssm(mocker: MockFixture):
    cache: Dict = MagicMock(spec=Dict)
    handshake: h.Handshake = h.Handshake(cache=cache)
    mocker.patch.object(handshake, "_force")
    cloned: h.Handshake = handshake.clone()
    assert cloned._ssm is None
示例#7
0
def test_clone_forces(mocker: MockFixture):
    cache: Dict = MagicMock(spec=Dict)
    handshake: h.Handshake = h.Handshake(cache=cache)
    force: MagicMock = mocker.patch.object(handshake, "_force")
    handshake.clone()
    force.assert_called_once_with()
示例#8
0
def test_handshake_cache():
    cache: Dict = MagicMock(spec=Dict)
    handshake: h.Handshake = h.Handshake(cache=cache)
    assert cache == handshake._cache
    assert handshake._ssm is None
示例#9
0
def test_get_cached_none():
    cache: Dict = {"key to resolve": None}
    handshake: h.Handshake = h.Handshake(cache=cache)

    with raises(h.UnableToAccessParameter):
        handshake._get("key to resolve")
示例#10
0
def test_get_cached():
    cache: Dict = {"key to resolve": "expected"}
    handshake: h.Handshake = h.Handshake(cache=cache)

    actual: str = handshake._get("key to resolve")
    assert "expected" == actual
示例#11
0
def test_neither_ssm_nor_cache_raises():
    with raises(AssertionError):
        h.Handshake()
示例#12
0
def test_ssm_and_cache_raises():
    with raises(AssertionError):
        ssm: s.SecretManager = MagicMock(spec=s.SecretManager)
        cache: Dict = MagicMock(spec=Dict)
        h.Handshake(ssm=ssm, cache=cache)
示例#13
0
def test_handshake_ssm():
    ssm: s.SecretManager = MagicMock(spec=s.SecretManager)
    handshake: h.Handshake = h.Handshake(ssm=ssm)
    assert ssm == handshake._ssm
    assert {} == handshake._cache