123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- import unittest
- from pathlib import Path
- from testing.utils import *
- class TestIdCardTmp(unittest.TestCase):
- def _helper(self, image_path, item: ResultItem, rotate=None):
- rotate = None if not rotate else rotate - 1
- root = Path(__file__).parent
- image_path = str(root / image_path)
- if rotate is None:
- r = send_request(image_path, '0')
- else:
- r = send_request_cv2(image_path, '0', rotate)
- if r['status'] == '000':
- actual = {}
- for k, v in r['result'].items():
- if isinstance(v, dict):
- actual[k] = v['text']
- continue
- actual[k] = v
- del actual['confidence']
- print(actual)
- self.assertEqual(item, ResultItem(**actual))
- else:
- self.assertEqual('101', r['status'])
- def test_01(self):
- image_path = '../images/tmp/02_img.jpg'
- rotate = 2
- input = {'card_type': '0',
- 'orientation': rotate,
- 'name': '李荣',
- 'id': '62272519990210142X',
- 'ethnicity': '回',
- 'gender': '女',
- 'birthday': '1999年02月10日',
- 'address': '甘肃省华亭县石堡子开发区纪家庄居委会小庄居民小组141号',
- 'address_province': '甘肃省',
- 'address_city': '平凉市',
- 'address_region': '华亭县',
- 'address_detail': '石堡子开发区纪家庄居委会小庄居民小组141号',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- def test_02(self):
- image_path = '../images/tmp/10_img.jpg'
- rotate = 1
- input = {'card_type': '0',
- 'orientation': rotate,
- 'name': '张鹏',
- 'id': '652924199703300012',
- 'ethnicity': '汉',
- 'gender': '男',
- 'birthday': '1997年03月30日',
- 'address': '新疆沙雅县沙雅镇新垦农场8组',
- 'address_province': '新疆维吾尔自治区',
- 'address_city': '阿克苏地区',
- 'address_region': '沙雅县',
- 'address_detail': '沙雅镇新垦农场8组',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- def test_03(self):
- image_path = '../images/tmp/18_img.jpg'
- rotate = 2
- input = {'card_type': '0',
- 'orientation': rotate,
- 'name': '任雅楠',
- 'id': '152701199711230022',
- 'ethnicity': '汉',
- 'gender': '女',
- 'birthday': '1997年11月23日',
- 'address': '内蒙古鄂尔多斯市东胜区那日松北路六号街坊110号',
- 'address_province': '内蒙古自治区',
- 'address_city': '鄂尔多斯市',
- 'address_region': '东胜区',
- 'address_detail': '那日松北路六号街坊110号',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- def test_04(self):
- image_path = '../images/tmp/16_img.jpg'
- rotate = 2
- input = {'card_type': '0',
- 'orientation': rotate,
- 'name': '许倩倩',
- 'id': '142623199608163029',
- 'ethnicity': '汉',
- 'gender': '女',
- 'birthday': '1996年08月16日',
- 'address': '山西省襄汾县古城镇上北戌村建忠巷7号',
- 'address_province': '山西省',
- 'address_city': '临汾市',
- 'address_region': '襄汾县',
- 'address_detail': '古城镇上北戌村建忠巷7号',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- def test_05(self):
- image_path = '../images/tmp/20_img.jpg'
- rotate = 2
- input = {'card_type': '0',
- 'orientation': rotate,
- 'name': '郭雨晴',
- 'id': '152824199605171225',
- 'ethnicity': '汉',
- 'gender': '女',
- 'birthday': '1996年05月17日',
- 'address': '内蒙古巴彦淖尔市乌拉特前旗新安镇羊房子村康家圪旦社125号',
- 'address_province': '内蒙古自治区',
- 'address_city': '巴彦淖尔市',
- 'address_region': '乌拉特前旗',
- 'address_detail': '新安镇羊房子村康家圪旦社125号',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- def test_06(self):
- image_path = '../images/tmp/15_img.jpg'
- rotate = 3
- input = {'card_type': '0',
- 'orientation': rotate,
- 'name': '侍荣',
- 'id': '150826199905130629',
- 'ethnicity': '汉',
- 'gender': '女',
- 'birthday': '1999年05月13日',
- 'address': '内蒙古巴彦淖尔市杭锦后旗头道桥镇新丰村7组17号',
- 'address_province': '内蒙古自治区',
- 'address_city': '巴彦淖尔市',
- 'address_region': '杭锦后旗',
- 'address_detail': '头道桥镇新丰村7组17号',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- # -----
- def test_07(self):
- image_path = '../images/tmp1/07_img.jpg'
- rotate = 0
- input = {'card_type': '0',
- 'orientation': rotate,
- 'name': '韩凯峰',
- 'id': '152822199806244811',
- 'ethnicity': '汉',
- 'gender': '男',
- 'birthday': '1998年06月24日',
- 'address': '内蒙古巴彦淖尔市五原县新公中镇永生村三社064号',
- 'address_province': '内蒙古自治区',
- 'address_city': '巴彦淖尔市',
- 'address_region': '五原县',
- 'address_detail': '新公中镇永生村三社064号',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- def test_08(self):
- image_path = '../images/tmp1/06_img.jpg'
- rotate = 0
- input = {'card_type': '0',
- 'orientation': rotate,
- 'name': '李秉桦',
- 'id': '452730200006265615',
- 'ethnicity': '壮',
- 'gender': '男',
- 'birthday': '2000年06月26日',
- 'address': '南宁市江南区五一路105号6栋4单元107房',
- 'address_province': '广西壮族自治区',
- 'address_city': '南宁市',
- 'address_region': '江南区',
- 'address_detail': '五一路105号6栋4单元107房',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- def test_09(self):
- image_path = '../images/tmp1/08_img.jpg'
- rotate = 0
- input = {'card_type': '0',
- 'orientation': 0,
- 'name': '路文强',
- 'id': '610111199412202514',
- 'ethnicity': '汉',
- 'gender': '男',
- 'birthday': '1994年12月20日',
- 'address': '西安市灞桥区路家湾1组65号',
- 'address_province': '陕西省',
- 'address_city': '西安市',
- 'address_region': '灞桥区',
- 'address_detail': '路家湾1组65号',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- def test_10(self):
- image_path = '../images/tmp1/10_img.png'
- rotate = 0
- input = {'card_type': '0',
- 'orientation': 0,
- 'name': '赵子嫣',
- 'id': '341621200001024945',
- 'ethnicity': '汉',
- 'gender': '女',
- 'birthday': '2000年01月02日',
- 'address': '安徽省涡阳县马店镇吴府行政村刘王自然村246号',
- 'address_province': '安徽省',
- 'address_city': '亳州市',
- 'address_region': '涡阳县',
- 'address_detail': '马店镇吴府行政村刘王自然村246号',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- def test_11(self):
- image_path = '../images/tmp1/12_img.jpg'
- rotate = 0
- input = {'card_type': '0',
- 'orientation': rotate,
- 'name': '达日罕',
- 'id': '150422200001286055',
- 'ethnicity': '蒙古',
- 'gender': '男',
- 'birthday': '2000年01月28日',
- 'address': '内蒙古赤峰市巴林左旗查干哈达苏木红光嘎查胡北沟屯一组',
- 'address_province': '内蒙古自治区',
- 'address_city': '赤峰市',
- 'address_region': '巴林左旗',
- 'address_detail': '查干哈达苏木红光嘎查胡北沟屯一组',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- def test_12(self):
- image_path = '../images/tmp1/13_img.jpg'
- rotate = 0
- input = {'card_type': '0',
- 'orientation': 0,
- 'name': '菅恒硕',
- 'id': '372330199906226155',
- 'ethnicity': '汉',
- 'gender': '男',
- 'birthday': '1999年06月22日',
- 'address': '山东省邹平县魏桥镇菅家村14号',
- 'address_province': '山东省',
- 'address_city': '滨州市',
- 'address_region': '邹平县',
- 'address_detail': '魏桥镇营家村14号',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
- def test_13(self):
- image_path = '../images/tmp1/14_img.jpg'
- rotate = 0
- input = {'card_type': '0',
- 'orientation': rotate,
- 'name': '张劲松',
- 'id': '150125199902090217',
- 'ethnicity': '汉',
- 'gender': '男',
- 'birthday': '1999年02月09日',
- 'address': '呼和浩特市赛罕区呼伦贝尔南路雅格星城A3号楼2502号',
- 'address_province': '内蒙古自治区',
- 'address_city': '呼和浩特市',
- 'address_region': '赛罕区',
- 'address_detail': '呼伦贝尔南路雅格星城A3号楼2502号',
- 'expire_date': ''}
- self._helper(image_path, ResultItem(**input), rotate)
|