@@ -48,6 +48,8 @@ def test_download_config_api(client):
4848 assert res .status_code == 200
4949 assert data ["success" ] is True
5050 assert data ["data" ]["effective" ]["max_concurrent" ] == 2
51+ assert data ["data" ]["effective" ]["gallery_archive_enabled" ] is True
52+ assert "gallery_archive_file" in data ["data" ]["effective" ]
5153
5254 res = client .post (
5355 "/api/download/config" ,
@@ -90,9 +92,42 @@ def test_create_download_job_success(client):
9092 final_job = _wait_for_job (client , job_id )
9193 assert final_job ["status" ] == "success"
9294 assert final_job ["output_path_rel" ] == "mock-output.mp4"
95+ assert final_job ["output_files_rel" ] == ["mock-output.mp4" ]
96+ assert final_job ["file_count" ] == 1
97+ assert final_job ["engine" ] == "yt-dlp"
9398 assert final_job ["cookie_match_mode" ] == "none"
9499
95100
101+ def test_create_download_job_with_gallery_engine (client ):
102+ res = client .post ("/api/download/jobs" , json = {"url" : "https://example.com/post" , "engine" : "gallery-dl" })
103+ data = res .get_json ()
104+ assert res .status_code == 200
105+ assert data ["success" ] is True
106+ final_job = _wait_for_job (client , data ["data" ]["job" ]["id" ])
107+ assert final_job ["status" ] == "success"
108+ assert final_job ["engine" ] == "gallery-dl"
109+
110+
111+ def test_create_download_job_rejects_invalid_engine (client ):
112+ res = client .post ("/api/download/jobs" , json = {"url" : "https://example.com/video" , "engine" : "wget" })
113+ data = res .get_json ()
114+ assert res .status_code == 400
115+ assert data ["success" ] is False
116+ assert "engine" in data ["error" ]
117+
118+
119+ def test_detail_route_redirects_image_to_image_view (client ):
120+ media_root = client .application .config ["MEDIA_ROOT" ]
121+ image_file = media_root / "from-download.JPG"
122+ image_file .write_bytes (b"\x89 PNG\r \n " )
123+
124+ res = client .get ("/detail/from-download.JPG" , follow_redirects = False )
125+ assert res .status_code in {301 , 302 , 308 }
126+ location = res .headers .get ("Location" , "" )
127+ assert location .startswith ("/image?uri=" )
128+ assert "from-download.JPG" in location
129+
130+
96131def test_create_download_job_validation (client ):
97132 res = client .post ("/api/download/jobs" , json = {"url" : "file:///tmp/a.mp4" })
98133 data = res .get_json ()
@@ -128,6 +163,7 @@ def test_download_probe_api(client):
128163 assert res .status_code == 200
129164 assert data ["success" ] is True
130165 assert "yt_dlp_available" in data ["data" ]
166+ assert "gallery_dl_available" in data ["data" ]
131167 assert "ffmpeg_available" in data ["data" ]
132168
133169
@@ -200,7 +236,7 @@ def fail_execute(self, job_id): # noqa: ARG001
200236 return 1 , "network" , ""
201237
202238 monkeypatch .setattr ("tiklocal.services.downloader.DownloadManager._execute_download" , fail_execute )
203- res = client .post ("/api/download/jobs" , json = {"url" : "https://example.com/fail" })
239+ res = client .post ("/api/download/jobs" , json = {"url" : "https://example.com/fail" , "engine" : "gallery-dl" })
204240 data = res .get_json ()
205241 assert res .status_code == 200
206242 failed_job = _wait_for_job (client , data ["data" ]["job" ]["id" ])
@@ -216,6 +252,7 @@ def ok_execute(self, job_id): # noqa: ARG001
216252 new_job_id = retry_data ["data" ]["job" ]["id" ]
217253 assert new_job_id != failed_job ["id" ]
218254 assert retry_data ["data" ]["job" ]["retry_of" ] == failed_job ["id" ]
255+ assert retry_data ["data" ]["job" ]["engine" ] == "gallery-dl"
219256 final = _wait_for_job (client , new_job_id )
220257 assert final ["status" ] == "success"
221258
0 commit comments