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, nation): root = Path(__file__).parent image_path = str(root / image_path) r = send_request(image_path, '0') self.assertEqual(nation, r['result']['ethnicity']['text'], f'{image_path} ethnicity case error') def test_01(self): image_path = '../images/false/miss_nation/01.png' self._helper(image_path, '汉') def test_03(self): image_path = '../images/false/miss_nation/03.jpg' self._helper(image_path, '汉') def test_08(self): image_path = '../images/false/miss_nation/08.jpg' self._helper(image_path, '汉') def test_09(self): image_path = '../images/false/miss_nation/09.jpg' self._helper(image_path, '汉') def test_10(self): image_path = '../images/false/miss_nation/10.jpg' self._helper(image_path, '汉') def test_11(self): image_path = '../images/false/miss_nation/11.jpg' self._helper(image_path, '回')