import base64 import unittest from pathlib import Path import requests from testing.utils import send_request class TestBankCardConvex(unittest.TestCase): def _helper(self, image_path, sta, orient, card_no): root = Path(__file__).parent image_path = str(root / image_path) r = send_request(image_path) 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(card_no, r['result']['number']['text'], f'{image_path} number case error') def test_back_mess(self): image_path = '../images/all/convex/back_mess.jpg' self._helper(image_path, '000', 0, '6222521510000593') def test_convex_0(self): image_path = '../images/all/convex/convex_0.jpg' self._helper(image_path, '000', 0, '6258091767775765') def test_convex_90(self): image_path = '../images/all/convex/convex_0.jpg' self._helper(image_path, '000', 1, '6217991910056756013') def test_convex_180(self): image_path = '../images/all/convex/convex_180.jpg' self._helper(image_path, '000', 2, '6214835715794218') def test_convex_270(self): image_path = '../images/all/convex/convex_270.jpg' self._helper(image_path, '000', 3, '6222081211001840619') def test_mohu1(self): image_path = '../images/all/convex/mohu1.jpg' self._helper(image_path, '000', 0, '6212261602020022770') def test_mohu2(self): image_path = '../images/all/convex/mohu2.jpg' self._helper(image_path, '000', 1, '6215581504002751986') def test_small(self): image_path = '../images/all/convex/small.jpg' self._helper(image_path, '000', 0, '6217981910002853676') def test_tilt1(self): image_path = '../images/all/convex/tilt1.jpg' self._helper(image_path, '000', 3, '6215590613003222324') def test_tilt2(self): image_path = '../images/all/convex/tilt2.jpg' self._helper(image_path, '000', 0, '623061571509189093') class TestBankCardPrint(unittest.TestCase): def _helper(self, image_path, sta, orient, card_no): root = Path(__file__).parent image_path = str(root / image_path) r = send_request(image_path) 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(card_no, r['result']['number']['text'], f'{image_path} number case error') def test_front_0(self): image_path = '../images/all/print/front_0.jpg' self._helper(image_path, '000', 0, '6216638405000213022') def test_front_90(self): image_path = '../images/all/print/front_90.jpg' self._helper(image_path, '000', 1, '6216618401001365345') def test_front_180(self): image_path = '../images/all/print/front_180.png' self._helper(image_path, '000', 2, '6230522590019175070') def test_front_270(self): image_path = '../images/all/print/front_270.png' self._helper(image_path, '000', 3, '6228480329658828572') def test_long(self): image_path = '../images/all/print/long.jpg' self._helper(image_path, '000', 0, '6217991910038919747') def test_mohu1(self): image_path = '../images/all/print/mohu1.jpg' self._helper(image_path, '000', 1, '6217000416004100998') def test_mohu2(self): image_path = '../images/all/print/mohu2.jpg' self._helper(image_path, '000', 0, '6217000870003035904') def test_small1(self): image_path = '../images/all/print/small1.jpg' self._helper(image_path, '000', 0, '6222020602005624997') def test_small2(self): image_path = '../images/all/print/small2.png' self._helper(image_path, '000', 0, '6222020602015798211') def test_special(self): image_path = '../images/all/print/special.jpg' self._helper(image_path, '000', 0, '6259760610567202') def test_small2(self): image_path = '../images/all/print/small2.png' self._helper(image_path, '000', 0, '6222020602015798211') if __name__ == '__main__': unittest.main()