import unittest from dataclasses import dataclass from pathlib import Path import pytest from testing.utils import * @dataclass class ResultItem: status: str orientation: int name: str id: str ethnicity: str gender: str birthday: str address: str class TestIdCard0(unittest.TestCase): def _helper(self, image_path, item: ResultItem): root = Path(__file__).parent image_path = str(root / image_path) r = send_request(image_path, '0') self.assertEqual(item, ResultItem(status=r['status'], orientation=r['result']['orientation'], name=r['result']['name']['text'], id=r['result']['id']['text'], ethnicity=r['result']['ethnicity']['text'], gender=r['result']['gender']['text'], birthday=r['result']['birthday']['text'], address=r['result']['address']['text'] )) def test_01_0(self): image_path = '../images/all/0/01_0.jpg' self._helper(image_path, ResultItem(status='000', orientation=0, name='左翔宇', id='220204199910123017', ethnicity='蒙古', gender='男', birthday='1999年10月12日', address='吉林省吉林市船营区鑫安小区2-6-60号')) def test_02_90(self): image_path = '../images/all/0/02_90.jpg' self._helper(image_path, ResultItem(status='000', orientation=1, name='张开天', id='622301199710247376', ethnicity='汉', gender='男', birthday='1997年10月24日', address='甘肃省武威市凉州区九墩乡平乐村四组23号')) def test_03_0(self): image_path = '../images/all/0/03_0(minor).jpg' self._helper(image_path, ResultItem(status='000', orientation=0, name='张荣军', id='654122199712254017', ethnicity='锡伯', gender='男', birthday='1997年12月25日', address='新疆察布查尔锡伯自治县堆齐牛录乡杜林拜北街西二巷29号')) def test_04_180(self): image_path = '../images/all/0/04_180.jpg' self._helper(image_path, ResultItem(status='000', orientation=2, name='方势文', id='360428199610220096', ethnicity='汉', gender='男', birthday='1996年10月22日', address='江西省九江市都昌县都昌镇沿湖路238号')) def test_05_270(self): image_path = '../images/all/0/05_270.jpg' self._helper(image_path, ResultItem(status='000', orientation=3, name='孔一凡', id='310102198710034449', ethnicity='汉', gender='女', birthday='1987年10月03日', address='上海市黄浦区静修路79弄5号')) def test_addreess(self): image_path = '../images/all/0/address.png' self._helper(image_path, ResultItem(status='000', orientation=0, name='王磊', id='150203199308092110', ethnicity='汉', gender='男', birthday='1993年08月09日', address='内蒙古包头市昆都仑区昆河镇刘二圪梁村393号')) def test_long_name(self): image_path = '../images/all/0/long_name.png' self._helper(image_path, ResultItem(status='000', orientation=0, name='叶干别尔地·坎吉巴依', id='653024199812031239', ethnicity='柯尔克孜', gender='男', birthday='1998年12月03日', address='南京市栖霞区文苑路1号')) def test_mohu(self): image_path = '../images/all/0/mohu.jpg' self._helper(image_path, ResultItem(status='000', orientation=0, name='田浩', id='640221199702060618', ethnicity='汉', gender='男', birthday='1997年02月06日', address='宁夏平罗县黄渠桥镇侯家梁村二队29')) def test_mohu_90(self): image_path = '../images/all/0/mohu_90.jpg' self._helper(image_path, ResultItem(status='000', orientation=1, name='王睿', id='421202199506051096', ethnicity='汉', gender='男', birthday='1995年06月05日', address='湖北省咸宁市咸安区温泉淦河大道12号')) def test_small(self): image_path = '../images/all/0/small.jpg' self._helper(image_path, ResultItem(status='000', orientation=0, name='董建', id='654121199802042775', ethnicity='回', gender='男', birthday='1998年02月04日', address='新疆伊宁县愉群翁乡伊克翁村216号')) def test_special1(self): image_path = '../images/all/0/special1.jpg' self._helper(image_path, ResultItem(status='000', orientation=0, name='宋宝磊', id='150430199905051616', ethnicity='汉', gender='男', birthday='1999年05月05日', address='内蒙古赤峰市敖汉旗四家子镇林家地村唐坊沟七组')) def test_special2(self): image_path = '../images/all/0/special2.jpg' self._helper(image_path, ResultItem(status='000', orientation=0, name='彭贤端', id='450922199412083669', ethnicity='汉', gender='女', birthday='1994年12月08日', address='广西陆川县清湖镇塘寨村新屋队62号')) @pytest.mark.parametrize( "image_path, status, orientation, expire_date", [ (Path('../images/all/1/01_0.jpg'), '000', 0, '20220511-20420511'), (Path('../images/all/1/02_270.jpg'), '000', 3, '20180531-20280531'), (Path('../images/all/1/03_180.jpg'), '000', 2, '20170109-20270109'), (Path('../images/all/1/04_90.jpg'), '000', 1, '20190715-20390715'), (Path('../images/all/1/05-270.jpg'), '000', 3, '20140320-20240320'), (Path('../images/all/1/small.png'), '000', 0, '20190620-20290620'), (Path('../images/all/1/special.jpg'), '000', 0, '20190813-20290813'), ] ) def test_back_side(image_path, status, orientation, expire_date): root = Path(__file__).parent image_path = str(root / image_path) r = send_request(image_path, '1') if r['status'] == '000': assert (r['result']['expire_date']['text'], r['result']['orientation']) == (expire_date, orientation) else: assert r['status'] == status if __name__ == '__main__': unittest.main()