Example #1
0
def test_generate_validation_report():
    # Empty
    this_conf, validation_results = config.read_mediagoblin_config(
        CARROT_CONF_EMPTY, FAKE_CONFIG_SPEC)
    report = config.generate_validation_report(this_conf, validation_results)
    assert report is None

    # Good
    this_conf, validation_results = config.read_mediagoblin_config(
        CARROT_CONF_GOOD, FAKE_CONFIG_SPEC)
    report = config.generate_validation_report(this_conf, validation_results)
    assert report is None

    # Bad
    this_conf, validation_results = config.read_mediagoblin_config(
        CARROT_CONF_BAD, FAKE_CONFIG_SPEC)
    report = config.generate_validation_report(this_conf, validation_results)

    assert report.startswith("""\
There were validation problems loading this config file:
--------------------------------------------------------""")

    expected_warnings = [
        'carrotapp:carrotcake = the value "slobber" is of the wrong type.',
        'carrotapp:num_carrots = the value "GROSS" is of the wrong type.',
        'celery:EAT_CELERY_WITH_CARROTS = the value "pants" is of the wrong type.']
    warnings = report.splitlines()[2:]

    assert len(warnings) == 3
    for warning in expected_warnings:
        assert warning in warnings
Example #2
0
def test_generate_validation_report():
    # Empty
    this_conf, validation_results = config.read_mediagoblin_config(CARROT_CONF_EMPTY, FAKE_CONFIG_SPEC)
    report = config.generate_validation_report(this_conf, validation_results)
    assert report is None

    # Good
    this_conf, validation_results = config.read_mediagoblin_config(CARROT_CONF_GOOD, FAKE_CONFIG_SPEC)
    report = config.generate_validation_report(this_conf, validation_results)
    assert report is None

    # Bad
    this_conf, validation_results = config.read_mediagoblin_config(CARROT_CONF_BAD, FAKE_CONFIG_SPEC)
    report = config.generate_validation_report(this_conf, validation_results)

    assert report.startswith(
        """\
There were validation problems loading this config file:
--------------------------------------------------------"""
    )

    expected_warnings = [
        'carrotapp:carrotcake = the value "slobber" is of the wrong type.',
        'carrotapp:num_carrots = the value "GROSS" is of the wrong type.',
        'celery:EAT_CELERY_WITH_CARROTS = the value "pants" is of the wrong type.',
    ]
    warnings = report.splitlines()[2:]

    assert len(warnings) == 3
    for warning in expected_warnings:
        assert warning in warnings
Example #3
0
def setup_global_and_app_config(config_path):
    global_config, validation_result = read_mediagoblin_config(config_path)
    app_config = global_config["mediagoblin"]
    # report errors if necessary
    validation_report = generate_validation_report(global_config, validation_result)
    if validation_report:
        raise ImproperlyConfigured(validation_report)

    setup_globals(app_config=app_config, global_config=global_config)

    return global_config, app_config
Example #4
0
def setup_global_and_app_config(config_path):
    global_config, validation_result = read_mediagoblin_config(config_path)
    app_config = global_config['mediagoblin']
    # report errors if necessary
    validation_report = generate_validation_report(global_config,
                                                   validation_result)
    if validation_report:
        raise ImproperlyConfigured(validation_report)

    setup_globals(app_config=app_config, global_config=global_config)

    return global_config, app_config