Example #1
0
def test_validate_option_application():
    d = FULL_CONFIG_BASE.copy()
    d['application'] = {
        'image-dir': '/home/user/projects/web-app/images',
        'path': '/home/user/projects/web-app/module',
        'template-dir': '/home/user/projects/web-app/html',
        'classes':{
            'RootController': '/',
            'WikiController': '/wiki',
            'MediaController': '/media',
        }
    }
    cp = ConfigValidator(d)
    assert cp.validate_mandatory()
Example #2
0
def test_validate_sub_options_should_be_dict():
    d = FULL_CONFIG_BASE.copy()
    d['databases'] = {
        'classes': 213
    }
    cp = ConfigValidator(d)
    assert_invalid_option('classes', '213',
                          cp.validate_mandatory)
Example #3
0
def test_application_invalid_names_with_bad_characters():
    d = FULL_CONFIG_BASE.copy()
    d['application'] = {
        'fjkdas#@$%*kdfhagf': '/',
    }

    cp = ConfigValidator(d)
    assert_invalid_option('application', 'fjkdas#@$%*kdfhagf',
                          cp.validate_mandatory)
Example #4
0
def test_application_invalid_names_starting_with_number():
    d = FULL_CONFIG_BASE.copy()
    d['application'] = {
        '3kdjfbsff': '/',
    }

    cp = ConfigValidator(d)
    assert_invalid_option('application', '3kdjfbsff',
                          cp.validate_mandatory)
Example #5
0
def test_application_invalid_values_without_bar_at_start():
    d = FULL_CONFIG_BASE.copy()
    d['application'] = {
        'something': 'asd/',
    }

    cp = ConfigValidator(d)
    assert_invalid_option('something', 'asd/',
                          cp.validate_mandatory)
Example #6
0
def test_static_invalid_controller_name_weird_charactes():
    d = FULL_CONFIG_BASE.copy()
    d['static'] = {
        '%$*': 'sqlite://asdasd',
    }

    cp = ConfigValidator(d)
    assert_invalid_option('static', '%$*',
                          cp.validate_mandatory)
Example #7
0
def test_application_invalid_names_with_spaces():
    d = FULL_CONFIG_BASE.copy()
    d['application'] = {
        'path with spaces': '/',
    }

    cp = ConfigValidator(d)
    assert_invalid_option('application', 'path with spaces',
                          cp.validate_mandatory)
Example #8
0
def test_config_validator_validate_calls_validation_methods():
    mocker = Mox()
    cp = ConfigValidator({})
    cp.validate_mandatory = mocker.CreateMockAnything()
    cp.validate_optional = mocker.CreateMockAnything()

    cp.validate_mandatory()

    mocker.ReplayAll()
    cp.validate()
    mocker.VerifyAll()
    def configure(self):
        current_full_path = self.fs.current_dir()

        full_path = self.fs.current_dir("settings.yml")
        raw_yaml = self.fs.open(full_path, 'r').read()
        orig_dict = yaml.load(raw_yaml)

        validator = ConfigValidator(orig_dict)
        config = SpongeConfig(cherrypy.config, validator)
        config.setup_all(current_full_path)
Example #10
0
def test_application_invalid_controller_name_spaces():
    d = FULL_CONFIG_BASE.copy()
    d['application'] = {
        'classes':{
            'Controller With Spaces': '/',
        }
    }

    cp = ConfigValidator(d)
    assert_invalid_option('classes', 'Controller With Spaces',
                          cp.validate_mandatory)
Example #11
0
def test_application_invalid_controller_name_bad_characters():
    d = FULL_CONFIG_BASE.copy()
    d['application'] = {
        'classes':{
            '-040%$WeirdNameController': '/',
        }
    }

    cp = ConfigValidator(d)
    assert_invalid_option('classes', '-040%$WeirdNameController',
                          cp.validate_mandatory)
Example #12
0
def test_application_invalid_controller_name_numeral():
    d = FULL_CONFIG_BASE.copy()
    d['application'] = {
        'classes':{
            '5NumeralController': '/',
        }
    }

    cp = ConfigValidator(d)
    assert_invalid_option('classes', '5NumeralController',
                          cp.validate_mandatory)
Example #13
0
def test_controller_url_should_start_with_slash():
    d = FULL_CONFIG_BASE.copy()
    d['application'] = {
        'classes':{
            'Controller With Spaces': 'wee/',
        }
    }

    cp = ConfigValidator(d)
    assert_invalid_option('classes', 'Controller With Spaces',
                          cp.validate_mandatory)
Example #14
0
def test_invalid_mandatory_option_databases_none():
    d = FULL_CONFIG_BASE.copy()
    d['databases'] = None
    cp = ConfigValidator(d)
    assert_invalid_option('databases', None,
                          cp.validate_mandatory)
Example #15
0
def test_validate_mandatory_does_not_require_option_databases():
    d = FULL_CONFIG_BASE.copy()
    del d['databases']
    cp = ConfigValidator(d)
    cp.validate_mandatory()
Example #16
0
def test_validate_option_host():
    d = FULL_CONFIG_BASE.copy()
    d['host'] = '127.0.0.1'
    cp = ConfigValidator(d)
    assert cp.validate_mandatory()
Example #17
0
def test_validate_mandatory_requires_option_port():
    d = FULL_CONFIG_BASE.copy()
    del d['port']
    cp = ConfigValidator(d)
    assert_required_option('port', cp.validate_mandatory)
Example #18
0
def test_validate_mandatory_requires_option_application():
    d = FULL_CONFIG_BASE.copy()
    del d['application']
    cp = ConfigValidator(d)
    assert_required_option('application', cp.validate_mandatory)
Example #19
0
def test_any_value_stashes_vartype():
    av = ConfigValidator.AnyValue(bool)
    assert_equals(av.vartype, bool)
Example #20
0
def test_invalid_mandatory_option_static_string():
    d = FULL_CONFIG_BASE.copy()
    d['static'] = 'should_be_dict'
    cp = ConfigValidator(d)
    assert_invalid_option('static', 'should_be_dict',
                          cp.validate_mandatory)
Example #21
0
def test_invalid_mandatory_option_autoreload_string():
    d = FULL_CONFIG_BASE.copy()
    d['autoreload'] = 'should_be_bool'
    cp = ConfigValidator(d)
    assert_invalid_option('autoreload', 'should_be_bool',
                          cp.validate_mandatory)
Example #22
0
def test_invalid_mandatory_option_run_as():
    d = FULL_CONFIG_BASE.copy()
    d['run-as'] = 'blabla'
    cp = ConfigValidator(d)
    assert_invalid_option('run-as', 'blabla', cp.validate_mandatory)
Example #23
0
def test_invalid_mandatory_option_application_none():
    d = FULL_CONFIG_BASE.copy()
    d['application'] = None
    cp = ConfigValidator(d)
    assert_invalid_option('application', None,
                          cp.validate_mandatory)
Example #24
0
def test_validate_mandatory_does_not_requires_option_static():
    d = FULL_CONFIG_BASE.copy()
    del d['static']
    cp = ConfigValidator(d)
    cp.validate_mandatory()
Example #25
0
def test_invalid_mandatory_option_static_none():
    d = FULL_CONFIG_BASE.copy()
    d['static'] = None
    cp = ConfigValidator(d)
    assert_invalid_option('static', 'None',
                          cp.validate_mandatory)
Example #26
0
def test_validate_option_port():
    d = FULL_CONFIG_BASE.copy()
    d['port'] = '8080'
    cp = ConfigValidator(d)
    assert cp.validate_mandatory()
Example #27
0
def test_validate_mandatory_option_run_as_standalone():
    d = FULL_CONFIG_BASE.copy()
    d['run-as'] = 'standalone'
    cp = ConfigValidator(d)
    assert cp.validate_mandatory()
Example #28
0
def test_invalid_mandatory_option_port_string():
    d = FULL_CONFIG_BASE.copy()
    d['port'] = 'invalid_port'
    cp = ConfigValidator(d)
    assert_invalid_option('port', 'invalid_port',
                          cp.validate_mandatory)
Example #29
0
def test_invalid_mandatory_option_port_float():
    d = FULL_CONFIG_BASE.copy()
    d['port'] = 90.2
    cp = ConfigValidator(d)
    assert_invalid_option('port', '90.2',
                          cp.validate_mandatory)
Example #30
0
def test_validate_option_autoreload():
    d = FULL_CONFIG_BASE.copy()
    d['autoreload'] = True
    cp = ConfigValidator(d)
    assert cp.validate_mandatory()