Skip to content

Commit ee6a6e7

Browse files
authored
Add dedicated Flask test coverage for search, workspaces, and export APIs (#101) (#104)
* feat: initial implementation of test cases for the apis * fix: review findings * fix: nitpick findings * fix: reviewer's findings
1 parent f194541 commit ee6a6e7

9 files changed

Lines changed: 435 additions & 254 deletions

File tree

.github/workflows/tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
# Pytest fixtures (tests/conftest.py) build a temp workspaceStorage and
115115
# exercise Flask routes via app.test_client(). Only listed files — not
116116
# `pytest tests/` — to avoid re-collecting unittest.TestCase classes above.
117-
run: python -m pytest tests/test_api_endpoints.py tests/test_pdf_export.py tests/test_search_helpers.py -v --tb=short
117+
run: python -m pytest tests/test_api_search.py tests/test_api_workspaces.py tests/test_api_export.py tests/test_pdf_export.py tests/test_search_helpers.py -v --tb=short
118118

119119
# ── PyInstaller desktop build (Windows only, once per workflow) ────────
120120
# Closes #44. Builds the onedir bundle and smoke-tests --help so the
@@ -149,7 +149,9 @@ jobs:
149149
- name: Install runtime deps + mypy
150150
# Install from the pinned lock file for deterministic resolution,
151151
# then add mypy (dev-only; not in requirements-lock.txt).
152-
# Flask 3.1+ ships inline types — do not install types-Flask (conflicts).
152+
# Flask 3.1+ includes inline type hints — do not add or install types-Flask
153+
# (it will conflict with our pip installs). Preventative guidance for future
154+
# maintainers editing the steps below.
153155
run: |
154156
python -m pip install --upgrade pip
155157
python -m pip install -r requirements-lock.txt

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ __pycache__/
99
venv/
1010
.venv/
1111
env/
12-
.mypy-ci-test/
1312

1413
# Packaging
1514
*.egg-info/

api/export_api.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import zipfile
1313
from datetime import datetime
1414
from pathlib import Path
15-
from typing import Any, cast
15+
from typing import Any
1616

1717
from flask import Blueprint, Response, request
1818

@@ -45,7 +45,14 @@ def _get_export_state() -> dict[str, Any]:
4545
if os.path.isfile(state_path):
4646
try:
4747
with open(state_path, "r", encoding="utf-8") as f:
48-
return cast(dict[str, Any], json.load(f))
48+
parsed = json.load(f)
49+
if isinstance(parsed, dict):
50+
return parsed
51+
_logger.warning(
52+
"Export state in %s is not a JSON object (got %s); ignoring",
53+
state_path,
54+
type(parsed).__name__,
55+
)
4956
except (json.JSONDecodeError, ValueError, OSError) as e:
5057
_logger.warning(
5158
"Could not read export state from %s: %s",

tests/_helpers.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Shared test helpers that must not live in conftest.
2+
3+
pytest treats conftest specially and it is not guaranteed to be importable as
4+
``tests.conftest`` under non-default import modes (e.g. ``--import-mode=importlib``).
5+
"""
6+
from __future__ import annotations
7+
8+
from flask.testing import FlaskClient
9+
10+
from app import create_app
11+
from utils.exclusion_rules import tokenize_rule
12+
13+
14+
def client_with_rules(rule_lines: list[str]) -> FlaskClient:
15+
"""Flask test client with EXCLUSION_RULES parsed from the given lines.
16+
17+
Requires WORKSPACE_PATH / CLI_CHATS_PATH to already be set (e.g. by
18+
``workspace_storage`` fixture).
19+
"""
20+
parsed = [tokenize_rule(line) for line in rule_lines]
21+
app = create_app()
22+
app.config["TESTING"] = True
23+
app.config["EXCLUSION_RULES"] = [r for r in parsed if r]
24+
return app.test_client()

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
HAPPY_WORKSPACE_ID,
2424
)
2525

26-
2726
def _make_global_state_db(path: str) -> None:
2827
"""globalStorage/state.vscdb with one composerData + one bubbleId row."""
2928
# contextlib.closing guarantees conn.close() even if an exec/commit raises

tests/test_api_endpoints.py

Lines changed: 0 additions & 248 deletions
This file was deleted.

0 commit comments

Comments
 (0)