ocr_test.py 973 B

123456789101112131415161718192021222324252627282930313233
  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/regbook', json={'image': img_str})
  9. print(r.json())
  10. return r.json()
  11. class TestRegBookOcr(unittest.TestCase):
  12. def test_it_works(self):
  13. self.assertEqual(1, 1, 'it not works')
  14. def test_case_1(self):
  15. image_path = './images/1.jpg'
  16. r = send_request(image_path)
  17. self.assertEqual(r['status'], '000', 'status case error')
  18. self.assertEqual(r['result']['name']['text'], '苏婷', 'name case error')
  19. def test_case_2(self):
  20. image_path = './images/2.jpeg'
  21. r = send_request(image_path)
  22. self.assertEqual(r['status'], '000', 'status case error')
  23. self.assertEqual(r['result']['name']['text'], '孙也桐', 'name case error')