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/idcard', json={'image': img_str, 'image_type': '0'}) return r.json() class TestIdCardOcr(unittest.TestCase): def test_it_works(self): self.assertEqual(1, 1, 'it not works') def test_front_180(self): image_path = './images/front-180.png' r = send_request(image_path) self.assertEqual(r['status'], '000', 'status case error') self.assertEqual(r['result']['orientation'], 2, 'orientation case error') def test_front_270(self): image_path = './images/front-270.png' r = send_request(image_path) self.assertEqual(r['status'], '000', 'status case error') self.assertEqual(r['result']['orientation'], 3, 'orientation case error')