Пример #1
0
def test_run_secret_without_env_var_set_raises_with_cast(monkeypatch):
    monkeypatch.delenv("FOO", raising=False)
    e = EnvVarSecret(env_var="FOO", raise_if_missing=True, cast=int)
    with pytest.raises(ValueError, match="variable not set"):
        e.run()
Пример #2
0
def test_run_secret_with_cast_datetime(monkeypatch):
    monkeypatch.setenv("FOO", "2019-01-02 03:04:05")
    e = EnvVarSecret(env_var="FOO", cast=pendulum.parse)
    assert e.run() == pendulum.datetime(2019, 1, 2, 3, 4, 5)
Пример #3
0
def test_run_secret_with_cast(monkeypatch):
    monkeypatch.setenv("FOO", "1")
    e = EnvVarSecret(env_var="FOO", cast=int)
    assert e.run() == 1
Пример #4
0
def test_run_secret_without_env_var_set_returns_none_even_if_cast_set(
        monkeypatch):
    monkeypatch.delenv("FOO", raising=False)
    e = EnvVarSecret(env_var="FOO", cast=int)
    assert e.run() is None
Пример #5
0
def test_run_secret_without_name_set_raises(monkeypatch):
    monkeypatch.delenv("FOO", raising=False)
    e = EnvVarSecret(name="FOO", raise_if_missing=True)
    with pytest.raises(ValueError, match="variable not set"):
        e.run()
Пример #6
0
def test_run_secret(monkeypatch):
    monkeypatch.setenv("FOO", "1")
    e = EnvVarSecret(env_var="FOO")
    assert e.run() == "1"
Пример #7
0
def test_run_secret_with_new_name_at_runtime_and_raise_missing(monkeypatch):
    monkeypatch.setenv("FOO", "1")
    e = EnvVarSecret(name="FOO", raise_if_missing=True)
    with pytest.raises(ValueError, match="variable not set"):
        e.run(name="BAR")
Пример #8
0
def test_secret_raises_if_no_name_provided():
    e = EnvVarSecret()
    with pytest.raises(ValueError, match="secret name must be provided"):
        e.run()
Пример #9
0
def test_secret_name_set_at_runtime(monkeypatch):
    monkeypatch.setenv("FOO", "1")
    e = EnvVarSecret()
    assert e.run("FOO") == "1"
Пример #10
0
def test_run_secret_with_new_name_at_runtime(monkeypatch):
    monkeypatch.setenv("FOO", "1")
    e = EnvVarSecret(name="FOO")
    assert e.run(name="BAR") is None
Пример #11
0
def test_run_secret_without_name_set_returns_none(monkeypatch):
    monkeypatch.delenv("FOO", raising=False)
    e = EnvVarSecret(name="FOO")
    assert e.run() is None