def validate(self) -> bool:
     """
     Valid ID or not?
     Luhn algorithm validates the ID number
     Additional check is where the date makes sense
     In Luhn 0000
     """
     if self.identity_length() and self.valid_birth_date():
         try:
             return bool(luhn.validate(self.id_number))
         except ValueError as e:
             logger.error(e)
             return False
     else:
         return False
Example #2
0
def test_luhn_validate():

    pos = luhn.validate("9001245289086")
    neg = luhn.validate("0000000000001")
    assert pos is True
    assert neg is False
Example #3
0
def test_luhn_complete():
    luhn_complete = luhn.complete("900124528908")
    assert luhn_complete == "9001245289086"
    assert luhn.validate(luhn_complete)
Example #4
0
def test_luhn_digit():
    luhn_digit = luhn.digit("900124528908")
    assert luhn_digit == 6
    assert luhn.validate(f"900124528908{luhn_digit}")
Example #5
0
def test_luhn_generate():
    luhn_gen = luhn.generate(20)
    assert len(luhn_gen) == 20
    assert luhn.validate(luhn_gen)