Esempio n. 1
0
def test_efc_from_env_variables(monkeypatch, schema):
    mock_env = {
        'LINOTP_FOO': "quux",
        'LINOTP_CFG': "doh",  # This should be ignored (reserved name)
        'LINOTP_QUUX': "xyzzy",  # This should also be ignored (not in schema)
    }
    monkeypatch.setattr(os, "environ", mock_env)
    cs = s.ConfigSchema(schema=schema)
    efc = ExtFlaskConfig("/", config_schema=cs)
    efc.from_env_variables()
    assert efc["FOO"] == "quux"
    assert "CFG" not in efc
    assert "QUUX" not in efc
Esempio n. 2
0
def test_efc_normal_get_second_arg_deprecated(caplog, default):
    # This test ensures that calling `ExtFlaskConfig.get()` with an
    # undefined value emits a warning. This is because we don't want
    # people to scatter random default values all over the code. For
    # the time being we don't raise an actual exception but we might
    # get to that in the future.

    efc = ExtFlaskConfig("/")
    caplog.clear()
    # with pytest.raises(s.LinOTPConfigKeyError) as ex:
    #     efc.get("FOO", default)
    assert efc.get("FOO", default) == default
    assert len(caplog.messages) == 1
    assert "violates the DRY principle" in caplog.messages[0]
Esempio n. 3
0
def test_efc_dunder_setitem_schema(schema, key, value, result, result_value):
    cs = s.ConfigSchema(schema=schema)
    efc = ExtFlaskConfig("/", config_schema=cs)
    if result == "OK":
        efc[key] = value
        assert efc[key] == result_value
    else:
        with pytest.raises(result) as ex:
            efc[key] = value
        assert result_value in str(ex.value)
Esempio n. 4
0
def test_efc_relative_file_hack(item_name):
    efc = ExtFlaskConfig("/")
    efc[item_name] = "quux"
    # We use a convoluted method to get at the actual value of `efc[…]`
    # because retrieving `efc[…]` directly will yield the result of
    # `os.path.join()`, which is a string.
    assert isinstance(
        super(ExtFlaskConfig, efc).__getitem__(item_name),
        ExtFlaskConfig.RelativePathName)
    # In real life, `ROOT_DIR` will be `app.root_path`, but we're not in an
    # app context here. This doesn't matter because we're only testing that
    # `ROOT_DIR` is prepended to a relative path name; the actual value of
    # `ROOT_DIR` is immaterial.
    assert efc[item_name] == "/ROOT_DIR_UNSET/./quux"
    efc[item_name] = "/quux"
    assert efc[item_name] == "/quux"  # nothing prepended
Esempio n. 5
0
 def __init__(self):
     self.config = ExtFlaskConfig("/ROOT_PATH")
     self.root_path = "/ROOT_PATH"
Esempio n. 6
0
def test_efc_root_dir():
    # Security blanket to make sure asking for `config['ROOT_DIR']`
    # doesn't cause an infinite regression.
    efc = ExtFlaskConfig("/")
    efc["ROOT_DIR"] = "/etc/linotp"
    assert efc["ROOT_DIR"] == "/etc/linotp"
Esempio n. 7
0
def test_efc_relative_file_hack_get():
    efc = ExtFlaskConfig("/")
    efc["FOO_DIR"] = "bar"
    assert efc.get("FOO_DIR") == "/ROOT_DIR_UNSET/./bar"
    efc["FOO_DIR"] = "/bar"
    assert efc.get("FOO_DIR") == "/bar"
Esempio n. 8
0
def test_efc_normal_get():
    efc = ExtFlaskConfig("/")
    efc["FOO"] = "bar"
    assert efc["FOO"] == efc.get("FOO")
Esempio n. 9
0
def test_efc_relative_file_hack_btd():
    efc = ExtFlaskConfig("/")
    BTD = "BABEL_TRANSLATION_DIRECTORIES"
    efc[BTD] = "foo;/bar/baz"
    assert efc[BTD] == "/ROOT_DIR_UNSET/./foo;/bar/baz"
Esempio n. 10
0
def test_efc_dunder_setitem_getitem_no_schema():
    """This tests the simplest code path."""
    efc = ExtFlaskConfig("/")
    efc["FOO"] = "bar"
    assert super(ExtFlaskConfig, efc).__getitem__("FOO") == "bar"
    assert efc["FOO"] == "bar"
Esempio n. 11
0
def test_efc_set_schema(schema):
    cs = s.ConfigSchema(schema=schema)
    efc = ExtFlaskConfig("/")
    assert efc.config_schema is None
    efc.set_schema(cs)
    assert efc.config_schema == cs