Skip to content

Commit

Permalink
Checking for config file existance before mapping variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagoasdf committed Oct 10, 2024
1 parent 402b9c8 commit d9eba7c
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions noxfiles/utils_nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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

0 comments on commit d9eba7c

Please sign in to comment.