数据看板
This commit is contained in:
19
tests/test_data_dashboard_service.py
Normal file
19
tests/test_data_dashboard_service.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import unittest
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from data_dashboard_service import list_runs
|
||||
|
||||
|
||||
class DataDashboardServiceTest(unittest.TestCase):
|
||||
@patch("data_dashboard_service._request")
|
||||
def test_list_runs_normalizes_single_run(self, request):
|
||||
response = Mock()
|
||||
response.json.return_value = {"ok": True, "run": {"id": "sqa_1", "status": "completed"}}
|
||||
request.return_value = response
|
||||
result = list_runs(task_id="sqa_1")
|
||||
self.assertEqual(result["total"], 1)
|
||||
self.assertEqual(result["items"][0]["id"], "sqa_1")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
47
tests/test_ocr_dashboard_service.py
Normal file
47
tests/test_ocr_dashboard_service.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import unittest
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from ocr_dashboard_service import export_evidences, get_summary, list_batches, list_results
|
||||
from task_service import TaskError
|
||||
|
||||
|
||||
class OcrDashboardServiceTest(unittest.TestCase):
|
||||
@patch("ocr_dashboard_service.SESSION.get")
|
||||
def test_list_batches_unwraps_framework_response(self, get):
|
||||
response = Mock()
|
||||
response.json.return_value = {"success": True, "code": 200, "data": [{"batch_key": "b1"}]}
|
||||
get.return_value = response
|
||||
self.assertEqual(list_batches()[0]["batch_key"], "b1")
|
||||
|
||||
@patch("ocr_dashboard_service.SESSION.get")
|
||||
def test_summary_forwards_scope(self, get):
|
||||
response = Mock()
|
||||
response.json.return_value = {"success": True, "code": 200, "data": {"questions": []}}
|
||||
get.return_value = response
|
||||
get_summary("b1", "c1")
|
||||
self.assertEqual(get.call_args.kwargs["params"], {"batch_key": "b1", "collection_key": "c1"})
|
||||
|
||||
def test_results_rejects_oversized_page(self):
|
||||
with self.assertRaises(TaskError):
|
||||
list_results({"page_size": "201"})
|
||||
|
||||
@patch("ocr_dashboard_service.SESSION.get")
|
||||
@patch("ocr_dashboard_service.list_evidences")
|
||||
def test_export_evidences_builds_zip(self, list_evidences, get):
|
||||
list_evidences.return_value = {"items": [{
|
||||
"question_code": "Q1", "search_keyword": "山姆会员卡", "device_code": "DEV-1",
|
||||
"city": "厦门", "sort_order": 1, "source_file_name": "shot.jpg",
|
||||
"cos_url": "https://bucket.cos.ap-guangzhou.myqcloud.com/shot.jpg",
|
||||
}]}
|
||||
response = Mock(content=b"image-bytes")
|
||||
get.return_value = response
|
||||
|
||||
payload, filename, count = export_evidences({"batch_key": "b1", "collection_key": "c1"})
|
||||
|
||||
self.assertEqual(filename, "holy-crab-evidences-all.zip")
|
||||
self.assertEqual(count, 1)
|
||||
self.assertTrue(payload.read(2) == b"PK")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user