Example #1
0
def load_config(config_path, environment_name):
    """Helper method for loading a :py:class:`~alarmageddon.config.Config`

    :param config_path: Path to the JSON configuration file.
    :param environment_name: The config environment to run Alarmageddon in.

    """
    return Config.from_file(config_path, environment_name)
Example #2
0
def create_configuration(template_directory,
                         environment_name="test",
                         config_key="email_notifications",
                         smtp_host=None,
                         smtp_port=None,
                         subject_template_name=None,
                         subject_template_content=None,
                         body_template_name=None,
                         body_template_content=None):
    """ Create a complete test configuration using the specified parameters
        template_directory - [Required] A directory location for templates.
                                        Must be a py.path.local object.
        environment_name - [Optional] The name of the environment.
                                      Corresponds to environment-specific email
                                      configuration. Defaults to "test".
        config_key - [Optional] The email notification config section key.
                                Defaults to "email_notifications".
        smtp_host - [Optional] SMTP server host name. Must be a string.
                               Defaults to null value.
        smtp_port - [Optional] SMTP server port number. Must be an integer.
                               Defaults to null value.
        subject_template_name - [Optional] The name of the template to create.
                                           Defaults to
                                           "default_subject.template".
        subject_template_content - [Optional] Allows tests to override default
                                              content written to the template.
                                              Must be a valid string. Defaults
                                              to the default.template.
        body_template_name - [Optional] The name of the template to create.
                                        Defaults to "default_subject.template".
        body_template_content - [Optional] Allows tests to override default
                                           content written to the template.
                                           Must be a valid string. Defaults to
                                           the default template.
    """
    email_template_directory = template_directory.mkdir("email_templates")

    body_template = create_body_template(email_template_directory,
                                         body_template_name,
                                         body_template_content)
    subject_template = create_subject_template(email_template_directory,
                                               subject_template_name,
                                               subject_template_content)

    json_config = create_json_config(str(email_template_directory),
                                     environment_name, config_key,
                                     smtp_host, smtp_port,
                                     body_template, subject_template)
    config = Config(json.loads(json_config), environment_name)

    return config
Example #3
0
def test_config_gets_correct_host_stable(conf):
    c = Config(conf, "stable")
    assert c.hostname("service") == "http://www.stable.com"
Example #4
0
def test_config_gets_correct_host_bad_service(conf):
    c = Config(conf, "stable")
    with pytest.raises(KeyError):
        c.hostname("wrong")
Example #5
0
def test_config_incorrect_environment(conf):
    c = Config(conf, "prod")
    with pytest.raises(ValueError):
        c = Config(conf, "foo")
Example #6
0
def test_config_gets_correct_host_prod(conf):
    c = Config(conf, "prod")
    assert c.hostname("service") == "http://www.prod.com"
Example #7
0
def test_config_returns_values(conf):
    c = Config(conf, "prod")
    assert c.values() == conf.values()
Example #8
0
def test_config_correct_environment(conf):
    c = Config(conf, "prod")
    assert c.environment_name() == "prod"
Example #9
0
def test_config_returns_keys(conf):
    c = Config(conf, "prod")
    assert c.keys() == conf.keys()
Example #10
0
def test_config_gets_nested_value(conf):
    c = Config(conf, "prod")
    assert c["sub"]["value"] == 42
Example #11
0
def test_config_gets_missing_value_as_none(conf):
    c = Config(conf, "prod")
    assert c.get("missing") is None
Example #12
0
def test_config_gets_missing_value(conf):
    c = Config(conf, "prod")
    with pytest.raises(KeyError):
        c["missing"]
Example #13
0
def test_config_gets_simple_value(conf):
    c = Config(conf, "prod")
    assert c["foo"] == 'bar'