@@ -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+
64127def test_set_language_switches_ui_text (tmp_path ):
65128 app = create_app (str (tmp_path ))
66129 client = app .test_client ()
0 commit comments