feat: update status codes and navigation structure in calculations and reports routes
This commit is contained in:
@@ -35,11 +35,16 @@ class FakeState:
|
||||
] = field(default_factory=dict)
|
||||
financial_inputs: dict[Tuple[int, str],
|
||||
Dict[str, Any]] = field(default_factory=dict)
|
||||
navigation_groups: dict[str, Dict[str, Any]] = field(default_factory=dict)
|
||||
navigation_links: dict[Tuple[int, str],
|
||||
Dict[str, Any]] = field(default_factory=dict)
|
||||
sequences: Dict[str, int] = field(default_factory=lambda: {
|
||||
"users": 0,
|
||||
"projects": 0,
|
||||
"scenarios": 0,
|
||||
"financial_inputs": 0,
|
||||
"navigation_groups": 0,
|
||||
"navigation_links": 0,
|
||||
})
|
||||
|
||||
|
||||
@@ -50,6 +55,9 @@ class FakeResult:
|
||||
def fetchone(self) -> Any | None:
|
||||
return self._rows[0] if self._rows else None
|
||||
|
||||
def fetchall(self) -> list[Any]:
|
||||
return list(self._rows)
|
||||
|
||||
|
||||
class FakeConnection:
|
||||
def __init__(self, state: FakeState) -> None:
|
||||
@@ -105,6 +113,13 @@ class FakeConnection:
|
||||
rows = [SimpleNamespace(id=record["id"])] if record else []
|
||||
return FakeResult(rows)
|
||||
|
||||
if lower_sql.startswith("select name from roles"):
|
||||
rows = [
|
||||
SimpleNamespace(name=record["name"])
|
||||
for record in self.state.roles.values()
|
||||
]
|
||||
return FakeResult(rows)
|
||||
|
||||
if lower_sql.startswith("insert into user_roles"):
|
||||
key = (int(params["user_id"]), int(params["role_id"]))
|
||||
self.state.user_roles.add(key)
|
||||
@@ -171,6 +186,67 @@ class FakeConnection:
|
||||
rows = [SimpleNamespace(id=scenario["id"])] if scenario else []
|
||||
return FakeResult(rows)
|
||||
|
||||
if lower_sql.startswith("insert into navigation_groups"):
|
||||
slug = params["slug"]
|
||||
record = self.state.navigation_groups.get(slug)
|
||||
if record is None:
|
||||
self.state.sequences["navigation_groups"] += 1
|
||||
record = {
|
||||
"id": self.state.sequences["navigation_groups"],
|
||||
"slug": slug,
|
||||
}
|
||||
record.update(
|
||||
label=params["label"],
|
||||
sort_order=int(params.get("sort_order", 0)),
|
||||
icon=params.get("icon"),
|
||||
tooltip=params.get("tooltip"),
|
||||
is_enabled=bool(params.get("is_enabled", True)),
|
||||
)
|
||||
self.state.navigation_groups[slug] = record
|
||||
return FakeResult([])
|
||||
|
||||
if lower_sql.startswith("select id from navigation_groups where slug"):
|
||||
slug = params["slug"]
|
||||
record = self.state.navigation_groups.get(slug)
|
||||
rows = [SimpleNamespace(id=record["id"])] if record else []
|
||||
return FakeResult(rows)
|
||||
|
||||
if lower_sql.startswith("insert into navigation_links"):
|
||||
group_id = int(params["group_id"])
|
||||
slug = params["slug"]
|
||||
key = (group_id, slug)
|
||||
record = self.state.navigation_links.get(key)
|
||||
if record is None:
|
||||
self.state.sequences["navigation_links"] += 1
|
||||
record = {
|
||||
"id": self.state.sequences["navigation_links"],
|
||||
"group_id": group_id,
|
||||
"slug": slug,
|
||||
}
|
||||
record.update(
|
||||
parent_link_id=(int(params["parent_link_id"]) if params.get(
|
||||
"parent_link_id") is not None else None),
|
||||
label=params["label"],
|
||||
route_name=params.get("route_name"),
|
||||
href_override=params.get("href_override"),
|
||||
match_prefix=params.get("match_prefix"),
|
||||
sort_order=int(params.get("sort_order", 0)),
|
||||
icon=params.get("icon"),
|
||||
tooltip=params.get("tooltip"),
|
||||
required_roles=list(params.get("required_roles") or []),
|
||||
is_enabled=bool(params.get("is_enabled", True)),
|
||||
is_external=bool(params.get("is_external", False)),
|
||||
)
|
||||
self.state.navigation_links[key] = record
|
||||
return FakeResult([])
|
||||
|
||||
if lower_sql.startswith("select id from navigation_links where group_id"):
|
||||
group_id = int(params["group_id"])
|
||||
slug = params["slug"]
|
||||
record = self.state.navigation_links.get((group_id, slug))
|
||||
rows = [SimpleNamespace(id=record["id"])] if record else []
|
||||
return FakeResult(rows)
|
||||
|
||||
if lower_sql.startswith("insert into financial_inputs"):
|
||||
key = (int(params["scenario_id"]), params["name"])
|
||||
record = self.state.financial_inputs.get(key)
|
||||
|
||||
Reference in New Issue
Block a user