Skip to content

Commit 24eb501

Browse files
gkorlandCopilot
andcommitted
Add graph_exists check to repo_info endpoints, fix test cleanup assertion
- Replace ineffective 'if stats is None' guard in repo_info with g.graph_exists() check in both api/index.py and tests/index.py - Add missing mock_db.aclose assertion in test_async_get_repos_empty Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 20a02d5 commit 24eb501

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

api/index.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,15 @@ async def repo_info(data: RepoRequest, _=Depends(public_or_auth)):
178178

179179
g = AsyncGraphQuery(data.repo)
180180
try:
181+
if not await g.graph_exists():
182+
return JSONResponse({"status": f'Missing repository "{data.repo}"'}, status_code=400)
183+
181184
stats = await g.stats()
182185
finally:
183186
await g.close()
184187
info = await async_get_repo_info(data.repo)
185188

186-
if stats is None or info is None:
189+
if info is None:
187190
return JSONResponse({"status": f'Missing repository "{data.repo}"'}, status_code=400)
188191

189192
stats |= info

tests/index.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,14 @@ async def list_repos(_=Depends(token_required)):
142142
async def repo_info(data: RepoRequest, _=Depends(token_required)):
143143
g = AsyncGraphQuery(data.repo)
144144
try:
145+
if not await g.graph_exists():
146+
return JSONResponse({"status": f'Missing repository "{data.repo}"'}, status_code=400)
147+
145148
stats = await g.stats()
146149
finally:
147150
await g.close()
148151
info = await async_get_repo_info(data.repo)
149-
if stats is None or info is None:
152+
if info is None:
150153
return JSONResponse({"status": f'Missing repository "{data.repo}"'}, status_code=400)
151154
stats |= info
152155
return {"status": "success", "info": stats}

tests/test_async_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ async def test_async_get_repos_empty():
8282
repos = await async_get_repos()
8383

8484
assert repos == []
85+
mock_db.aclose.assert_awaited_once()
8586

8687

8788
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)