true_test.py 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import unittest
  2. from dataclasses import dataclass
  3. from pathlib import Path
  4. from testing.utils import *
  5. @dataclass
  6. class ResultItem:
  7. status: str
  8. orientation: int
  9. name: str
  10. id: str
  11. ethnicity: str
  12. gender: str
  13. birthday: str
  14. address: str
  15. class TestIdCardAddress(unittest.TestCase):
  16. def _helper(self, image_path, item: ResultItem):
  17. root = Path(__file__).parent
  18. image_path = str(root / image_path)
  19. r = send_request(image_path, '0')
  20. self.assertEqual(item.status, r['status'], f'{image_path} status case error')
  21. self.assertEqual(item.orientation, r['result']['orientation'], f'{image_path} orientation case error')
  22. self.assertEqual(item.name, r['result']['name']['text'], f'{image_path} name case error')
  23. self.assertEqual(item.id, r['result']['id']['text'], f'{image_path} id case error')
  24. self.assertEqual(item.ethnicity, r['result']['ethnicity']['text'], f'{image_path} ethnicity case error')
  25. self.assertEqual(item.gender, r['result']['gender']['text'], f'{image_path} gender case error')
  26. self.assertEqual(item.birthday, r['result']['birthday']['text'], f'{image_path} birthday case error')
  27. self.assertEqual(item.address, r['result']['address']['text'], f'{image_path} address case error')
  28. def test_01(self):
  29. image_path = '../images/ture/01.jpg'
  30. self._helper(image_path, ResultItem(status='000',
  31. orientation=0,
  32. name='宋宝磊',
  33. id='150430199905051616',
  34. ethnicity='汉',
  35. gender='男',
  36. birthday='1999年05月05日',
  37. address='内蒙古赤峰市敖汉旗四家子镇林家地村唐坊沟七组'))
  38. def test_02(self):
  39. image_path = '../images/ture/02.jpg'
  40. self._helper(image_path, ResultItem(status='000',
  41. orientation=2,
  42. name='方势文',
  43. id='360428199610220096',
  44. ethnicity='汉',
  45. gender='男',
  46. birthday='1996年10月22日',
  47. address='江西省九江市都昌县都昌镇沿湖路238号'))
  48. def test_03(self):
  49. image_path = '../images/ture/03.jpg'
  50. self._helper(image_path, ResultItem(status='000',
  51. orientation=0,
  52. name='彭贤端',
  53. id='450922199412083669',
  54. ethnicity='汉',
  55. gender='女',
  56. birthday='1994年12月08日',
  57. address='广西陆川县清湖镇塘寨村新屋队62号'))
  58. def test_04(self):
  59. image_path = '../images/ture/04.png'
  60. self._helper(image_path, ResultItem(status='000',
  61. orientation=0,
  62. name='王晓凤',
  63. id='150921199910021527',
  64. ethnicity='汉',
  65. gender='女',
  66. birthday='1999年10月02日',
  67. address='呼和浩特市新城区赛马场北路城市维也纳13号楼2单元1303号'))
  68. def test_05(self):
  69. image_path = '../images/ture/05.jpg'
  70. self._helper(image_path, ResultItem(status='000',
  71. orientation=0,
  72. name='任学东',
  73. id='152630198501117517',
  74. ethnicity='汉',
  75. gender='男',
  76. birthday='1985年01月11日',
  77. address='内蒙古乌兰察布市察哈尔右翼前旗巴音塔拉镇谢家村22户'))
  78. def test_06(self):
  79. image_path = '../images/ture/06.jpg'
  80. self._helper(image_path, ResultItem(status='000',
  81. orientation=0,
  82. name='田浩',
  83. id='640221199702060618',
  84. ethnicity='汉',
  85. gender='男',
  86. birthday='1997年02月06日',
  87. address='宁夏平罗县黄渠桥镇侯家梁村二队29'))
  88. def test_07_0(self):
  89. image_path = '../images/ture/07_0.jpg'
  90. self._helper(image_path, ResultItem(status='000',
  91. orientation=0,
  92. name='左翔宇',
  93. id='220204199910123017',
  94. ethnicity='蒙古',
  95. gender='男',
  96. birthday='1999年10月12日',
  97. address='吉林省吉林市船营区鑫安小区2-6-60号'))
  98. def test_07_90(self):
  99. image_path = '../images/ture/07_90.jpg'
  100. self._helper(image_path, ResultItem(status='000',
  101. orientation=1,
  102. name='左翔宇',
  103. id='220204199910123017',
  104. ethnicity='蒙古',
  105. gender='男',
  106. birthday='1999年10月12日',
  107. address='吉林省吉林市船营区鑫安小区2-6-60号'))
  108. def test_07_180(self):
  109. image_path = '../images/ture/07_180.jpg'
  110. self._helper(image_path, ResultItem(status='000',
  111. orientation=2,
  112. name='左翔宇',
  113. id='220204199910123017',
  114. ethnicity='蒙古',
  115. gender='男',
  116. birthday='1999年10月12日',
  117. address='吉林省吉林市船营区鑫安小区2-6-60号'))
  118. def test_08_0(self):
  119. image_path = '../images/ture/08_0.jpg'
  120. self._helper(image_path, ResultItem(status='000',
  121. orientation=0,
  122. name='张开天',
  123. id='622301199710247376',
  124. ethnicity='汉',
  125. gender='男',
  126. birthday='1997年10月24日',
  127. address='甘肃省武威市凉州区九墩乡平乐村四组23号'))
  128. def test_08_180(self):
  129. image_path = '../images/ture/08_180.jpg'
  130. self._helper(image_path, ResultItem(status='000',
  131. orientation=2,
  132. name='张开天',
  133. id='622301199710247376',
  134. ethnicity='汉',
  135. gender='男',
  136. birthday='1997年10月24日',
  137. address='甘肃省武威市凉州区九墩乡平乐村四组23号'))
  138. def test_09(self):
  139. image_path = '../images/ture/09.jpeg'
  140. self._helper(image_path, ResultItem(status='000',
  141. orientation=0,
  142. name='韩毅',
  143. id='211102199912162010',
  144. ethnicity='汉',
  145. gender='男',
  146. birthday='1999年12月16日',
  147. address=
  148. '辽宁省盘锦市双台子区胜利街道团结社区15区40号'))
  149. def test_10(self):
  150. image_path = '../images/ture/10.jpg'
  151. self._helper(image_path, ResultItem(status='000',
  152. orientation=0,
  153. name='曾令权',
  154. id='432524199306221414',
  155. ethnicity='汉',
  156. gender='男',
  157. birthday='1993年06月22日',
  158. address='湖南省新化县维山乡官庄村陈家冲组21号'))
  159. if __name__ == '__main__':
  160. unittest.main()