예제 #1
0
def test_using_env(tmpdir):
    load(settings, filename=JSON)
    assert settings.HOST == "prodserver.com"

    tmpfile = tmpdir.mkdir("sub").join("test_using_env.json")
    tmpfile.write(JSON)
    with settings.using_env("DEVELOPMENT", filename=str(tmpfile)):
        assert settings.HOST == "devserver.com"
    assert settings.HOST == "prodserver.com"
예제 #2
0
def test_envless():
    settings = LazySettings()
    _json = """
    {
        "colors__yellow__code": "#FFCC00",
        "COLORS__yellow__name": "Yellow"
    }
    """
    load(settings, filename=_json)
    assert settings.COLORS.yellow.code == "#FFCC00"
    assert settings.COLORS.yellow.name == "Yellow"
예제 #3
0
def test_prefix():
    settings = LazySettings(filter_strategy=PrefixFilter("prefix"))
    _json = """
    {
        "prefix_colors__yellow__code": "#FFCC00",
        "COLORS__yellow__name": "Yellow"
    }
    """
    load(settings, filename=_json)
    assert settings.COLORS.yellow.code == "#FFCC00"
    with pytest.raises(AttributeError):
        settings.COLORS.yellow.name
예제 #4
0
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"
예제 #5
0
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
예제 #6
0
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
예제 #7
0
def test_load_from_multiple_json():
    """Assert loads from JSON string"""
    load(settings, filename=JSONS)
    assert settings.HOST == "otherjson.com"
    assert settings.PASSWORD == 123456
    assert settings.SECRET == 42.0
    assert settings.PORT == 8080
    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=JSONS, env="DEVELOPMENT")
    assert settings.PORT == 8080
    assert settings.HOST == "otherjson.com"
    load(settings, filename=JSONS)
    assert settings.HOST == "otherjson.com"
    assert settings.PASSWORD == 123456
    load(settings, filename=JSON, env="DEVELOPMENT")
    assert settings.PORT == 8080
    assert settings.HOST == "devserver.com"
    load(settings, filename=JSON)
    assert settings.HOST == "prodserver.com"
    assert settings.PASSWORD == 11111
예제 #8
0
def test_load_from_multiple_json():
    """Assert loads from JSON string"""
    load(settings, filename=JSONS)
    assert settings.HOST == 'otherjson.com'
    assert settings.PASSWORD == 123456
    assert settings.SECRET == 42.0
    assert settings.PORT == 8080
    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=JSONS, env='DEVELOPMENT')
    assert settings.PORT == 8080
    assert settings.HOST == 'otherjson.com'
    load(settings, filename=JSONS)
    assert settings.HOST == 'otherjson.com'
    assert settings.PASSWORD == 123456
    load(settings, filename=JSON, env='DEVELOPMENT')
    assert settings.PORT == 8080
    assert settings.HOST == 'devserver.com'
    load(settings, filename=JSON)
    assert settings.HOST == 'prodserver.com'
    assert settings.PASSWORD == 11111
예제 #9
0
def test_cleaner():
    load(settings, filename=JSON)
    assert settings.HOST == 'server.com'
    assert settings.PORT == 8080
    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, namespace='DEVELOPMENT')
    assert settings.HOST == 'dev_server.com'
    load(settings, filename=JSON)
    assert settings.HOST == 'server.com'
    clean(settings, settings.namespace)
예제 #10
0
def test_load_from_json():
    """Assert loads from JSON string"""
    load(settings, filename=JSON)
    assert settings.HOST == 'server.com'
    assert settings.PORT == 8080
    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, namespace='DEVELOPMENT')
    assert settings.HOST == 'dev_server.com'
    load(settings, filename=JSON)
    assert settings.HOST == 'server.com'
예제 #11
0
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"
예제 #12
0
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'
예제 #13
0
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"
예제 #14
0
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'
예제 #15
0
def test_key_error_on_invalid_namespace():
    """Assert error raised if namespace is not found in JSON"""
    with pytest.raises(KeyError):
        load(settings, filename=JSON, namespace='FOOBAR', silent=False)
예제 #16
0
def test_no_key_error_on_invalid_namespace():
    """Assert error raised if namespace is not found in JSON"""
    load(settings, filename=JSON, namespace='FOOBAR', silent=True)
예제 #17
0
def test_multiple_filenames():
    load(settings, filename="a.json,b.json,c.json,d.json")
예제 #18
0
def test_empty_value():
    load(settings, filename="")
예제 #19
0
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)
예제 #20
0
def test_no_filename_is_none():
    """Assert if passed no filename return is None"""
    assert load(settings) is None
예제 #21
0
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)