import json import os import pytest import responses from tesseract import BBOXOCR @pytest.fixture def client(): from _wsgi import init_app app = init_app(model_class=BBOXOCR) app.config['TESTING'] = True with app.test_client() as client: yield client @pytest.fixture def model_dir_env(tmp_path, monkeypatch): model_dir = tmp_path / "model_dir" model_dir.mkdir() monkeypatch.setattr(BBOXOCR, 'MODEL_DIR', str(model_dir)) return model_dir def read_test_mage(file_name): image_path = os.path.join(os.path.dirname(__file__), "test_images", file_name) with open(image_path, "rb") as f: return f.read() @responses.activate def test_basic_interactions(client, model_dir_env): responses.add( responses.GET, "http://test_predict.easyocr.ml-backend.com/image.jpeg", body=read_test_mage("image.jpeg"), status=200, ) # draw first bbox response = client.post('/predict', json=json.loads('{"tasks": [{"id": 311, "annotations": [], "file_upload": "a79e939b-images.json", "drafts": [], "predictions": [], "data": {"image": "http://test_predict.easyocr.ml-backend.com/image.jpeg"}, "meta": {}, "created_at": "2024-03-19T23:15:01.004453Z", "updated_at": "2024-03-20T01:55:39.644616Z", "inner_id": 11, "total_annotations": 0, "cancelled_annotations": 0, "total_predictions": 0, "comment_count": 0, "unresolved_comment_count": 0, "last_comment_updated_at": null, "project": 3, "updated_by": 1, "comment_authors": []}], "project": "3.1710890019", "label_config": " \\n \\n \\n \\n \\n\\n