Beispiel #1
0
def test_read_yaml_string_with_env_var_not_exist():
    config_with_env_var_not_exist = """
    user: ${USER_NAME}
    password: ${PASSWORD}
    """
    with pytest.raises(ValueError):
        utils.read_yaml_string(config_with_env_var_not_exist)
Beispiel #2
0
def test_read_yaml_string_with_env_var_infix():
    config_with_env_var_infix = """
    user: db_${USER_NAME}_admin
    password: db_${PASS}_admin
    """
    r = utils.read_yaml_string(config_with_env_var_infix)
    assert r['user'] == 'db_user_admin' and r['password'] == 'db_pass_admin'
Beispiel #3
0
def test_read_yaml_string_with_multiple_env_vars_per_line():
    config_with_env_var = """
    user: ${USER_NAME} ${PASS}
    password: ${PASS}
    """
    r = utils.read_yaml_string(config_with_env_var)
    assert r['user'] == 'user pass' and r['password'] == 'pass'
Beispiel #4
0
def test_read_yaml_string_with_env_var():
    config_with_env_var = """
    user: ${USER_NAME}
    password: ${PASS}
    """
    r = utils.read_yaml_string(config_with_env_var)
    assert r['user'] == 'user' and r['password'] == 'pass'
Beispiel #5
0
def test_read_yaml_string():
    config_without_env_var = """
    user: user
    password: pass
    """
    r = utils.read_yaml_string(config_without_env_var)
    assert r['user'] == 'user' and r['password'] == 'pass'
Beispiel #6
0
    def validate_domain_yaml(cls, yaml):
        """Validate domain yaml."""
        from pykwalify.core import Core

        log = logging.getLogger('pykwalify')
        log.setLevel(logging.WARN)

        schema_file = pkg_resources.resource_filename(__name__,
                                                      "schemas/domain.yml")
        source_data = utils.read_yaml_string(yaml)
        c = Core(source_data=source_data, schema_files=[schema_file])
        try:
            c.validate(raise_exception=True)
        except SchemaError:
            raise InvalidDomain("Failed to validate your domain yaml. "
                                "Make sure the file is correct, to do so"
                                "take a look at the errors logged during "
                                "validation previous to this exception. ")
Beispiel #7
0
 def from_yaml(cls, yaml):
     cls.validate_domain_yaml(yaml)
     data = read_yaml_string(yaml)
     return cls.from_dict(data)