import unittest import base64 from pathlib import Path import requests url = 'http://192.168.199.249: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, name): root = Path(__file__).parent image_path = str(root / image_path) r = send_request(image_path, '0') self.assertEqual(name, r['result']['name']['text'], f'{image_path} name case error') def test_01(self): image_path = '../images/false/miss_name/01.jpg' self._helper(image_path, '董建') def test_02(self): image_path = '../images/false/miss_name/02.jpg' self._helper(image_path, '朱变变') if __name__ == '__main__': unittest.main()