test_interface.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import base64
  2. from pathlib import Path
  3. import unittest
  4. import config
  5. from config import send_request
  6. image_path = 'image'
  7. # TX_test, TX_sb, DX_test, DX_sb
  8. envl = 'DX_test'
  9. url = config.URL[envl]
  10. token = config.TOKEN[envl]
  11. class TestOcr(unittest.TestCase):
  12. def _helper(self, image_path, suffix):
  13. root = Path(__file__).parent
  14. image_path = str(root / image_path)
  15. r = send_request(image_path, suffix, url, token)
  16. self.assertIn('result', r, f'{suffix} test error')
  17. def test_bank(self):
  18. image_path = './image/bankcard.jpg'
  19. suffix = '/yhksb/bankcard' if 'sb' in envl else '/yhksbtest/bankcard'
  20. self._helper(image_path, suffix)
  21. def test_idcard(self):
  22. image_path = './image/idcard.jpg'
  23. suffix = '/sfzsb/idcard' if 'sb' in envl else '/sfzsbtest/idcard'
  24. self._helper(image_path, suffix)
  25. def test_regbook(self):
  26. image_path = './image/regbook.jpg'
  27. suffix = '/hkbsb/regbook' if 'sb' in envl else '/hkbsbtest/regbook'
  28. self._helper(image_path, suffix)
  29. def test_schoolcert(self):
  30. image_path = './image/schoolcert.jpg'
  31. suffix = '/xxw/schoolcert' if 'sb' in envl else '/xxwtest/schoolcert'
  32. self._helper(image_path, suffix)
  33. def test_cet(self):
  34. image_path = './image/cet.jpg'
  35. suffix = '/cet/cet' if 'sb' in envl else '/cettest/cet'
  36. self._helper(image_path, suffix)
  37. def test_blef(self):
  38. image_path = './image/blfe.jpg'
  39. suffix = '/blfe/blfe' if 'sb' in envl else '/blfetest/blfe'
  40. self._helper(image_path, suffix)