-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_export_api_bulk.py
More file actions
89 lines (72 loc) · 2.63 KB
/
Copy pathtest_export_api_bulk.py
File metadata and controls
89 lines (72 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Tests for bulk export HTTP behavior (empty export / state JSON)."""
from __future__ import annotations
import json
import sys
from pathlib import Path
import pytest
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT))
from flask import Flask # noqa: E402
from api.export_api import export_bp # noqa: E402
@pytest.fixture
def isolated_state(tmp_path, monkeypatch):
path = tmp_path / "export_state.json"
monkeypatch.setattr("api.export_api._STATE_FILE", str(path))
return path
def test_bulk_export_invalid_since_returns_400(isolated_state, tmp_path):
app = Flask(__name__)
app.config["TESTING"] = True
app.config["CLAUDE_PROJECTS_DIR"] = str(tmp_path)
app.register_blueprint(export_bp)
client = app.test_client()
resp = client.post("/api/export", json={"since": "lst"})
assert resp.status_code == 400
body = resp.get_json()
assert body["error"] == "Invalid since mode"
assert body["code"] == "INVALID_SINCE_MODE"
assert body["since"] == "lst"
def test_bulk_export_non_object_json_returns_400(isolated_state, tmp_path):
app = Flask(__name__)
app.config["TESTING"] = True
app.config["CLAUDE_PROJECTS_DIR"] = str(tmp_path)
app.register_blueprint(export_bp)
client = app.test_client()
resp = client.post(
"/api/export",
data=json.dumps(["all"]),
content_type="application/json",
)
assert resp.status_code == 400
body = resp.get_json()
assert body["error"] == "Invalid request body"
assert body["code"] == "INVALID_REQUEST_BODY"
def test_bulk_export_empty_returns_422_json(isolated_state, tmp_path):
app = Flask(__name__)
app.config["TESTING"] = True
app.config["CLAUDE_PROJECTS_DIR"] = str(tmp_path)
app.register_blueprint(export_bp)
client = app.test_client()
resp = client.post("/api/export", json={"since": "all"})
assert resp.status_code == 422
body = resp.get_json()
assert body["error"] == "Nothing to export"
assert body["code"] == "EXPORT_NOTHING_TO_EXPORT"
assert body["since"] == "all"
def test_export_state_json_fields(isolated_state):
isolated_state.write_text(
json.dumps({
"lastExportTime": "2026-01-01T12:00:00",
"exportedCount": 5,
"sessions": {},
}),
encoding="utf-8",
)
app = Flask(__name__)
app.config["TESTING"] = True
app.register_blueprint(export_bp)
client = app.test_client()
resp = client.get("/api/export/state")
assert resp.status_code == 200
body = resp.get_json()
assert body["last_export_session_count"] == 5
assert "export_count" not in body