import unittest
from dataclasses import dataclass
from pathlib import Path

from testing.utils import *


@dataclass
class ResultItem:
    status: str
    orientation: int
    name: str
    id: str
    ethnicity: str
    gender: str
    birthday: str
    address: str


class TestIdCardAddress(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.status, r['status'], f'{image_path} status case error')
        self.assertEqual(item.orientation, r['result']['orientation'], f'{image_path} orientation case error')
        self.assertEqual(item.name, r['result']['name']['text'], f'{image_path} name case error')
        self.assertEqual(item.id, r['result']['id']['text'], f'{image_path} id case error')
        self.assertEqual(item.ethnicity, r['result']['ethnicity']['text'], f'{image_path} ethnicity case error')
        self.assertEqual(item.gender, r['result']['gender']['text'], f'{image_path} gender case error')
        self.assertEqual(item.birthday, r['result']['birthday']['text'], f'{image_path} birthday case error')
        self.assertEqual(item.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, ResultItem(status='000',
                                            orientation=0,
                                            name='宋宝磊',
                                            id='150430199905051616',
                                            ethnicity='汉',
                                            gender='男',
                                            birthday='1999年05月05日',
                                            address='内蒙古赤峰市敖汉旗四家子镇林家地村唐坊沟七组'))

    def test_02(self):
        image_path = '../images/ture/02.jpg'
        self._helper(image_path, ResultItem(status='000',
                                            orientation=2,
                                            name='方势文',
                                            id='360428199610220096',
                                            ethnicity='汉',
                                            gender='男',
                                            birthday='1996年10月22日',
                                            address='江西省九江市都昌县都昌镇沿湖路238号'))

    def test_03(self):
        image_path = '../images/ture/03.jpg'
        self._helper(image_path, ResultItem(status='000',
                                            orientation=0,
                                            name='彭贤端',
                                            id='450922199412083669',
                                            ethnicity='汉',
                                            gender='女',
                                            birthday='1994年12月08日',
                                            address='广西陆川县清湖镇塘寨村新屋队62号'))

    def test_04(self):
        image_path = '../images/ture/04.png'
        self._helper(image_path, ResultItem(status='000',
                                            orientation=0,
                                            name='王晓凤',
                                            id='150921199910021527',
                                            ethnicity='汉',
                                            gender='女',
                                            birthday='1999年10月02日',
                                            address='呼和浩特市新城区赛马场北路城市维也纳13号楼2单元1303号'))

    def test_05(self):
        image_path = '../images/ture/05.jpg'
        self._helper(image_path, ResultItem(status='000',
                                            orientation=0,
                                            name='任学东',
                                            id='152630198501117517',
                                            ethnicity='汉',
                                            gender='男',
                                            birthday='1985年01月11日',
                                            address='内蒙古乌兰察布市察哈尔右翼前旗巴音塔拉镇谢家村22户'))

    def test_06(self):
        image_path = '../images/ture/06.jpg'
        self._helper(image_path, ResultItem(status='000',
                                            orientation=0,
                                            name='田浩',
                                            id='640221199702060618',
                                            ethnicity='汉',
                                            gender='男',
                                            birthday='1997年02月06日',
                                            address='宁夏平罗县黄渠桥镇侯家梁村二队29'))

    def test_07_0(self):
        image_path = '../images/ture/07_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_07_90(self):
        image_path = '../images/ture/07_90.jpg'
        self._helper(image_path, ResultItem(status='000',
                                            orientation=1,
                                            name='左翔宇',
                                            id='220204199910123017',
                                            ethnicity='蒙古',
                                            gender='男',
                                            birthday='1999年10月12日',
                                            address='吉林省吉林市船营区鑫安小区2-6-60号'))

    def test_07_180(self):
        image_path = '../images/ture/07_180.jpg'
        self._helper(image_path, ResultItem(status='000',
                                            orientation=2,
                                            name='左翔宇',
                                            id='220204199910123017',
                                            ethnicity='蒙古',
                                            gender='男',
                                            birthday='1999年10月12日',
                                            address='吉林省吉林市船营区鑫安小区2-6-60号'))

    def test_08_0(self):
        image_path = '../images/ture/08_0.jpg'
        self._helper(image_path, ResultItem(status='000',
                                            orientation=0,
                                            name='张开天',
                                            id='622301199710247376',
                                            ethnicity='汉',
                                            gender='男',
                                            birthday='1997年10月24日',
                                            address='甘肃省武威市凉州区九墩乡平乐村四组23号'))

    def test_08_180(self):
        image_path = '../images/ture/08_180.jpg'
        self._helper(image_path, ResultItem(status='000',
                                            orientation=2,
                                            name='张开天',
                                            id='622301199710247376',
                                            ethnicity='汉',
                                            gender='男',
                                            birthday='1997年10月24日',
                                            address='甘肃省武威市凉州区九墩乡平乐村四组23号'))

    def test_09(self):
        image_path = '../images/ture/09.jpeg'
        self._helper(image_path, ResultItem(status='000',
                                            orientation=0,
                                            name='韩毅',
                                            id='211102199912162010',
                                            ethnicity='汉',
                                            gender='男',
                                            birthday='1999年12月16日',
                                            address=
                                            '辽宁省盘锦市双台子区胜利街道团结社区15区40号'))

    def test_10(self):
        image_path = '../images/ture/10.jpg'
        self._helper(image_path, ResultItem(status='000',
                                            orientation=0,
                                            name='曾令权',
                                            id='432524199306221414',
                                            ethnicity='汉',
                                            gender='男',
                                            birthday='1993年06月22日',
                                            address='湖南省新化县维山乡官庄村陈家冲组21号'))


if __name__ == '__main__':
    unittest.main()
