ocr_test.py 980 B

123456789101112131415161718192021222324252627282930
  1. import unittest
  2. import base64
  3. import requests
  4. url = 'http://localhost:8080'
  5. def send_request(image_path):
  6. with open(image_path, 'rb') as f:
  7. img_str: str = base64.encodebytes(f.read()).decode('utf-8')
  8. r = requests.post(f'{url}/ocr_system/idcard', json={'image': img_str, 'image_type': '0'})
  9. return r.json()
  10. class TestIdCardOcr(unittest.TestCase):
  11. def test_it_works(self):
  12. self.assertEqual(1, 1, 'it not works')
  13. def test_front_180(self):
  14. image_path = './images/front-180.png'
  15. r = send_request(image_path)
  16. self.assertEqual(r['status'], '000', 'status case error')
  17. self.assertEqual(r['result']['orientation'], 2, 'orientation case error')
  18. def test_front_270(self):
  19. image_path = './images/front-270.png'
  20. r = send_request(image_path)
  21. self.assertEqual(r['status'], '000', 'status case error')
  22. self.assertEqual(r['result']['orientation'], 3, 'orientation case error')