From d9eba7ccb7d381ee1708903955c7a6c07f61ae30 Mon Sep 17 00:00:00 2001 From: bruno Date: Thu, 10 Oct 2024 12:50:21 -0700 Subject: [PATCH] Checking for config file existance before mapping variables --- noxfiles/utils_nox.py | 51 ++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/noxfiles/utils_nox.py b/noxfiles/utils_nox.py index 6b11cd14bbd..9269eb54abe 100644 --- a/noxfiles/utils_nox.py +++ b/noxfiles/utils_nox.py @@ -70,11 +70,10 @@ def init_saas_connector(session: nox.Session) -> None: dataset_path = Path(f"data/saas/dataset/{variable_map['connector_id']}_dataset.yml") try: - config_path.touch(exist_ok=False) dataset_path.touch(exist_ok=False) except Exception: logger.warning( - f"Files for {session.posargs[0]} already exist, skipping config and dataset files" + f"Dataset file for {session.posargs[0]} already exist, skipping file creation" ) # location of Jinja templates @@ -88,27 +87,11 @@ def init_saas_connector(session: nox.Session) -> None: fixtures_template = environment.get_template("new_fixtures.jinja") filename = f"tests/fixtures/saas/{variable_map['connector_id']}_fixtures.py" - if config_path.exists and dataset_path.exists: - config = yaml.safe_load(config_path.open('r')) - integration = config["saas_config"] - - # check if external references is present - external = True if "external_references" in integration.keys() else False - - # extract the type of request - requests = [endpoint["requests"] for endpoint in integration["endpoints"]] - method = [request.keys() for request in requests] - keys = [list(key)[0] for key in method] - - variable_map["external"] = external - variable_map["methods"] = keys - variable_map["delete"] = False - variable_map["read"] = False - - if any(key in ["update", "delete"] for key in keys): - variable_map["delete"] = True - if any(key == "read" for key in keys): - variable_map["read"] = True + if config_path.exists() : + logger.warning( + f"Config file for {session.posargs[0]} already exist, loading it for variable mapping " + ) + prepare_variable_maps_from_config_file(config_path, variable_map) contents = fixtures_template.render(variable_map) try: @@ -134,3 +117,25 @@ def init_saas_connector(session: nox.Session) -> None: # session.error( # f"Files for {session.posargs[0]} already exist, skipping initialization" # ) + +def prepare_variable_maps_from_config_file(config_path: Path, variable_map: dict): + config = yaml.safe_load(config_path.open('r')) + integration = config["saas_config"] + + # check if external references is present + external = True if "external_references" in integration.keys() else False + + # extract the type of request + requests = [endpoint["requests"] for endpoint in integration["endpoints"]] + method = [request.keys() for request in requests] + keys = [list(key)[0] for key in method] + + variable_map["external"] = external + variable_map["methods"] = keys + variable_map["delete"] = False + variable_map["read"] = False + + if any(key in ["update", "delete"] for key in keys): + variable_map["delete"] = True + if any(key == "read" for key in keys): + variable_map["read"] = True