How to use the dynaconf.loaders.json_loader.load function in dynaconf

To help you get started, weā€™ve selected a few dynaconf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rochacbruno / dynaconf / tests / test_json_loader.py View on Github external
def test_empty_value():
    load(settings, filename="")
github rochacbruno / dynaconf / tests / test_json_loader.py View on Github external
def test_key_error_on_invalid_env():
    """Assert error raised if env is not found in JSON"""
    with pytest.raises(KeyError):
        load(settings, filename=JSON, env="FOOBAR", silent=False)
github rochacbruno / dynaconf / tests / test_json_loader.py View on Github external
def test_no_key_error_on_invalid_env():
    """Assert error raised if env is not found in JSON"""
    load(settings, filename=JSON, env="FOOBAR", silent=True)
github rochacbruno / dynaconf / tests / test_json_loader.py View on Github external
def test_load_single_key():
    """Test loading a single key"""
    _JSON = """
    {
      "foo": {
        "bar": "blaz",
        "zaz": "naz"
      }
    }
    """
    load(settings, filename=_JSON, env="FOO", key="bar")
    assert settings.BAR == "blaz"
    assert settings.exists("BAR") is True
    assert settings.exists("ZAZ") is False
github rochacbruno / dynaconf / tests / test_json_loader.py View on Github external
def test_no_filename_is_none():
    """Assert if passed no filename return is None"""
    assert load(settings) is None
github rochacbruno / dynaconf / tests / test_json_loader.py View on Github external
def test_load_from_json():
    """Assert loads from JSON string"""
    load(settings, filename=JSON)
    assert settings.HOST == "prodserver.com"
    assert settings.PORT == 8080
    assert settings.ALIST == ["item1", "item2", 23]
    assert settings.SERVICE["url"] == "service.com"
    assert settings.SERVICE.url == "service.com"
    assert settings.SERVICE.port == 80
    assert settings.SERVICE.auth.password == "qwerty"
    assert settings.SERVICE.auth.test == 1234
    load(settings, filename=JSON, env="DEVELOPMENT")
    assert settings.HOST == "devserver.com"
    load(settings, filename=JSON)
    assert settings.HOST == "prodserver.com"
github rochacbruno / dynaconf / tests / test_json_loader.py View on Github external
def test_cleaner():
    load(settings, filename=JSON)
    assert settings.HOST == "prodserver.com"
    assert settings.PORT == 8080
    assert settings.ALIST == ["item1", "item2", 23]
    assert settings.SERVICE["url"] == "service.com"
    assert settings.SERVICE.url == "service.com"
    assert settings.SERVICE.port == 80
    assert settings.SERVICE.auth.password == "qwerty"
    assert settings.SERVICE.auth.test == 1234
    load(settings, filename=JSON, env="DEVELOPMENT")
    assert settings.HOST == "devserver.com"
    load(settings, filename=JSON)
    assert settings.HOST == "prodserver.com"

    settings.clean()
    with pytest.raises(AttributeError):
        assert settings.HOST == "prodserver.com"
github rochacbruno / dynaconf / tests / test_json_loader.py View on Github external
def test_multiple_filenames():
    load(settings, filename="a.json,b.json,c.json,d.json")
github rochacbruno / dynaconf / tests / test_json_loader.py View on Github external
def test_load_dunder():
    """Test loading with dunder settings"""
    _JSON = """
    {
      "foo": {
        "colors__yellow__code": "#FFCC00",
        "COLORS__yellow__name": "Yellow"
      }
    }
    """
    load(settings, filename=_JSON, env="FOO")
    assert settings.COLORS.yellow.code == "#FFCC00"
    assert settings.COLORS.yellow.name == "Yellow"
github rochacbruno / dynaconf / tests / test_json_loader.py View on Github external
def test_cleaner():
    load(settings, filename=JSON)
    assert settings.HOST == "prodserver.com"
    assert settings.PORT == 8080
    assert settings.ALIST == ["item1", "item2", 23]
    assert settings.SERVICE["url"] == "service.com"
    assert settings.SERVICE.url == "service.com"
    assert settings.SERVICE.port == 80
    assert settings.SERVICE.auth.password == "qwerty"
    assert settings.SERVICE.auth.test == 1234
    load(settings, filename=JSON, env="DEVELOPMENT")
    assert settings.HOST == "devserver.com"
    load(settings, filename=JSON)
    assert settings.HOST == "prodserver.com"

    settings.clean()
    with pytest.raises(AttributeError):
        assert settings.HOST == "prodserver.com"