Skip to content

Commit ce78057

Browse files
committed
Corrige o erro no template.
1 parent f803af7 commit ce78057

5 files changed

Lines changed: 78 additions & 5 deletions

File tree

spsvalidator/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "spsvalidator"
7-
version = "1.0.0"
7+
version = "1.10"
88
description = "Standalone SPS package validator desktop webapp"
99
readme = "README.md"
1010
requires-python = ">=3.11"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
APP_VERSION = "1.0.0"
1+
APP_VERSION = "1.10"
22
BUILD_MACOS_VERSION = "26.3.1 (25D2128)"
33
BUILD_PLATFORM = "macOS"

spsvalidator/src/spsvalidator/db/repository.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
from datetime import UTC, datetime
77

88

9+
def _json_safe(value):
10+
if isinstance(value, bytes):
11+
return value.decode("utf-8", errors="replace")
12+
if isinstance(value, dict):
13+
return {key: _json_safe(item) for key, item in value.items()}
14+
if isinstance(value, (list, tuple)):
15+
return [_json_safe(item) for item in value]
16+
return value
17+
18+
919
def init_db(db_path: str) -> None:
1020
with sqlite3.connect(db_path) as connection:
1121
connection.execute("""
@@ -67,8 +77,8 @@ def insert_validation_result(
6777
len(rows),
6878
len(exceptions),
6979
status,
70-
json.dumps(rows, ensure_ascii=False),
71-
json.dumps(exceptions, ensure_ascii=False),
80+
json.dumps(_json_safe(rows), ensure_ascii=False),
81+
json.dumps(_json_safe(exceptions), ensure_ascii=False),
7282
),
7383
)
7484
for article in articles:

spsvalidator/src/spsvalidator/web/routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def _current_translations():
3333

3434

3535
def _render_index(**context):
36+
context.setdefault("error_message", None)
3637
return render_template(
3738
"index.html",
3839
history_items=list_validations(current_app.config["DB_PATH"]),
39-
error_message=None,
4040
**context,
4141
)
4242

spsvalidator/tests/test_service_and_web.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,69 @@ def save(self, destination):
6161
assert b"ERROR" in csv_response.data
6262

6363

64+
def test_run_validation_persists_bytes_in_report(monkeypatch, tmp_path):
65+
app = create_app(str(tmp_path))
66+
db_path = app.config["DB_PATH"]
67+
68+
def fake_validate(zip_path: str):
69+
return {
70+
"rows": [
71+
{
72+
"group": "g",
73+
"title": "t",
74+
"response": "ERROR",
75+
"expected_value": b"expected",
76+
"got_value": b"got",
77+
}
78+
],
79+
"exceptions": [{"response": "exception", "detail": b"fail"}],
80+
"articles": [
81+
{
82+
"xml_path": "article.xml",
83+
"title": "Article",
84+
"authors_text": "A B",
85+
"doi": "",
86+
"pid": "",
87+
"article_status": "issue",
88+
"issue_count": 1,
89+
}
90+
],
91+
}
92+
93+
monkeypatch.setattr(validation_service, "validate_sps_zip", fake_validate)
94+
95+
class UploadedFile:
96+
filename = "package.zip"
97+
98+
def save(self, destination):
99+
Path(destination).write_bytes(b"zip")
100+
101+
result = validation_service.run_validation(db_path, UploadedFile())
102+
client = app.test_client()
103+
response = client.get(f"/validation/{result['history_id']}/report.csv")
104+
assert response.status_code == 200
105+
assert b"expected" in response.data
106+
assert b"got" in response.data
107+
108+
109+
def test_validate_route_shows_error_on_failure(monkeypatch, tmp_path):
110+
app = create_app(str(tmp_path))
111+
112+
def fake_validate(zip_path: str):
113+
raise RuntimeError("validation failed")
114+
115+
monkeypatch.setattr(validation_service, "validate_sps_zip", fake_validate)
116+
client = app.test_client()
117+
response = client.post(
118+
"/validate",
119+
data={"package_zip": (_zip_fixture_xml(), "package.zip")},
120+
content_type="multipart/form-data",
121+
)
122+
html = response.get_data(as_text=True)
123+
assert response.status_code == 200
124+
assert "validation failed" in html
125+
126+
64127
def test_set_language_switches_ui_text(tmp_path):
65128
app = create_app(str(tmp_path))
66129
client = app.test_client()

0 commit comments

Comments
 (0)