test_interface.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. print(suffix)
  21. self._helper(image_path, suffix)
  22. def test_idcard(self):
  23. image_path = './image/idcard.jpg'
  24. suffix = '/sfzsb/idcard' if 'sb' in envl else '/sfzsbtest/idcard'
  25. self._helper(image_path, suffix)
  26. def test_regbook(self):
  27. image_path = './image/regbook.jpg'
  28. suffix = '/hkbsb/regbook' if 'sb' in envl else '/hkbsbtest/regbook'
  29. self._helper(image_path, suffix)
  30. def test_schoolcert(self):
  31. image_path = './image/schoolcert.jpg'
  32. suffix = '/xxw/schoolcert' if 'sb' in envl else '/xxwtest/schoolcert'
  33. self._helper(image_path, suffix)
  34. def test_cet(self):
  35. image_path = './image/cet.jpg'
  36. suffix = '/cet/cet' if 'sb' in envl else '/cettest/cet'
  37. self._helper(image_path, suffix)
  38. def test_blef(self):
  39. image_path = './image/blfe.jpg'
  40. suffix = '/blfe/blfe' if 'sb' in envl else '/blfetest/blfe'
  41. self._helper(image_path, suffix)