def test_analysis_old_dni_valid_id_surnames(self): parser = DNIScumParser(DNI_OLD_COMPLETE_SURNAMES) reference_date = datetime(year=2017, month=11, day=1).date() self.assertAnalysis([parser.VALID], parser.analysis(person={'name': 'Jose alberto', 'surnames': 'Cort\xe9s sanz', 'id': None}, reference_date=reference_date))
def test_analysis_dni_expired(self): parser = DNIScumParser(DNI_OLD) reference_date = datetime(year=2030, month=11, day=1).date() self.assertAnalysis([parser.EXPIRED, parser.FRONT, parser.BACK], parser.analysis(person={'name': 'maria del sagrario', 'surnames': 'sanchez de la blanca puente', 'id': '56933095f'}, reference_date=reference_date))
def test_analysis_old_dni_valid(self): parser = DNIScumParser(DNI_OLD) reference_date = datetime(year=2017, month=11, day=1).date() self.assertAnalysis([parser.VALID], parser.analysis(person={'name': 'maria del sagrario', 'surnames': 'sanchez de la blanca puente', 'id': '56933095f'}, reference_date=reference_date))
def test_analysis_old_dni_valid_id_none(self): parser = DNIScumParser(DNI_OLD_ALL) reference_date = datetime(year=2017, month=11, day=1).date() self.assertAnalysis([parser.VALID], parser.analysis(person={'name': 'Clara', 'surnames': 'Abad', 'id': None}, reference_date=reference_date))
def test_dni_old_first_back_in_same_level(self): keywords = dict(self.keywords) keywords = {key:False for key, value in self.keywords.items()} keywords["idesp"] = True keywords['dni num'] = True keywords['domicilio / domicili'] = True keywords['lugar de nacimiento/ lloc de naixement'] = True keywords['equipo / equip'] = True parser = DNIScumParser(DNI_OLD_FIRST_BACK) result = parser.parse() ocrs = {'date_expires': u'210610', 'surnames': u'martinez gago', 'date_birth': u'690619', 'names': u'pepa esther', 'nat': u'esp', 'country': u'esp', 'dni': u'53686041w', 'sex': u'f'} self.assertResult(result, [date(year=1969, month=6, day=19), date(year=2021, month=6, day=10)], keywords, ocrs)
def test_dni_old(self): keywords = dict(self.keywords) keywords['dni'] = False keywords['nombre'] = False keywords['apellidos'] = False keywords['num soport validez'] = False ocrs = {'date_expires': '210919', 'date_birth': '781009', 'nat': 'esp', 'country': 'esp', 'dni': '56933095f', 'sex': 'f', 'surnames': 'sanchoz de la blancakpuente', 'names': 'm'} parser = DNIScumParser(DNI_OLD) result = parser.parse() self.assertResult(result, [date(year=2021, month=9, day=19)], keywords, ocrs)
def test_dni_old_no_back(self): keywords = dict(self.keywords) keywords['equipo'] = False keywords['lugar de nacimiento'] = False keywords['lugar de domicilio'] = False keywords['dni'] = False keywords['provincia/pais'] = False keywords['nombre'] = False keywords['apellidos'] = False keywords['hijo/a de'] = False keywords['num soport validez'] = False keywords['domicilio'] = False ocrs = {} parser = DNIScumParser(DNI_OLD_NO_BACK) result = parser.parse() self.assertResult(result, [date(year=2021, month=9, day=19)], keywords, ocrs)
def test_dni_new_no_back_no_correct_dates(self): keywords = dict(self.keywords) keywords['domicilio'] = False keywords['primer apellido'] = False keywords['segundo apellido'] = False keywords['dni num'] = False keywords['valido hasta'] = False keywords['lugar de domicilio'] = False keywords['hijo/a de'] = False keywords['equipo'] = False keywords['lugar de nacimiento'] = False keywords['lugar de domicilio'] = False keywords['dni'] = False keywords['provincia/pais'] = False ocrs = {} parser = DNIScumParser(DNI_NEW_NO_BACK_ERROR_DATES) result = parser.parse() self.assertResult(result, [], keywords, ocrs)
def test_dni_new_no_back(self): keywords = dict(self.keywords) keywords['domicilio'] = False keywords['primer apellido'] = False keywords['segundo apellido'] = False keywords['dni num'] = False keywords['valido hasta'] = False keywords['lugar de domicilio'] = False keywords['hijo/a de'] = False keywords['equipo'] = False keywords['lugar de nacimiento'] = False keywords['lugar de domicilio'] = False keywords['dni'] = False keywords['provincia/pais'] = False ocrs = {} parser = DNIScumParser(DNI_NEW_NO_BACK) result = parser.parse() self.assertResult(result, [date(year=1983, month=11, day=17), date(year=2026, month=4, day=12)], keywords, ocrs)
def test_dni_new(self): keywords = dict(self.keywords) keywords['domicilio'] = False keywords['primer apellido'] = False keywords['segundo apellido'] = False keywords['dni num'] = False keywords['valido hasta'] = False keywords['lugar de domicilio'] = False keywords['hijo/a de'] = False keywords['equipo'] = False keywords['lugar de nacimiento'] = False keywords['lugar de domicilio'] = False keywords['dni'] = False keywords['provincia/pais'] = False ocrs = {'date_expires': u'260412', 'surnames': u'alvarez dorado', 'date_birth': u'831117', 'names': u'ramon', 'nat': u'esp', 'country': u'esp', 'dni': u'04900073d', 'sex': u'm'} parser = DNIScumParser(DNI_NEW) result = parser.parse() self.assertResult(result, [date(year=1983, month=11, day=17), date(year=2026, month=4, day=12)], keywords, ocrs)
def test_dni_old_cat(self): keywords = self.keywords.copy() keywords['segundo apellido'] = False keywords['equipo'] = False keywords['lugar de domicilio'] = False keywords['dni'] = False keywords['provincia/pais'] = False keywords["apellidos"] = False keywords["num soport validez"] = False keywords["fecha de nacimiento"] = False keywords["sexo nacionalidad"] = False keywords["valido hasta"] = False keywords["domicilio"] = False keywords["idesp"] = False keywords["hijo/a de"] = False keywords["lugar de nacimiento"] = False keywords['nombre'] = False keywords['primer apellido'] = False ocrs = {'date_expires': u'240123', 'date_birth': u'730116', 'nat': u'esp', 'country': u'esp', 'dni': u'52522003r', 'sex': u'm'} parser = DNIScumParser(DNI_OLD_CAT) result = parser.parse() self.assertResult(result, [date(year=2025, month=1, day=23)], keywords, ocrs)
def test_dni_old_no_back_cat(self): keywords = self.keywords.copy() keywords['segundo apellido'] = False keywords['equipo'] = False keywords['lugar de domicilio'] = False keywords['dni'] = False keywords['provincia/pais'] = False keywords["apellidos"] = False keywords["num soport validez"] = False keywords["fecha de nacimiento"] = False keywords["sexo nacionalidad"] = False keywords["valido hasta"] = False keywords["domicilio"] = False keywords["idesp"] = False keywords["hijo/a de"] = False keywords["lugar de nacimiento"] = False keywords['nombre'] = False keywords['primer apellido'] = False ocrs = {} parser = DNIScumParser(DNI_OLD_NO_BACK_CAT) result = parser.parse() self.assertResult(result, [date(year=2025, month=1, day=23)], keywords, ocrs)
def test_analysis_not_valid(self): parser = DNIScumParser(DNI_NOT_VALID) self.assertAnalysis([parser.NOT_VALID], parser.analysis())
def test_is_expired_with_no_back(self): parser = DNIScumParser(DNI_NEW_NO_BACK) reference_date = datetime(year=2030, month=12, day=1).date() self.assertTrue(parser.is_expired(reference_date))
def test_is_front(self): parser = DNIScumParser(DNI_NEW_NO_BACK) self.assertTrue(parser.is_front())
def test_not_is_front(self): parser = DNIScumParser(DNI_ONLY_BACK) self.assertFalse(parser.is_front())
def test_is_back(self): parser = DNIScumParser(DNI_NEW) self.assertTrue(parser.is_back())
def test_check_id_complete_dni(self): parser = DNIScumParser(DNI_OLD) self.assertTrue(parser.check_id('56933095f'))
def test_not_is_expired_with_back_mr(self): parser = DNIScumParser(DNI_NEW) reference_date = datetime(year=2017, month=12, day=1).date() self.assertFalse(parser.is_expired(reference_date))
def test_check_person_not_found(self): parser = DNIScumParser(DNI_NEW) self.assertFalse(parser.check_person({'name': 'jose', 'surnames': 'martinez dorado'}))
def test_check_person_found(self): parser = DNIScumParser(DNI_NEW) self.assertTrue(parser.check_person({'name': 'ramon', 'surnames': 'alvarez dorado'}))
def test_check_id_only_back_not_found(self): parser = DNIScumParser(DNI_OLD_ONLY_BACK) self.assertFalse(parser.check_id('89933095f'))
def test_check_id_only_back(self): parser = DNIScumParser(DNI_OLD_ONLY_BACK) self.assertTrue(parser.check_id('56933095f'))
def test_check_id_only_front(self): parser = DNIScumParser(DNI_OLD_NO_BACK) self.assertTrue(parser.check_id('56933095f'))
def test_analysis_dates_not_found(self): parser = DNIScumParser(DNI_NO_DATES) self.assertAnalysis([parser.BACK], parser.analysis(person={'name': 'begoña', 'surnames': 'sanz perez', 'id': '25748789r'}))
def test_analysis_new_dni_valid_with_only_number(self): parser = DNIScumParser(DNI_NEW) reference_date = datetime(year=2017, month=11, day=1).date() self.assertAnalysis([parser.VALID], parser.analysis(person={'name': 'ramon', 'surnames': 'alvarez dorado'}, reference_date=reference_date))
def test_analysis_keywords_not_found(self): parser = DNIScumParser(DNI_NO_KEYWORDS) self.assertAnalysis([parser.BACK], parser.analysis(person={'name': 'manuel', 'surnames': 'martinez perez', 'id': '16925657p'}))
def test_analysis_new_dni_not_client(self): parser = DNIScumParser(DNI_NEW) reference_date = datetime(year=2017, month=11, day=1).date() self.assertAnalysis([parser.FRONT, parser.BACK, parser.NOT_VALID_PERSON], parser.analysis(person={'name': 'luis', 'surnames': 'alvarez dorado', 'id': '14900073d'}, reference_date=reference_date))
def test_check_id_complete_dni_not_found(self): parser = DNIScumParser(DNI_OLD) self.assertFalse(parser.check_id('77 933095f'))
def test_not_is_back(self): parser = DNIScumParser(DNI_NEW_NO_BACK) self.assertFalse(parser.is_back())