import unittest import base64 import requests url = 'http://localhost:8080' def send_request(image_path): with open(image_path, 'rb') as f: img_str: str = base64.encodebytes(f.read()).decode('utf-8') r = requests.post(f'{url}/ocr_system/regbook', json={'image': img_str}) print(r.json()) return r.json() class TestRegBookOcr(unittest.TestCase): def test_it_works(self): self.assertEqual(1, 1, 'it not works') def test_case_1(self): image_path = './images/1.jpg' r = send_request(image_path) self.assertEqual(r['status'], '000', 'status case error') self.assertEqual(r['result']['name']['text'], '苏婷', 'name case error') def test_case_2(self): image_path = './images/2.jpeg' r = send_request(image_path) self.assertEqual(r['status'], '000', 'status case error') self.assertEqual(r['result']['name']['text'], '孙也桐', 'name case error')