예제 #1
0
    def test_overwrite_with_parameter_cors(self):
        config = MinosConfig(path=self.config_file_path,
                             api_gateway_cors_enabled=False)
        cors = config.cors

        self.assertIsInstance(cors.enabled, bool)
        self.assertFalse(cors.enabled)
예제 #2
0
    def test_default_graceful_stop_timeout(self):
        config = MinosConfig(self.CONFIG_FILE_PATH)
        service = DiscoveryService(address=config.discovery.connection.host,
                                   port=config.discovery.connection.port,
                                   config=config)

        self.assertEqual(5, service.graceful_stop_timeout)
예제 #3
0
 async def test_load_endpoints(self):
     conf = MinosConfig(path=BASE_PATH / "test_config.yml")
     app = web.Application()
     rest = RestRoutesLoader(endpoints=conf.rest.endpoints,
                             config=conf,
                             app=app)
     app = rest.get_app()
     self.assertIsInstance(app, web.Application)
예제 #4
0
    async def get_application(self):
        """
        Override the get_app method to return your application.
        """
        config = MinosConfig(self.CONFIG_FILE_PATH)
        service = DiscoveryService(address=config.discovery.connection.host,
                                   port=config.discovery.connection.port,
                                   config=config)

        return await service.create_application()
예제 #5
0
    def test_config_rest(self):
        config = MinosConfig(path=self.config_file_path)
        rest = config.rest

        broker = rest.connection
        self.assertEqual("localhost", broker.host)
        self.assertEqual(8900, broker.port)

        endpoints = rest.endpoints
        self.assertEqual("AddOrder", endpoints[0].name)
예제 #6
0
    async def test_stop(self):
        config = MinosConfig(self.CONFIG_FILE_PATH)
        service = DiscoveryService(address=config.discovery.connection.host,
                                   port=config.discovery.connection.port,
                                   config=config)

        with patch("asyncio.sleep") as mock:
            mock.return_value = None
            await service.stop()
            self.assertEqual(1, mock.call_count)
            self.assertEqual(call(service.graceful_stop_timeout),
                             mock.call_args)
예제 #7
0
    async def get_application(self):
        """
        Override the get_app method to return your application.
        """
        config = MinosConfig(self.CONFIG_FILE_PATH)
        rest_interface = ExampleRestService(
            address=config.rest.connection.host,
            port=config.rest.connection.port,
            endpoints=config.rest.endpoints,
            config=config,
        )

        return await rest_interface.create_application()
예제 #8
0
 async def test_redis_wrong_client_connection(self):
     with patch.dict(
         os.environ,
         {
             "DISCOVERY_SERVICE_DB_HOST": "redishost",
             "DISCOVERY_SERVICE_DB_PORT": "8393",
             "DISCOVERY_SERVICE_DB_PASSWORD": "******",
         },
         clear=True,
     ):
         config = MinosConfig(self.CONFIG_FILE_PATH)
         with self.assertRaises(ConnectionError):
             redis_client = MinosRedisClient(config=config)
             await redis_client.ping()
예제 #9
0
def start(file_path: Optional[Path] = typer.Argument(
    "config.yml",
    help="Discovery Service configuration file.",
    envvar="MINOS_API_GATEWAY_CONFIG_FILE_PATH")):  # pragma: no cover
    """Start Discovery services."""

    config = MinosConfig(file_path)

    services = (
        HealthStatusCheckerService(interval=120, delay=0, config=config),
        DiscoveryService(address=config.discovery.connection.host,
                         port=config.discovery.connection.port,
                         config=config),
    )
    launcher = EntrypointLauncher(services=services)  # pragma: no cover
    launcher.launch()
예제 #10
0
    def test_config_discovery(self):
        config = MinosConfig(path=self.config_file_path)
        discovery = config.discovery

        conn = discovery.connection
        self.assertEqual("localhost", conn.host)
        self.assertEqual(8080, conn.port)

        db = discovery.database
        self.assertEqual("localhost", db.host)
        self.assertEqual(6379, db.port)
        self.assertEqual(None, db.password)

        self.assertEqual("/discover", discovery.connection.path)

        endpoints = discovery.endpoints
        self.assertEqual("Discover", endpoints[0].name)
예제 #11
0
 def test_overwrite_with_parameter(self):
     config = MinosConfig(path=self.config_file_path,
                          api_gateway_rest_host="::1")
     rest = config.rest
     self.assertEqual("::1", rest.connection.host)
예제 #12
0
 def test_overwrite_with_environment(self):
     config = MinosConfig(path=self.config_file_path)
     rest = config.rest
     self.assertEqual("::1", rest.connection.host)
예제 #13
0
    def test_overwrite_with_environment_cors(self):
        config = MinosConfig(path=self.config_file_path)
        cors = config.cors

        self.assertIsInstance(cors.enabled, bool)
        self.assertFalse(cors.enabled)
예제 #14
0
 async def test_callback(self):
     config = MinosConfig(self.CONFIG_FILE_PATH)
     service = HealthStatusCheckerService(interval=0.1, loop=None, config=config)
     service.status_checker.check = MagicMock(side_effect=service.status_checker.check)
     await service.callback()
     self.assertEqual(1, service.status_checker.check.call_count)
예제 #15
0
 def test_config_ini_fail(self):
     with self.assertRaises(MinosConfigException):
         MinosConfig(path=BASE_PATH / "test_fail_config.yaml")
예제 #16
0
 def test_multiple_default_config_raises(self):
     with self.assertRaises(MinosConfigDefaultAlreadySetException):
         with MinosConfig(path=self.config_file_path):
             with MinosConfig(path=self.config_file_path):
                 pass
예제 #17
0
 def test_get_default_default(self):
     with MinosConfig(path=self.config_file_path) as config:
         self.assertEqual(config, MinosConfigAbstract.get_default())
예제 #18
0
 def test_is_instance(self):
     config = MinosConfig(self.CONFIG_FILE_PATH)
     service = HealthStatusCheckerService(interval=0.1, config=config)
     self.assertIsInstance(service, PeriodicService)
예제 #19
0
    def test_config_cors(self):
        config = MinosConfig(path=self.config_file_path)
        cors = config.cors

        self.assertIsInstance(cors.enabled, bool)
        self.assertTrue(cors.enabled)
예제 #20
0
 def setUp(self) -> None:
     config = MinosConfig(self.CONFIG_FILE_PATH)
     self.redis_client = MinosRedisClient(config=config)
예제 #21
0
 def test_overwrite_with_environment_discovery_port(self):
     config = MinosConfig(path=self.config_file_path)
     conn = config.discovery.connection
     self.assertEqual(4040, conn.port)
예제 #22
0
 async def setUpAsync(self) -> None:
     await super().setUpAsync()
     self.config = MinosConfig(self.CONFIG_FILE_PATH)
     self.redis = MinosRedisClient(config=self.config)
     await self.redis.flush_db()
예제 #23
0
 def test_overwrite_with_environment_discovery_db_host(self):
     config = MinosConfig(path=self.config_file_path)
     conn = config.discovery.database
     self.assertEqual("::1", conn.host)
예제 #24
0
 def test_overwrite_with_environment_discovery_db_password(self):
     config = MinosConfig(path=self.config_file_path)
     conn = config.discovery.database
     self.assertEqual("1234", conn.password)
예제 #25
0
 def test_overwrite_with_environment_false(self):
     config = MinosConfig(path=self.config_file_path,
                          with_environment=False)
     rest = config.rest
     self.assertEqual("localhost", rest.connection.host)