def test_load_cache_implementation_defaults(self, mock_environment):
        mock_environment[CACHE_HOST_KEY] = CACHE_HOST
        config.setup_config(CONFIG_PREFIX)

        loaded_cache = main.load_cache_implementation()

        self.assertIsInstance(loaded_cache, redis_cache.RedisCache)
        self.assertEqual(loaded_cache.expiry_time, DEFAULT_CACHE_EXPIRY_TIME)
    def test_setup_config_populates_config(self, mock_environ):
        mock_environ["PREFIX_TEST"] = "123"
        mock_environ["PREFIX_LOG_LEVEL"] = "INFO"

        self.assertEqual({}, config.config)

        config.setup_config("PREFIX")

        self.assertEqual({"TEST": "123", "LOG_LEVEL": "INFO"}, config.config)
    def setup_logger(self, mock_environ):
        mock_environ["PREFIX_LOG_LEVEL"] = "INFO"
        config.setup_config("PREFIX")

        def remove_logging_handler():
            logging.getLogger().handlers = []

        self.addCleanup(remove_logging_handler)
        integration_adaptors_logger.configure_logging()
    def test_load_cache_implementation(self, mock_environment):
        mock_environment[CACHE_EXPIRY_TIME_KEY] = CACHE_EXPIRY_TIME
        mock_environment[CACHE_HOST_KEY] = CACHE_HOST
        mock_environment[CACHE_PORT_KEY] = CACHE_PORT
        mock_environment[DISABLE_TLS] = DISABLE_TLS
        config.setup_config(CONFIG_PREFIX)

        loaded_cache = main.load_cache_implementation()

        self.assertIsInstance(loaded_cache, redis_cache.RedisCache)
        self.assertEqual(loaded_cache.expiry_time, CACHE_EXPIRY_TIME)
Exemplo n.º 5
0
def main():
    config.setup_config("MHS")
    secrets.setup_secret_config("MHS")
    log.configure_logging()
    data_dir = pathlib.Path(definitions.ROOT_DIR) / "data"

    configure_http_client()

    routing = initialise_routing()

    certificates = certs.Certs.create_certs_files(
        data_dir / '..',
        private_key=secrets.get_secret_config('CLIENT_KEY'),
        local_cert=secrets.get_secret_config('CLIENT_CERT'),
        ca_certs=secrets.get_secret_config('CA_CERTS'))
    max_retries = int(
        config.get_config('OUTBOUND_TRANSMISSION_MAX_RETRIES', default="3"))
    retry_delay = int(
        config.get_config('OUTBOUND_TRANSMISSION_RETRY_DELAY', default="100"))
    http_proxy_host = config.get_config('OUTBOUND_HTTP_PROXY', default=None)
    http_proxy_port = None
    if http_proxy_host is not None:
        http_proxy_port = int(
            config.get_config('OUTBOUND_HTTP_PROXY_PORT', default="3128"))
    transmission = outbound_transmission.OutboundTransmission(
        certificates.local_cert_path, certificates.private_key_path,
        certificates.ca_certs_path, max_retries, retry_delay, http_proxy_host,
        http_proxy_port)

    party_key = secrets.get_secret_config('PARTY_KEY')
    work_description_store = dynamo_persistence_adaptor.DynamoPersistenceAdaptor(
        table_name=config.get_config('STATE_TABLE_NAME'))
    sync_async_store = dynamo_persistence_adaptor.DynamoPersistenceAdaptor(
        table_name=config.get_config('SYNC_ASYNC_STATE_TABLE_NAME'))
    store_retries = int(
        config.get_config('STATE_STORE_MAX_RETRIES', default='3'))
    max_request_size = int(config.get_config('SPINE_REQUEST_MAX_SIZE'))
    workflows = initialise_workflows(transmission, party_key,
                                     work_description_store, sync_async_store,
                                     max_request_size, store_retries, routing)
    start_tornado_server(data_dir, workflows)
    def test_get_config_success(self, mock_environ):
        mock_environ["PREFIX_TEST"] = "123"

        config.setup_config("PREFIX")

        self.assertEqual("123", config.get_config("TEST"))
    def test_setup_config_filters_by_prefix(self, mock_environ):
        mock_environ["SOME_OTHER_CONFIG"] = "BLAH"

        config.setup_config("PREFIX")

        self.assertEqual({}, config.config)