Skip to content

Commit

Permalink
In webapp, resolve dirpath coming from envvar and set 'InfoMander.pat…
Browse files Browse the repository at this point in the history
…h' as the first directory of 'MANDR_ROOT'
  • Loading branch information
thomass-dev committed Jul 16, 2024
1 parent 4183f11 commit 921957b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/mandr/dashboard/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
@app.get("/api/mandrs")
async def list_mandrs(request: Request) -> list[str]:
"""Send the list of mandrs path below the current working directory."""
path = os.environ["MANDR_PATH"]
root = Path(os.environ["MANDR_ROOT"])
root = Path(os.environ["MANDR_ROOT"]).resolve()
directories = list(root.iterdir())

if len(directories) != 1 or (not directories[0].is_dir()):
raise ValueError("'{root}' is not a valid mandr root")

path = directories[0].stem
ims = [InfoMander(path, root=root)]
paths = []

Expand All @@ -36,7 +41,7 @@ async def list_mandrs(request: Request) -> list[str]:
@app.get("/api/mandrs/{path:path}")
async def get_mandr(request: Request, path: str):
"""Return one mandr."""
root = Path(os.environ["MANDR_ROOT"])
root = Path(os.environ["MANDR_ROOT"]).resolve()

if not (root / path).exists():
raise HTTPException(status_code=404, detail=f"No mandr found in '{path}'")
Expand Down
1 change: 0 additions & 1 deletion tests/integration/dashboard/test_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def test_index(client: TestClient):


def test_list_mandrs(client: TestClient, tmp_path):
os.environ["MANDR_PATH"] = "root"
os.environ["MANDR_ROOT"] = str(tmp_path)

InfoMander("root", root=tmp_path).add_info("key", "value")
Expand Down

0 comments on commit 921957b

Please sign in to comment.