all_test.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import base64
  2. import unittest
  3. from pathlib import Path
  4. import requests
  5. from testing.utils import send_request
  6. class TestBankCardConvex(unittest.TestCase):
  7. def _helper(self, image_path, sta, orient, card_no):
  8. root = Path(__file__).parent
  9. image_path = str(root / image_path)
  10. r = send_request(image_path)
  11. self.assertEqual(sta, r['status'], f'{image_path} status case error')
  12. self.assertEqual(orient, r['result']['orientation'], f'{image_path} orientation case error')
  13. self.assertEqual(card_no, r['result']['number']['text'], f'{image_path} number case error')
  14. def test_back_mess(self):
  15. image_path = '../images/all/convex/back_mess.jpg'
  16. self._helper(image_path, '000', 0, '6222521510000593')
  17. def test_convex_0(self):
  18. image_path = '../images/all/convex/convex_0.jpg'
  19. self._helper(image_path, '000', 0, '6258091767775765')
  20. def test_convex_90(self):
  21. image_path = '../images/all/convex/convex_0.jpg'
  22. self._helper(image_path, '000', 1, '6217991910056756013')
  23. def test_convex_180(self):
  24. image_path = '../images/all/convex/convex_180.jpg'
  25. self._helper(image_path, '000', 2, '6214835715794218')
  26. def test_convex_270(self):
  27. image_path = '../images/all/convex/convex_270.jpg'
  28. self._helper(image_path, '000', 3, '6222081211001840619')
  29. def test_mohu1(self):
  30. image_path = '../images/all/convex/mohu1.jpg'
  31. self._helper(image_path, '000', 0, '6212261602020022770')
  32. def test_mohu2(self):
  33. image_path = '../images/all/convex/mohu2.jpg'
  34. self._helper(image_path, '000', 1, '6215581504002751986')
  35. def test_small(self):
  36. image_path = '../images/all/convex/small.jpg'
  37. self._helper(image_path, '000', 0, '6217981910002853676')
  38. def test_tilt1(self):
  39. image_path = '../images/all/convex/tilt1.jpg'
  40. self._helper(image_path, '000', 3, '6215590613003222324')
  41. def test_tilt2(self):
  42. image_path = '../images/all/convex/tilt2.jpg'
  43. self._helper(image_path, '000', 0, '623061571509189093')
  44. class TestBankCardPrint(unittest.TestCase):
  45. def _helper(self, image_path, sta, orient, card_no):
  46. root = Path(__file__).parent
  47. image_path = str(root / image_path)
  48. r = send_request(image_path)
  49. self.assertEqual(sta, r['status'], f'{image_path} status case error')
  50. self.assertEqual(orient, r['result']['orientation'], f'{image_path} orientation case error')
  51. self.assertEqual(card_no, r['result']['number']['text'], f'{image_path} number case error')
  52. def test_front_0(self):
  53. image_path = '../images/all/print/front_0.jpg'
  54. self._helper(image_path, '000', 0, '6216638405000213022')
  55. def test_front_90(self):
  56. image_path = '../images/all/print/front_90.jpg'
  57. self._helper(image_path, '000', 1, '6216618401001365345')
  58. def test_front_180(self):
  59. image_path = '../images/all/print/front_180.png'
  60. self._helper(image_path, '000', 2, '6230522590019175070')
  61. def test_front_270(self):
  62. image_path = '../images/all/print/front_270.png'
  63. self._helper(image_path, '000', 3, '6228480329658828572')
  64. def test_long(self):
  65. image_path = '../images/all/print/long.jpg'
  66. self._helper(image_path, '000', 0, '6217991910038919747')
  67. def test_mohu1(self):
  68. image_path = '../images/all/print/mohu1.jpg'
  69. self._helper(image_path, '000', 1, '6217000416004100998')
  70. def test_mohu2(self):
  71. image_path = '../images/all/print/mohu2.jpg'
  72. self._helper(image_path, '000', 0, '6217000870003035904')
  73. def test_small1(self):
  74. image_path = '../images/all/print/small1.jpg'
  75. self._helper(image_path, '000', 0, '6222020602005624997')
  76. def test_small2(self):
  77. image_path = '../images/all/print/small2.png'
  78. self._helper(image_path, '000', 0, '6222020602015798211')
  79. def test_special(self):
  80. image_path = '../images/all/print/special.jpg'
  81. self._helper(image_path, '000', 0, '6259760610567202')
  82. def test_small2(self):
  83. image_path = '../images/all/print/small2.png'
  84. self._helper(image_path, '000', 0, '6222020602015798211')
  85. if __name__ == '__main__':
  86. unittest.main()