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)
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)
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)
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()
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)
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)
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()
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()
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()
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)
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)
def test_overwrite_with_environment(self): config = MinosConfig(path=self.config_file_path) rest = config.rest self.assertEqual("::1", rest.connection.host)
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)
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)
def test_config_ini_fail(self): with self.assertRaises(MinosConfigException): MinosConfig(path=BASE_PATH / "test_fail_config.yaml")
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
def test_get_default_default(self): with MinosConfig(path=self.config_file_path) as config: self.assertEqual(config, MinosConfigAbstract.get_default())
def test_is_instance(self): config = MinosConfig(self.CONFIG_FILE_PATH) service = HealthStatusCheckerService(interval=0.1, config=config) self.assertIsInstance(service, PeriodicService)
def test_config_cors(self): config = MinosConfig(path=self.config_file_path) cors = config.cors self.assertIsInstance(cors.enabled, bool) self.assertTrue(cors.enabled)
def setUp(self) -> None: config = MinosConfig(self.CONFIG_FILE_PATH) self.redis_client = MinosRedisClient(config=config)
def test_overwrite_with_environment_discovery_port(self): config = MinosConfig(path=self.config_file_path) conn = config.discovery.connection self.assertEqual(4040, conn.port)
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()
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)
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)
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)