true_test.py 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import base64
  2. import unittest
  3. from pathlib import Path
  4. import requests
  5. url = 'http://192.168.199.208:18081'
  6. def send_request(image_path, image_type):
  7. with open(image_path, 'rb') as f:
  8. img_str: str = base64.encodebytes(f.read()).decode('utf-8')
  9. r = requests.post(f'{url}/ocr_system/idcard', json={'image': img_str, 'image_type': image_type})
  10. print(r.json())
  11. return r.json()
  12. class TestIdCardAddress(unittest.TestCase):
  13. def _helper(self, image_path, sta, orient, name, id, ethnicity, gender, birthday, address):
  14. root = Path(__file__).parent
  15. image_path = str(root / image_path)
  16. r = send_request(image_path, '0')
  17. self.assertEqual(sta, r['status'], f'{image_path} status case error')
  18. self.assertEqual(orient, r['result']['orientation'], f'{image_path} orientation case error')
  19. self.assertEqual(name, r['result']['name']['text'], f'{image_path} name case error')
  20. self.assertEqual(id, r['result']['id']['text'], f'{image_path} id case error')
  21. self.assertEqual(ethnicity, r['result']['ethnicity']['text'], f'{image_path} ethnicity case error')
  22. self.assertEqual(gender, r['result']['gender']['text'], f'{image_path} gender case error')
  23. self.assertEqual(birthday, r['result']['birthday']['text'], f'{image_path} birthday case error')
  24. self.assertEqual(address, r['result']['address']['text'], f'{image_path} address case error')
  25. def test_01(self):
  26. image_path = '../images/ture/01.jpg'
  27. self._helper(image_path, '000', 0, '宋宝磊', '150430199905051616', '汉', '男', '1999年05月05日',
  28. '内蒙古赤峰市敖汉旗四家子镇林家地村唐坊沟七组')
  29. def test_02(self):
  30. image_path = '../images/ture/02.jpg'
  31. self._helper(image_path, '000', 2, '方势文', '360428199610220096', '汉', '男', '1996年10月22日', '江西省九江市都昌县都昌镇沿湖路238号')
  32. def test_03(self):
  33. image_path = '../images/ture/03.jpg'
  34. self._helper(image_path, '000', 0, '彭贤端', '450922199412083669', '汉', '女', '1994年12月08日', '广西陆川县清湖镇塘寨村新屋队62号')
  35. def test_04(self):
  36. image_path = '../images/ture/04.png'
  37. self._helper(image_path, '000', 0, '王晓凤', '150921199910021527', '汉', '女', '1999年10月02日',
  38. '呼和浩特市新城区赛马场北路城市维也纳13号楼2单元1303号')
  39. def test_05(self):
  40. image_path = '../images/ture/05.jpg'
  41. self._helper(image_path, '000', 0, '任学东', '152630198501117517', '汉', '男', '1985年01月11日',
  42. '内蒙古乌兰察布市察哈尔右翼前旗巴音塔拉镇谢家村22户')
  43. def test_06(self):
  44. image_path = '../images/ture/06.jpg'
  45. self._helper(image_path, '000', 0, '田浩', '640221199702060618', '汉', '男', '1997年02月06日', '宁夏平罗县黄渠桥镇侯家梁村二队29')
  46. def test_07_0(self):
  47. image_path = '../images/ture/07_0.jpg'
  48. self._helper(image_path, '000', 0, '左翔宇', '220204199910123017', '蒙古', '男', '1999年10月12日',
  49. '吉林省吉林市船营区鑫安小区2-6-60号')
  50. def test_07_90(self):
  51. image_path = '../images/ture/07_90.jpg'
  52. self._helper(image_path, '000', 1, '左翔宇', '220204199910123017', '蒙古', '男', '1999年10月12日',
  53. '吉林省吉林市船营区鑫安小区2-6-60号')
  54. def test_07_180(self):
  55. image_path = '../images/ture/07_180.jpg'
  56. self._helper(image_path, '000', 2, '左翔宇', '220204199910123017', '蒙古', '男', '1999年10月12日',
  57. '吉林省吉林市船营区鑫安小区2-6-60号')
  58. def test_08_0(self):
  59. image_path = '../images/ture/08_0.jpg'
  60. self._helper(image_path, '000', 0, '张开天', '622301199710247376', '汉', '男', '1997年10月24日', '甘肃省武威市凉州区九墩乡平乐村四组23号')
  61. def test_08_180(self):
  62. image_path = '../images/ture/08_180.jpg'
  63. self._helper(image_path, '000', 2, '张开天', '622301199710247376', '汉', '男', '1997年10月24日', '甘肃省武威市凉州区九墩乡平乐村四组23号')
  64. def test_09(self):
  65. image_path = '../images/ture/09.jpeg'
  66. self._helper(image_path, '000', 0, '韩毅', '211102199912162010', '汉', '男', '1999年12月16日',
  67. '辽宁省盘锦市双台子区胜利街道团结社区15区40号')
  68. def test_10(self):
  69. image_path = '../images/ture/10.jpg'
  70. self._helper(image_path, '000', 0, '曾令权', '432524199306221414', '汉', '男', '1993年06月22日', '湖南省新化县维山乡官庄村陈家冲组21号')
  71. if __name__ == '__main__':
  72. unittest.main()