true_2_test.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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='2'):
  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. ))
  46. def test_case_01_0(self):
  47. image_path = '../images/2/10011800A11学籍学历证明001.png'
  48. self._helper(image_path, ResultItem(status='000',
  49. orientation=0,
  50. name='向龙',
  51. gender='男',
  52. admission_time='2008年9月1日',
  53. education_time='2012年6月30日',
  54. education_level='本科',
  55. education_type='普通高等教育',
  56. learning_type='普通全日制',
  57. school='泰山学院',
  58. major='应用心理学',
  59. number='104531201205000925'))
  60. def test_case_02_0(self):
  61. image_path = '../images/2/10044867A11学籍学历证明001.png'
  62. self._helper(image_path, ResultItem(status='000',
  63. orientation=0,
  64. name='胡磊',
  65. gender='男',
  66. admission_time='2012年9月1日',
  67. education_time='2016年7月1日',
  68. education_level='本科',
  69. education_type='普通高等教育',
  70. learning_type='普通全日制',
  71. school='红河学院',
  72. major='经济学',
  73. number='106871201605000620'))
  74. def test_case_03_0(self):
  75. image_path = '../images/2/10044923A11学籍学历证明001.png'
  76. self._helper(image_path, ResultItem(status='000',
  77. orientation=0,
  78. name='李国栋',
  79. gender='男',
  80. admission_time='2015年9月7日',
  81. education_time='2018年6月30日',
  82. education_level='专科',
  83. education_type='普通高等教育',
  84. learning_type='普通全日制',
  85. school='烟台职业学院',
  86. major='电子商务',
  87. number='123961201806109089'))
  88. def test_case_04_0(self):
  89. image_path = '../images/2/10045022A11学籍学历证明001.png'
  90. self._helper(image_path, ResultItem(status='000',
  91. orientation=0,
  92. name='张盛宇',
  93. gender='男',
  94. admission_time='2014年9月1日',
  95. education_time='2018年7月1日',
  96. education_level='本科',
  97. education_type='普通高等教育',
  98. learning_type='普通全日制',
  99. school='沈阳大学',
  100. major='环境工程',
  101. number='110351201805000659'))
  102. def test_case_05_0(self):
  103. image_path = '../images/2/10045286A11学籍学历证明001.png'
  104. self._helper(image_path, ResultItem(status='000',
  105. orientation=0,
  106. name='孟煜翔',
  107. gender='男',
  108. admission_time='2016年9月3日',
  109. education_time='2019年6月24日',
  110. education_level='专科',
  111. education_type='普通高等教育',
  112. learning_type='普通全日制',
  113. school='山东农业工程学院',
  114. major='环境艺术设计',
  115. number='144391201906001607'))
  116. def test_case_06_0(self):
  117. image_path = '../images/2/10045455A11学籍学历证明001.jpg'
  118. self._helper(image_path, ResultItem(status='000',
  119. orientation=0,
  120. name='王滢',
  121. gender='女',
  122. admission_time='2014年3月1日',
  123. education_time='2017年1月10日',
  124. education_level='专科',
  125. education_type='成人高等教育',
  126. learning_type='函授',
  127. school='黔南民族师范学院',
  128. major='语文教育',
  129. number='106705201706000196'))
  130. def test_case_07_0(self):
  131. image_path = '../images/2/10045568A11学籍学历证明001.jpg'
  132. self._helper(image_path, ResultItem(status='000',
  133. orientation=0,
  134. name='温振雄',
  135. gender='男',
  136. admission_time='2009年9月1日',
  137. education_time='2013年6月30日',
  138. education_level='本科',
  139. education_type='普通高等教育',
  140. learning_type='普通全日制',
  141. school='桂林理工大学',
  142. major='信息与计算科学',
  143. number='105961201305003535'))
  144. def test_case_08_0(self):
  145. image_path = '../images/2/10045573A11学籍学历证明001.JPG'
  146. self._helper(image_path, ResultItem(status='000',
  147. orientation=0,
  148. name='石福东',
  149. gender='男',
  150. admission_time='2012年9月12日',
  151. education_time='2015年7月15日',
  152. education_level='专科',
  153. education_type='普通高等教育',
  154. learning_type='普通全日制',
  155. school='内蒙古商贸职业学院',
  156. major='摄影摄像技术',
  157. number='126761201506003061'))
  158. def test_case_09_0(self):
  159. image_path = '../images/2/10046376A11学籍学历证明001.png'
  160. self._helper(image_path, ResultItem(status='000',
  161. orientation=0,
  162. name='冯驹驰',
  163. gender='男',
  164. admission_time='2009年9月15日',
  165. education_time='2012年7月15日',
  166. education_level='专科',
  167. education_type='普通高等教育',
  168. learning_type='普通全日制',
  169. school='内蒙古商贸职业学院',
  170. major='市场营销',
  171. number='126761201206002319'))
  172. def test_case_10_0(self):
  173. image_path = '../images/2/10046536A11学籍学历证明001.png'
  174. self._helper(image_path, ResultItem(status='000',
  175. orientation=0,
  176. name='张佳龙',
  177. gender='男',
  178. admission_time='2018年3月6日',
  179. education_time='2020年6月20日',
  180. education_level='本科',
  181. education_type='成人高等教育',
  182. learning_type='函授',
  183. school='青岛科技大学',
  184. major='制药工程',
  185. number='104265202005003447'))