true_0_test.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import unittest
  2. import base64
  3. from dataclasses import dataclass
  4. from pathlib import Path
  5. import requests
  6. url = 'http://localhost:8080'
  7. # 带线框识别比较差 例:6.27_02.png
  8. def send_request(image_path, image_type):
  9. with open(image_path, 'rb') as f:
  10. img_str: str = base64.encodebytes(f.read()).decode('utf-8')
  11. r = requests.post(f'{url}/ocr_system/schoolcert', json={'image': img_str, 'image_type': image_type})
  12. print(r.json())
  13. return r.json()
  14. @dataclass
  15. class ResultItem:
  16. status: str
  17. orientation: int
  18. name: str
  19. gender: str
  20. admission_time: str
  21. education_time: str
  22. education_level: str
  23. education_type: str
  24. learning_type: str
  25. school: str
  26. major: str
  27. number: str
  28. class TestSchoolCertOcr(unittest.TestCase):
  29. def _helper(self, image_path, item: ResultItem, image_type='0'):
  30. root = Path(__file__).parent
  31. image_path = str(root / image_path)
  32. r = send_request(image_path, image_type)
  33. self.assertEqual(item, ResultItem(status=r['status'],
  34. orientation=r['result']['orientation'],
  35. name=r['result']['name']['text'],
  36. gender=r['result']['gender']['text'],
  37. admission_time=r['result']['admission_time']['text'],
  38. education_time=r['result']['education_time']['text'],
  39. education_type=r['result']['education_type']['text'],
  40. education_level=r['result']['education_level']['text'],
  41. learning_type=r['result']['learning_type']['text'],
  42. school=r['result']['school']['text'],
  43. major=r['result']['major']['text'],
  44. number=r['result']['number']['text']))
  45. def test_case_01_0(self):
  46. image_path = '../images/0/10050464A11学籍学历证明001.JPG'
  47. self._helper(image_path, ResultItem(status='000',
  48. orientation=0,
  49. name='郑思龙',
  50. gender='男',
  51. admission_time='2019年09月01日',
  52. education_time='2022年07月01日',
  53. education_level='专科',
  54. education_type='普通高等教育',
  55. learning_type='普通全日制',
  56. school='黑龙江农垦职业学院',
  57. major='食品加工技术',
  58. number=''))
  59. def test_case_02_0(self):
  60. image_path = '../images/0/10051793A11学籍学历证明001.JPG'
  61. self._helper(image_path, ResultItem(status='000',
  62. orientation=0,
  63. name='白传旭',
  64. gender='男',
  65. admission_time='2019年09月01日',
  66. education_time='2022年07月01日',
  67. education_level='专科',
  68. education_type='普通高等教育',
  69. learning_type='普通全日制',
  70. school='黑龙江民族职业学院',
  71. major='食品检测技术',
  72. number=''))
  73. def test_case_03_0(self):
  74. image_path = '../images/0/10051795A11学籍学历证明001.JPG'
  75. self._helper(image_path, ResultItem(status='000',
  76. orientation=0,
  77. name='冯鹏宇',
  78. gender='男',
  79. admission_time='2019年09月01日',
  80. education_time='2022年07月01日',
  81. education_level='专科',
  82. education_type='普通高等教育',
  83. learning_type='普通全日制',
  84. school='黑龙江民族职业学院',
  85. major='食品加工技术',
  86. number=''))
  87. def test_case_04_0(self):
  88. image_path = '../images/0/10052117A11学籍学历证明001.JPG'
  89. self._helper(image_path, ResultItem(status='000',
  90. orientation=0,
  91. name='刘泽瑾',
  92. gender='女',
  93. admission_time='2017年09月01日',
  94. education_time='2021年07月01日',
  95. education_level='本科',
  96. education_type='普通高等教育',
  97. learning_type='普通全日制',
  98. school='华南理工大学',
  99. major='食品质量与安全',
  100. number=''))
  101. def test_case_05_0(self):
  102. image_path = '../images/0/10052164A11学籍学历证明001.JPG'
  103. self._helper(image_path, ResultItem(status='000',
  104. orientation=0,
  105. name='蒋嘉璐',
  106. gender='男',
  107. admission_time='2019年09月01日',
  108. education_time='2022年07月01日',
  109. education_level='专科',
  110. education_type='普通高等教育',
  111. learning_type='普通全日制',
  112. school='黑龙江民族职业学院',
  113. major='食品加工技术',
  114. number=''))
  115. def test_case_06_0(self):
  116. image_path = '../images/0/10052165A11学籍学历证明001.JPG'
  117. self._helper(image_path, ResultItem(status='000',
  118. orientation=0,
  119. name='班玉雪',
  120. gender='女',
  121. admission_time='2019年09月01日',
  122. education_time='2022年07月01日',
  123. education_level='专科',
  124. education_type='普通高等教育',
  125. learning_type='普通全日制',
  126. school='黑龙江民族职业学院',
  127. major='食品质量与安全',
  128. number=''))
  129. def test_case_07_0(self):
  130. image_path = '../images/0/10055552A11学籍学历证明001.JPG'
  131. self._helper(image_path, ResultItem(status='000',
  132. orientation=0,
  133. name='高健',
  134. gender='男',
  135. admission_time='2020年09月01日',
  136. education_time='2022年06月30日',
  137. education_level='本科',
  138. education_type='普通高等教育',
  139. learning_type='普通全日制',
  140. school='武汉生物工程学院',
  141. major='机械设计制造及其自动化',
  142. number=''))