Exemplo n.º 1
0
def test_reload():  # type: ignore
    secretmanager.SecretManagerServiceClient = fake_client(DICT)
    cfg = GCPSecretManagerConfiguration("fake_id")
    assert cfg == config_from_dict(DICT)

    cfg._client = FakeSecretClient(DICT2)
    cfg.reload()
    assert cfg == config_from_dict(DICT2)
Exemplo n.º 2
0
def test_dict():  # type: ignore
    d = DICT.copy()
    secretmanager.SecretManagerServiceClient = fake_client(d)
    cfg = GCPSecretManagerConfiguration("fake_id", cache_expiration=0)

    assert sorted(cfg.keys()) == sorted(d.keys())
    assert sorted(cfg.values()) == sorted(d.values())
    assert sorted(cfg.items()) == sorted(d.items())
Exemplo n.º 3
0
def test_load_dict():  # type: ignore
    secretmanager.SecretManagerServiceClient = fake_client(DICT)
    cfg = GCPSecretManagerConfiguration("fake_id")

    print(cfg)

    assert cfg["foo"] == "foo_val"
    assert cfg["with_underscore"] == "works"
    assert cfg.get("foo", "default") == "foo_val"
Exemplo n.º 4
0
def test_missing_key():  # type: ignore
    d = DICT.copy()
    secretmanager.SecretManagerServiceClient = fake_client(d)
    cfg = GCPSecretManagerConfiguration("fake_id", cache_expiration=0)

    with raises(KeyError):
        assert cfg["foo-missing"] is KeyError

    assert cfg.get("foo-missing", "default") == "default"
Exemplo n.º 5
0
def test_expiration(mocker):  # type: ignore
    # with cache
    secretmanager.SecretManagerServiceClient = fake_client(DICT)
    cfg = GCPSecretManagerConfiguration("fake_id")

    spy = mocker.spy(cfg._client, "access_secret_version")
    assert cfg["foo"] == "foo_val"
    assert cfg["foo"] == "foo_val"
    assert spy.call_count == 1

    # without cache
    secretmanager.SecretManagerServiceClient = fake_client(DICT)
    cfg = GCPSecretManagerConfiguration("fake_id", cache_expiration=0)

    spy = mocker.spy(cfg._client, "access_secret_version")
    assert cfg["foo"] == "foo_val"
    assert cfg["foo"] == "foo_val"  # this will ignore the cache
    assert spy.call_count == 2
Exemplo n.º 6
0
def test_get_attr():  # type: ignore
    d = DICT.copy()
    secretmanager.SecretManagerServiceClient = fake_client(d)
    cfg = GCPSecretManagerConfiguration("fake_id", cache_expiration=0)

    assert cfg.foo == "foo_val"

    with raises(KeyError):
        assert cfg.foo_missing is KeyError
Exemplo n.º 7
0
def test_deletion():  # type: ignore
    d = DICT.copy()
    secretmanager.SecretManagerServiceClient = fake_client(d)
    cfg = GCPSecretManagerConfiguration("fake_id", cache_expiration=0)

    assert cfg["foo"] == "foo_val"
    assert "foo" in cfg._cache
    del d["foo"]

    with raises(KeyError):
        assert cfg["foo"] is KeyError
Exemplo n.º 8
0
def test_str():  # type: ignore
    d = DICT.copy()
    secretmanager.SecretManagerServiceClient = fake_client(d)
    cfg = GCPSecretManagerConfiguration("fake_id", cache_expiration=0)

    # str
    assert (
        str(cfg) ==
        "{'bar': 'bar_val', 'foo': 'foo_val', 'password': '******', 'with_underscore': 'works'}"
    )
    assert cfg["password"] == "some passwd"
Exemplo n.º 9
0
def test_repr():  # type: ignore
    d = DICT.copy()
    secretmanager.SecretManagerServiceClient = fake_client(d)
    cfg = GCPSecretManagerConfiguration("fake_id", cache_expiration=0)

    assert repr(cfg) == "<GCPSecretManagerConfiguration: 'fake_id'>"