test_interface.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import base64
  2. from pathlib import Path
  3. import unittest
  4. import requests
  5. import config
  6. from config import send_request
  7. image_path = 'image'
  8. # test, sb ,idc
  9. url = config.URL['sb']
  10. token = config.TOKEN['sb']
  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'
  20. self._helper(image_path, suffix)
  21. def test_idcard(self):
  22. image_path = './image/idcard.jpg'
  23. suffix = '/sfzsb/idcard'
  24. self._helper(image_path, suffix)
  25. def test_regbook(self):
  26. image_path = './image/regbook.jpg'
  27. suffix = '/hkbsb/regbook'
  28. self._helper(image_path, suffix)
  29. def test_schoolcert(self):
  30. image_path = './image/schoolcert.jpg'
  31. suffix = '/xxw/schoolcert'
  32. self._helper(image_path, suffix)
  33. def test_cet(self):
  34. image_path = './image/cet.jpg'
  35. suffix = '/cet/cet'
  36. self._helper(image_path, suffix)
  37. # 测试营业执照
  38. URL = config.URL['blfe']
  39. token1 = config.TOKEN['blfe']
  40. class TestBlfeOcr(unittest.TestCase):
  41. def _helper(self, image_path, suffix):
  42. root = Path(__file__).parent
  43. image_path = str(root / image_path)
  44. r = send_request(image_path, suffix, URL, token)
  45. self.assertIn('result', r, f'{suffix} test error')
  46. def test_blfe(self):
  47. image_path = './image/blfe.jpg'
  48. suffix = '/blfetest/blfe'
  49. self._helper(image_path, suffix)