def test_name_format_4(self):
        input = "SMITH<JONES<<SUSIE<MARGARET<<<<<<<<<<<<"
        expected_output = ["Smith Jones", "Susie Margaret"]

        mrtd = MRTD(self.valid_mrz)
        output = mrtd.format_name(input)

        self.assertEqual(output, expected_output)
    def test_name_format_1(self):
        input = "JANSEN<<JAN<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
        expected_output = ["Jansen", "Jan"]

        mrtd = MRTD(self.valid_mrz)
        output = mrtd.format_name(input)

        self.assertEqual(output, expected_output)
    def test_date_format_2(self):
        input = "021228"
        expected_output = "2002-12-28"

        mrtd = MRTD(self.valid_mrz)
        output = mrtd.format_date(input)

        self.assertEqual(output, expected_output)
    def test_date_format_1(self):
        input = "900201"
        expected_output = "1990-02-01"

        mrtd = MRTD(self.valid_mrz)
        output = mrtd.format_date(input)

        self.assertEqual(output, expected_output)
    def test_name_format_3(self):
        input = "VAN<DER<MEULEN<<MARTIN<<<<<<<<<<<<<<<<<"
        expected_output = ["Van Der Meulen", "Martin"]

        mrtd = MRTD(self.valid_mrz)
        output = mrtd.format_name(input)

        self.assertEqual(output, expected_output)
    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_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)
    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_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_date_format_4(self):
        """
        Testing edge case
        """
        input = "090101"
        expected_output = "1909-01-01"

        mrtd = MRTD(self.valid_mrz)
        output = mrtd.format_date(input)

        self.assertEqual(output, expected_output)
    def test_date_format_3(self):
        input = "080101"
        """
        Testing edge case
        """
        expected_output = "2008-01-01"

        mrtd = MRTD(self.valid_mrz)
        output = mrtd.format_date(input)

        self.assertEqual(output, expected_output)
    def wait_for_card(self, data={}):
        # wait for nfc reader to detect a card

        mrtd = None

        if mrtd is None:
            mrtd = MRTD()

        if mrtd.wait_for_card():
            print("Card detected!")
            return {"card": True}
Exemple #13
0
    def _setup_mrtd(self, mrz):
        """
        3) Setup MRTD and get data
        """
        id_card = MRTD(mrz, True)

        self.personal_data = id_card.personal_data()

        if self.personal_data == None:
            sys.exit(1)

        self.image_base64 = id_card.photo_data()

        if self.image_base64 == None:
            sys.exit(1)
    def read_card(self, data={}):
        mrz = self.mrz
        if mrz is None:
            logging.info("MRTD: Trying to read MRZ...")
            mrz = self.get_mrz()

            if mrz:
                logging.info("MRTD: MRZ received [{}]".format(mrz))
                self.ocr.end_capture()
                self.mrtd = MRTD(mrz)
                self.mrz = mrz

        else:
            logging.info("MRTD: Waiting for card...")
            if self.get_mrtd():
                return {"mrtd": True}
    def test_date_format_5(self):
        """
        Testing edge cases
        """
        input_a = "060101"
        expected_output_a = "2006-01-01"

        input_b = "070101"
        expected_output_b = "1907-01-01"

        adjustment_years = 12

        mrtd = MRTD(self.valid_mrz)
        output_a = mrtd.format_date(input_a, adjustment_years)
        output_b = mrtd.format_date(input_b, adjustment_years)

        self.assertEqual(output_a, expected_output_a)
        self.assertEqual(output_b, expected_output_b)
Exemple #16
0
    def get_data(self):

        if self.default_data:
            with open('config.json') as input:
                json_input = json.load(input)
                docNumber = json_input['docNumber']
                self.docNrEntry.insert(0, docNumber)
                dateOfBirth = json_input['dob']
                self.dobEntry.insert(0, dateOfBirth)
                expiryDate = json_input['expDate']
                self.expDateEntry.insert(0, expiryDate)

        docNumber = self.docNrEntry.get()
        dateOfBirth = self.dobEntry.get()
        expiryDate = self.expDateEntry.get()

        mrz = [docNumber, dateOfBirth, expiryDate]

        id = MRTD(mrz, False)

        personal_data = id.personal_data()

        image_base64 = id.photo_data('png')
        self.set_output(personal_data, image_base64)
    def setup_mrtd(self):
        """
        3) Setup MRTD and get data
        """
        output_file = False
        id_card = MRTD(self.mrz, output_file)

        personal_data = id_card.personal_data()

        if personal_data == None:
            logging.error("DG1 could not be read")
            return False

        image_base64 = id_card.photo_data()

        if image_base64 == None:
            logging.error("DG2 could not be read")
            return False

        self.mrtd_data = [{
            'personal_data': personal_data
        }, {
            'image_base64': image_base64
        }]
    def test_mrz_string(self):
        mrz = ['ABCD01A23', '900101', '200101']
        mrtd = MRTD(mrz)

        self.assertEqual(mrtd.mrz_string,
                         "ABCD01A236???9001011?2001012<<<<<<<<<<<<<<06")
from mrtd import MRTD
import config

passport = MRTD(config.MRZ_CONFIG['mrz2'])
print(passport.do_bac())