all_test.py 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import unittest
  2. from dataclasses import dataclass
  3. from pathlib import Path
  4. import pytest
  5. from testing.utils import *
  6. @dataclass
  7. class ResultItem:
  8. status: str
  9. orientation: int
  10. name: str
  11. id: str
  12. ethnicity: str
  13. gender: str
  14. birthday: str
  15. address: str
  16. class TestIdCard0(unittest.TestCase):
  17. def _helper(self, image_path, item: ResultItem):
  18. root = Path(__file__).parent
  19. image_path = str(root / image_path)
  20. r = send_request(image_path, '0')
  21. self.assertEqual(item, ResultItem(status=r['status'],
  22. orientation=r['result']['orientation'],
  23. name=r['result']['name']['text'],
  24. id=r['result']['id']['text'],
  25. ethnicity=r['result']['ethnicity']['text'],
  26. gender=r['result']['gender']['text'],
  27. birthday=r['result']['birthday']['text'],
  28. address=r['result']['address']['text']
  29. ))
  30. def test_01_0(self):
  31. image_path = '../images/all/0/01_0.jpg'
  32. self._helper(image_path, ResultItem(status='000',
  33. orientation=0,
  34. name='左翔宇',
  35. id='220204199910123017',
  36. ethnicity='蒙古',
  37. gender='男',
  38. birthday='1999年10月12日',
  39. address='吉林省吉林市船营区鑫安小区2-6-60号'))
  40. def test_02_90(self):
  41. image_path = '../images/all/0/02_90.jpg'
  42. self._helper(image_path, ResultItem(status='000',
  43. orientation=1,
  44. name='张开天',
  45. id='622301199710247376',
  46. ethnicity='汉',
  47. gender='男',
  48. birthday='1997年10月24日',
  49. address='甘肃省武威市凉州区九墩乡平乐村四组23号'))
  50. def test_03_0(self):
  51. image_path = '../images/all/0/03_0(minor).jpg'
  52. self._helper(image_path, ResultItem(status='000',
  53. orientation=0,
  54. name='张荣军',
  55. id='654122199712254017',
  56. ethnicity='锡伯',
  57. gender='男',
  58. birthday='1997年12月25日',
  59. address='新疆察布查尔锡伯自治县堆齐牛录乡杜林拜北街西二巷29号'))
  60. def test_04_180(self):
  61. image_path = '../images/all/0/04_180.jpg'
  62. self._helper(image_path, ResultItem(status='000',
  63. orientation=2,
  64. name='方势文',
  65. id='360428199610220096',
  66. ethnicity='汉',
  67. gender='男',
  68. birthday='1996年10月22日',
  69. address='江西省九江市都昌县都昌镇沿湖路238号'))
  70. def test_05_270(self):
  71. image_path = '../images/all/0/05_270.jpg'
  72. self._helper(image_path, ResultItem(status='000',
  73. orientation=3,
  74. name='孔一凡',
  75. id='310102198710034449',
  76. ethnicity='汉',
  77. gender='女',
  78. birthday='1987年10月03日',
  79. address='上海市黄浦区静修路79弄5号'))
  80. def test_addreess(self):
  81. image_path = '../images/all/0/address.png'
  82. self._helper(image_path, ResultItem(status='000',
  83. orientation=0,
  84. name='王磊',
  85. id='150203199308092110',
  86. ethnicity='汉',
  87. gender='男',
  88. birthday='1993年08月09日',
  89. address='内蒙古包头市昆都仑区昆河镇刘二圪梁村393号'))
  90. def test_long_name(self):
  91. image_path = '../images/all/0/long_name.png'
  92. self._helper(image_path, ResultItem(status='000',
  93. orientation=0,
  94. name='叶干别尔地·坎吉巴依',
  95. id='653024199812031239',
  96. ethnicity='柯尔克孜',
  97. gender='男',
  98. birthday='1998年12月03日',
  99. address='南京市栖霞区文苑路1号'))
  100. def test_mohu(self):
  101. image_path = '../images/all/0/mohu.jpg'
  102. self._helper(image_path, ResultItem(status='000',
  103. orientation=0,
  104. name='田浩',
  105. id='640221199702060618',
  106. ethnicity='汉',
  107. gender='男',
  108. birthday='1997年02月06日',
  109. address='宁夏平罗县黄渠桥镇侯家梁村二队29'))
  110. def test_mohu_90(self):
  111. image_path = '../images/all/0/mohu_90.jpg'
  112. self._helper(image_path, ResultItem(status='000',
  113. orientation=1,
  114. name='王睿',
  115. id='421202199506051096',
  116. ethnicity='汉',
  117. gender='男',
  118. birthday='1995年06月05日',
  119. address='湖北省咸宁市咸安区温泉淦河大道12号'))
  120. def test_small(self):
  121. image_path = '../images/all/0/small.jpg'
  122. self._helper(image_path, ResultItem(status='000',
  123. orientation=0,
  124. name='董建',
  125. id='654121199802042775',
  126. ethnicity='回',
  127. gender='男',
  128. birthday='1998年02月04日',
  129. address='新疆伊宁县愉群翁乡伊克翁村216号'))
  130. def test_special1(self):
  131. image_path = '../images/all/0/special1.jpg'
  132. self._helper(image_path, ResultItem(status='000',
  133. orientation=0,
  134. name='宋宝磊',
  135. id='150430199905051616',
  136. ethnicity='汉',
  137. gender='男',
  138. birthday='1999年05月05日',
  139. address='内蒙古赤峰市敖汉旗四家子镇林家地村唐坊沟七组'))
  140. def test_special2(self):
  141. image_path = '../images/all/0/special2.jpg'
  142. self._helper(image_path, ResultItem(status='000',
  143. orientation=0,
  144. name='彭贤端',
  145. id='450922199412083669',
  146. ethnicity='汉',
  147. gender='女',
  148. birthday='1994年12月08日',
  149. address='广西陆川县清湖镇塘寨村新屋队62号'))
  150. @pytest.mark.parametrize(
  151. "image_path, status, orientation, expire_date",
  152. [
  153. (Path('../images/all/1/01_0.jpg'), '000', 0, '20220511-20420511'),
  154. (Path('../images/all/1/02_270.jpg'), '000', 3, '20180531-20280531'),
  155. (Path('../images/all/1/03_180.jpg'), '000', 2, '20170109-20270109'),
  156. (Path('../images/all/1/04_90.jpg'), '000', 1, '20190715-20390715'),
  157. (Path('../images/all/1/05-270.jpg'), '000', 3, '20140320-20240320'),
  158. (Path('../images/all/1/small.png'), '000', 0, '20190620-20290620'),
  159. (Path('../images/all/1/special.jpg'), '000', 0, '20190813-20290813'),
  160. ]
  161. )
  162. def test_back_side(image_path, status, orientation, expire_date):
  163. root = Path(__file__).parent
  164. image_path = str(root / image_path)
  165. r = send_request(image_path, '1')
  166. if r['status'] == '000':
  167. assert (r['result']['expire_date']['text'], r['result']['orientation']) == (expire_date, orientation)
  168. else:
  169. assert r['status'] == status
  170. if __name__ == '__main__':
  171. unittest.main()