This repository has been archived by the owner on Mar 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mrz-unittests.py
80 lines (58 loc) · 2.19 KB
/
mrz-unittests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import unittest
from mrtd import MRTD
from pypassport.reader import TimeOutException
from pypassport.doc9303.mrz import MRZException
class TestPassportClass(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(TestPassportClass, self).__init__(*args, **kwargs)
self.valid_mrz = "ABCD01A236???9001011?2001012<<<<<<<<<<<<<<06"
def test_mrz_string(self):
mrz = ['ABCD01A23', '900101', '200101']
mrtd = MRTD(mrz)
self.assertEqual(mrtd.mrz_string, "ABCD01A236???9001011?2001012<<<<<<<<<<<<<<06")
def test_valid_mrz_1(self):
"""
Valid MRZ
"""
input = ['ABCD01A23', '900101', '200101']
mrtd = MRTD(input)
valid = mrtd.check_mrz()
self.assertTrue(valid)
def test_valid_mrz_2(self):
"""
Invalid MRZ, document number too long
"""
input = ['ABCD01A23<', '900101', '200101']
mrtd = MRTD(input)
with self.assertRaises(MRZException) as context:
mrtd.check_mrz()
self.assertTrue("The mrz length is invalid" in context.exception)
def test_valid_mrz_3(self):
"""
Invalid MRZ, date of birth too long
"""
input = ['ABCD01A23', '900101<', '200101']
mrtd = MRTD(input)
with self.assertRaises(MRZException) as context:
mrtd.check_mrz()
self.assertTrue("The mrz length is invalid" in context.exception)
def test_valid_mrz_4(self):
"""
Invalid MRZ, experation date too long
"""
input = ['ABCD01A23', '900101', '200101<']
mrtd = MRTD(input)
with self.assertRaises(MRZException) as context:
mrtd.check_mrz()
self.assertTrue("The mrz length is invalid" in context.exception)
def test_valid_mrz_5(self):
"""
Invalid MRZ, every element too short
"""
input = ['ABCD01A2', '90010', '20010']
mrtd = MRTD(input)
with self.assertRaises(MRZException) as context:
mrtd.check_mrz()
self.assertTrue("The mrz length is invalid" in context.exception)
if __name__ == '__main__':
unittest.main()