Esempio 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)
Esempio 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())
Esempio 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"
Esempio 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"
Esempio 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
Esempio 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
Esempio 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
Esempio 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"
Esempio 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'>"