This commit is contained in:
2026-08-31 20:57:14 +02:00
parent 94fb6a8568
commit a32cc84a90
6 changed files with 159 additions and 26 deletions
+23
View File
@@ -1,4 +1,6 @@
import unittest
import time
from unittest.mock import patch
from app import app
from scraper import parse_distribution_labels, validate_maps_url
@@ -49,6 +51,27 @@ class ApiTests(unittest.TestCase):
response = app.test_client().post("/api/reviews", data=b"x" * 5000, content_type="application/json")
self.assertEqual(response.status_code, 413)
def test_reports_job_progress_and_result(self):
expected = {"total": 3, "average": 4.0, "ratings": {"5": 2, "4": 0, "3": 0, "2": 0, "1": 1}}
def fake_scrape(_url, progress):
progress(50, "Otwarto Chromium")
progress(99, "Pojawiły się liczniki")
return expected
client = app.test_client()
with patch("app.get_rating_distribution", side_effect=fake_scrape):
start = client.post("/api/reviews", json={"url": "https://maps.app.goo.gl/USRCto35jhoVtmj4A"})
self.assertEqual(start.status_code, 202)
job_id = start.get_json()["job_id"]
for _ in range(100):
job = client.get(f"/api/reviews/{job_id}").get_json()
if job["status"] == "complete":
break
time.sleep(0.005)
self.assertEqual(job["progress"], 100)
self.assertEqual(job["result"], expected)
if __name__ == "__main__":
unittest.main()