def test_get_key_wrong_default_type(): g = gestalt.Gestalt() g.add_config_path('./tests/testdata') g.build_config() with pytest.raises(TypeError) as terr: g.get_string('nonexist', 1234) assert 'Provided default is of incorrect type' in terr
def test_get_json_set_default_string(): g = gestalt.Gestalt() g.add_config_path('./tests/testdata') g.build_config() g.set_default_string('nonexisttest', 'otherdefval') testval = g.get_string('nonexisttest') assert testval == 'otherdefval'
def test_get_key_wrong_type(): g = gestalt.Gestalt() g.add_config_path('./tests/testdata') g.build_config() with pytest.raises(TypeError) as terr: g.get_string(1234) assert 'is not of string type' in terr
def test_loading_file_bad_json(): g = gestalt.Gestalt() with pytest.raises(ValueError) as terr: g.add_config_file('./tests/testdatabad/testjson.json') g.build_config() assert terr.type is ValueError assert 'but cannot be read as such' in terr.value.args[0]
def test_loading_dir_bad_files_yaml_only(): g = gestalt.Gestalt() with pytest.raises(ValueError) as terr: g.add_config_path('./tests/testdatabadyaml') g.build_config() assert terr.type is ValueError assert 'but cannot be read as such' in terr.value.args[0]
def test_set_list(): g = gestalt.Gestalt() g.set_list('mykey', ['hi', 'bye']) testval = g.get_list('mykey') assert testval assert 'hi' in testval assert 'bye' in testval
def test_set_default_list(): g = gestalt.Gestalt() g.set_default_list('mykey', ['bear', 'bull']) testval = g.get_list('mykey') assert testval assert 'bear' in testval assert 'bull' in testval
def test_set_default_bad_type_file_config(): g = gestalt.Gestalt() g.add_config_path('./tests/testdata') g.build_config() with pytest.raises(TypeError) as terr: g.set_default_string('numbers', 'notgood') assert 'File config has' in terr
def test_vault_mount_path(env_setup, mount_setup): g = gestalt.Gestalt() g.add_config_file("./tests/testvault/testmount.json") g.configure_provider("vault", Vault(role=None, jwt=None)) g.build_config() secret = g.get_string("test_mount.test_mount") assert secret == "test_mount_password"
def test_get_env_bad_type(): g = gestalt.Gestalt() g.auto_env() os.environ['MY_KEY'] = 'myval' with pytest.raises(TypeError) as terr: g.get_int('my.key') assert "could not be converted to type" in terr
def test_get_non_exist_key(): g = gestalt.Gestalt() g.add_config_path('./tests/testdata') g.build_config() with pytest.raises(ValueError) as terr: g.get_string('non-exist') assert 'is not in any configuration and no default is provided' in terr
def test_vault_interpolation(secret_setup): g = gestalt.Gestalt() g.add_config_file("./tests/testvault/testcorrect.json") vault = Vault(role=None, jwt=None) g.configure_provider("vault", vault) g.build_config() secret = g.get_string("test_secret.test_secret") assert secret == "test_secret_password"
def test_set_vault_key(env_setup, nested_setup): g = gestalt.Gestalt() g.configure_provider("vault", Vault(role=None, jwt=None)) g.set_string(key="test", value="ref+vault://secret/data/testnested#.slack.token") g.build_config() secret = g.get_string("test") assert secret == "random-token"
def test_get_json_list(): g = gestalt.Gestalt() g.add_config_path('./tests/testdata') g.build_config() testval = g.get_list('listing') assert testval assert 'dog' in testval assert 'cat' in testval
def test_set_override(): g = gestalt.Gestalt() g.add_config_path('./tests/testdata') g.build_config() testval = g.get_int('numbers') assert testval == 12345678 g.set_int('numbers', 6543) testval = g.get_int('numbers') assert testval == 6543
def test_override_nested_config(): g = gestalt.Gestalt() g.add_config_path('./tests/testoverride/') g.build_config() assert g.get_int("local") == 123456 assert g.get_string("nested1.nested2") == "final" assert g.get_string("pg.host") == "dev_host" assert g.get_string("pg.pass") == "def_pass" assert g.get_string("nested1.nested3.nested4.deeplevel") == "nested5"
def test_nest_key_for_vault(env_setup, nested_setup): g = gestalt.Gestalt() g.add_config_file("./tests/testvault/testnested.json") g.configure_provider("vault", Vault(role=None, jwt=None)) g.build_config() secret_db = g.get_string("remoteAPI.database.test_secret") secret_slack = g.get_string("remoteAPI.slack.token") assert secret_db == "test_secret_password" assert secret_slack == "random-token"
def test_set_default_string_bad_val(): g = gestalt.Gestalt() with pytest.raises(TypeError) as terr: g.set_default_string('mykey', 123) assert 'Input value when setting default' in terr
def test_loading_file_nonexist(): g = gestalt.Gestalt() with pytest.raises(ValueError) as terr: g.add_config_file('./tests/testdata/nothere.yaml') g.build_config() assert 'is not a file' in terr
def test_loading_file_dir(): g = gestalt.Gestalt() with pytest.raises(ValueError) as terr: g.add_config_file('./tests/testdata') assert 'is not a file' in terr
def test_loading_json_file(): g = gestalt.Gestalt() g.add_config_file('./tests/testdata/testjson.json') g.build_config() x = g.dump() assert len(x)
def test_set_default_string(): g = gestalt.Gestalt() g.set_default_string('mykey', 'myval') testval = g.get_string('mykey') assert testval == 'myval'
def test_vault_incorrect_path(env_setup, mount_setup): g = gestalt.Gestalt() g.add_config_file("./tests/testvault/testincorrectmount.json") g.configure_provider("vault", Vault(role=None, jwt=None)) with pytest.raises(RuntimeError): g.build_config()
def test_loading_json(): g = gestalt.Gestalt() g.add_config_path('./tests/testdata') g.build_config() x = g.dump() assert len(x)
def test_set_default_float(): g = gestalt.Gestalt() g.set_default_float('mykey', 1234.05) testval = g.get_float('mykey') assert testval == 1234.05
def test_set_default_bool(): g = gestalt.Gestalt() g.set_default_bool('mykey', False) testval = g.get_bool('mykey') assert testval is False
def test_set_default_bad_type_set_config(): g = gestalt.Gestalt() g.set_string('mykey', 'mystring') with pytest.raises(TypeError) as terr: g.set_default_int('mykey', 123) assert 'Set config has' in terr
def test_set_default_int_get_bad(): g = gestalt.Gestalt() g.set_default_int('mykey', 1234) with pytest.raises(TypeError) as terr: g.get_string('mykey') assert 'Given default set key is not of type' in terr
def test_set_default_string_bad_key(): g = gestalt.Gestalt() with pytest.raises(TypeError) as terr: g.set_default_string(1234, 'myval') assert 'Given key is not of string type' in terr
def test_set_default_string_bad_val_override(): g = gestalt.Gestalt() with pytest.raises(TypeError) as terr: g.set_default_string('mykey', 'myval') g.set_default_int('mykey', 1234) assert 'Overriding default key' in terr