def setUp(self): AppLogging.init('info') self.http_utils = mock.Mock() self.http_utils.get_demo_http_headers.return_value = {} self.app_config = mock.Mock() self.app_config.get_delay_start_ms.return_value = 0 self.app_config.get_process_start_time.return_value = time.time() self.result = mock.Mock() self.createResponseFunc = (lambda x, y, z: self.result) self.message = MessageHandler(self.app_config, self.http_utils, repository.Repository(["SOMETHING"]), self.createResponseFunc)
def setUp(self): AppLogging.init('info') self.http_utils = mock.Mock() self.http_utils.query_service.return_value = "{}" self.http_utils.get_demo_http_headers.return_value = {} self.app_config = mock.Mock() self.app_config.get_delay_start_ms.return_value = 0 self.app_config.get_process_start_time.return_value = time.time() self.result = mock.Mock() self.createResponseFunc = (lambda x,y,z: self.result) self.datastore = mock.Mock() self.all_inventory = [0,1,2,3,4,5,6,7,8,9] self.datastore.get_records.return_value = self.all_inventory self.inventory = InventoryHandler(self.app_config, self.datastore, self.http_utils, repository.Repository(["SOMETHING"]), self.createResponseFunc)
def lambda_handler(event, context): AppLogging.init('info') app_config = AppConfig( config_file=os.environ['config_file'] ) config = app_config.asdict() database_connection_info_func = lambda: DatabaseConnectionInfo( user=config['database']['user'], password=config['database']['password'], host=config['database']['host'], port=config['database']['port'], database=config['database']['name'] ) database_connector = MySqlConnector( connection_info=database_connection_info_func() ) database_inventory_repository = DatabaseInventoryRepository( database_connector=database_connector ) file_inventory_repository = FileInventoryRepository() inventory_repositories = { 'file': file_inventory_repository, 'database': database_inventory_repository } inventory_repository = inventory_repositories[inventory_repository_selector(app_config)] http_utils = HttpUtils( func_get_headers=lambda: (event['headers'] or dict()).items() ) def behavior_factory(name, value): if name == "throw": return ThrowException() elif name == "compute": return Compute(value) elif name == "malloc": return Malloc(value) elif name == "invalid_query": return InvalidQuery(database_inventory_repository) else: return None behavior_repository = Repository( app_id=app_config.get_app_id(), behavior_factory_func=behavior_factory ) AppLogging.init('info') if(inventory_repository_selector(app_config) == 'database'): setup_database = SetupDatabaseAction(database_connector, database_connection_info_func(), get_inventory_data()) setup_database.execute() endpoint = (event['resource'] or "").lower() if endpoint == "/": index = IndexHandler(app_config, behavior_repository) resp = index.index_message() elif endpoint == "/validatemessage": message = MessageHandler(app_config, http_utils, behavior_repository) resp = message.validate() elif endpoint == "/help": resp = help_message() elif endpoint == "/inventory": inventory = InventoryHandler(app_config, inventory_repository, http_utils, behavior_repository) resp = inventory.get_inventory() elif endpoint == "/inventory/{id+}": inventory = InventoryHandler(app_config, inventory_repository, http_utils, behavior_repository) item_id = event['pathParameters']['id'] resp = inventory.get_inventory_item(item_id) else: body = "Unsupported endpoint: " + endpoint resp = TronResponse(body, dict(), 404) return get_lambda_reponse(resp)
) for k, v in tron_response.get_headers().items(): response.headers[k] = v return response if __name__ == "__main__": container = Container() app_config = container.app_config() container.config.from_dict(app_config.asdict()) container.wire(modules=[sys.modules[__name__]]) arguments = container.arguments() AppLogging.init(arguments.logging_level) if inventory_repository_selector(app_config) == 'database': container.setup_database_action().execute() database_connector = container.database_connector() http_utils = container.http_utils() inventory = container.inventory_handler() message = container.message_handler() behaviors = container.behaviors_handler() index = container.index_handler() debug_mode = arguments.debug_mode if debug_mode is not None and debug_mode == 'On': os.environ["FLASK_ENV"] = "development"
def setUp(self): AppLogging.init('info') self.app_config = mock.Mock() self.result = mock.Mock() self.behaviors = BehaviorsHandler(self.app_config, repository.Repository(["SOMETHING"]))