12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import base64
- import unittest
- from pathlib import Path
- import requests
- url = 'http://192.168.199.208:18081'
- def send_request(image_path, image_type):
- with open(image_path, 'rb') as f:
- img_str: str = base64.encodebytes(f.read()).decode('utf-8')
- r = requests.post(f'{url}/ocr_system/idcard', json={'image': img_str, 'image_type': image_type})
- print(r.json())
- return r.json()
- class TestIdCardAddress(unittest.TestCase):
- def _helper(self, image_path, sta, orient, name, id, ethnicity, gender, birthday, address):
- root = Path(__file__).parent
- image_path = str(root / image_path)
- r = send_request(image_path, '0')
- self.assertEqual(sta, r['status'], f'{image_path} status case error')
- self.assertEqual(orient, r['result']['orientation'], f'{image_path} orientation case error')
- self.assertEqual(name, r['result']['name']['text'], f'{image_path} name case error')
- self.assertEqual(id, r['result']['id']['text'], f'{image_path} id case error')
- self.assertEqual(ethnicity, r['result']['ethnicity']['text'], f'{image_path} ethnicity case error')
- self.assertEqual(gender, r['result']['gender']['text'], f'{image_path} gender case error')
- self.assertEqual(birthday, r['result']['birthday']['text'], f'{image_path} birthday case error')
- self.assertEqual(address, r['result']['address']['text'], f'{image_path} address case error')
- def test_01(self):
- image_path = '../images/ture/01.jpg'
- self._helper(image_path, '000', 0, '宋宝磊', '150430199905051616', '汉', '男', '1999年05月05日',
- '内蒙古赤峰市敖汉旗四家子镇林家地村唐坊沟七组')
- def test_02(self):
- image_path = '../images/ture/02.jpg'
- self._helper(image_path, '000', 2, '方势文', '360428199610220096', '汉', '男', '1996年10月22日', '江西省九江市都昌县都昌镇沿湖路238号')
- def test_03(self):
- image_path = '../images/ture/03.jpg'
- self._helper(image_path, '000', 0, '彭贤端', '450922199412083669', '汉', '女', '1994年12月08日', '广西陆川县清湖镇塘寨村新屋队62号')
- def test_04(self):
- image_path = '../images/ture/04.png'
- self._helper(image_path, '000', 0, '王晓凤', '150921199910021527', '汉', '女', '1999年10月02日',
- '呼和浩特市新城区赛马场北路城市维也纳13号楼2单元1303号')
- def test_05(self):
- image_path = '../images/ture/05.jpg'
- self._helper(image_path, '000', 0, '任学东', '152630198501117517', '汉', '男', '1985年01月11日',
- '内蒙古乌兰察布市察哈尔右翼前旗巴音塔拉镇谢家村22户')
- def test_06(self):
- image_path = '../images/ture/06.jpg'
- self._helper(image_path, '000', 0, '田浩', '640221199702060618', '汉', '男', '1997年02月06日', '宁夏平罗县黄渠桥镇侯家梁村二队29')
- def test_07_0(self):
- image_path = '../images/ture/07_0.jpg'
- self._helper(image_path, '000', 0, '左翔宇', '220204199910123017', '蒙古', '男', '1999年10月12日',
- '吉林省吉林市船营区鑫安小区2-6-60号')
- def test_07_90(self):
- image_path = '../images/ture/07_90.jpg'
- self._helper(image_path, '000', 1, '左翔宇', '220204199910123017', '蒙古', '男', '1999年10月12日',
- '吉林省吉林市船营区鑫安小区2-6-60号')
- def test_07_180(self):
- image_path = '../images/ture/07_180.jpg'
- self._helper(image_path, '000', 2, '左翔宇', '220204199910123017', '蒙古', '男', '1999年10月12日',
- '吉林省吉林市船营区鑫安小区2-6-60号')
- def test_08_0(self):
- image_path = '../images/ture/08_0.jpg'
- self._helper(image_path, '000', 0, '张开天', '622301199710247376', '汉', '男', '1997年10月24日', '甘肃省武威市凉州区九墩乡平乐村四组23号')
- def test_08_180(self):
- image_path = '../images/ture/08_180.jpg'
- self._helper(image_path, '000', 2, '张开天', '622301199710247376', '汉', '男', '1997年10月24日', '甘肃省武威市凉州区九墩乡平乐村四组23号')
- def test_09(self):
- image_path = '../images/ture/09.jpeg'
- self._helper(image_path, '000', 0, '韩毅', '211102199912162010', '汉', '男', '1999年12月16日',
- '辽宁省盘锦市双台子区胜利街道团结社区15区40号')
- def test_10(self):
- image_path = '../images/ture/10.jpg'
- self._helper(image_path, '000', 0, '曾令权', '432524199306221414', '汉', '男', '1993年06月22日', '湖南省新化县维山乡官庄村陈家冲组21号')
- if __name__ == '__main__':
- unittest.main()
|