Exemplo n.º 1
0
def test_resource_manager_config_section(configfile,
                                         service_webserver_environ):
    parser = setup_parser(argparse.ArgumentParser("test-parser"))

    with mock.patch("os.environ", service_webserver_environ):
        app_config = parse(["-c", configfile], parser)

        # NOTE: during PR #1401 some tests starting failing because these
        # config entries were returning the wrong type.
        # I would expect traferet to auto-cast.
        # Let's check against multiple configs
        #
        # >>> import trafaret as t
        # >>> t.Int().check(3)
        # 3
        # >>> t.Int().check("3")
        # '3'
        # >>> t.ToInt().check("3")
        # 3
        # >>> t.ToInt().check(3)
        # 3
        #
        # NOTE: Changelog 2.0.2 https://trafaret.readthedocs.io/en/latest/changelog.html
        #   construct for int and float will use ToInt and ToFloat
        #
        # RESOLVED: changing the schema from Int() -> ToInt()
        assert isinstance(app_config["resource_manager"]["enabled"], bool)

        # Checks implementations of .resource_manager.config.get_* helpers
        assert isinstance(
            app_config["resource_manager"]
            ["resource_deletion_timeout_seconds"], int)
        assert isinstance(
            app_config["resource_manager"]
            ["garbage_collection_interval_seconds"], int)
Exemplo n.º 2
0
def test_creation_of_login_config(configfile, service_webserver_environ):
    parser = setup_parser(argparse.ArgumentParser("test-parser"))

    with mock.patch("os.environ", service_webserver_environ):
        app_config = parse(["-c", configfile], parser)

        for key, value in app_config.items():
            assert value != "None", "Use instead Null in {} for {}".format(
                configfile, key)

        # sections of app config used
        assert LOGIN_SECTION in app_config.keys()
        assert SMTP_SECTION in app_config.keys()
        assert DB_SECTION in app_config.keys()

        # creates update config
        fake_app = {APP_CONFIG_KEY: app_config}
        fake_storage = object()

        update_cfg = create_login_internal_config(fake_app, fake_storage)
        assert all(value.lower() is not ["none", "null", ""]
                   for value in update_cfg.values() if isinstance(value, str))

        # creates login.cfg
        login_internal_cfg = Cfg(CONFIG_DEFAULTS)
        try:
            login_internal_cfg.configure(update_cfg)
        except ValueError as ee:
            pytest.fail(f"{ee}: \n {update_cfg}")
Exemplo n.º 3
0
def test_correctness_under_environ(configfile, service_webserver_environ):
    parser = setup_parser(argparse.ArgumentParser("test-parser"))

    with mock.patch("os.environ", service_webserver_environ):
        cmd = ["-c", configfile]
        config = parse(cmd, parser)

        for key, value in config.items():
            assert value != "None", "Use instead Null in {} for {}".format(
                configfile, key)
Exemplo n.º 4
0
def test_correctness_under_environ(configfile, container_environ):
    parser = setup_parser(argparse.ArgumentParser("test-parser"))

    with mock.patch('os.environ', container_environ):
        cmd = ["-c", configfile]
        config = parse(cmd, parser)

        for key, value in config.items():
            assert value != 'None', "Use instead Null in {} for {}".format(
                configfile, key)

        # adds some defaults checks here
        assert config['smtp']['username'] is None
Exemplo n.º 5
0
def app_config(request, mock_webserver_service_environment) -> Dict:
    parser = setup_parser(argparse.ArgumentParser("test-parser"))
    config = parse(["-c", request.param], parser)
    print("app config [request.param]:\n", json.dumps(config, indent=1))
    return config