import base64 import unittest from pathlib import Path import requests url = 'http://192.168.199.208:18081' def send_request(image_path, image_type): with open(image_path, 'rb') as f: img_str: str = base64.encodebytes(f.read()).decode('utf-8') r = requests.post(f'{url}/ocr_system/idcard', json={'image': img_str, 'image_type': image_type}) print(r.json()) return r.json() class TestIdCardAddress(unittest.TestCase): def _helper(self, image_path): root = Path(__file__).parent image_path = str(root / image_path) r = send_request(image_path, 0) self.assertEqual(r['status'], '000', f'{image_path}status case error') # 难 def test_06(self): image_path = '../images/false/others/06.jpg' self._helper(image_path) # 难 def test_07(self): image_path = '../images/false/others/07.jpg' self._helper(image_path) # 北京市宣武区cpca错误 def test_cpca(self): image_path = '../images/false/others/cpca.png' self._helper(image_path) def test_long_name(self): image_path = '../images/false/others/long_name.png' self._helper(image_path)