Repository: identique/idnumbers (language: python)

Issue:
id number for Israel
https://en.wikipedia.org/wiki/National_identification_number#Israel


Discussion / hints:

Fix patch:
diff --git a/idnumbers/nationalid/ISR.py b/idnumbers/nationalid/ISR.py
new file mode 100644
index 00000000..e54d44a0
--- /dev/null
+++ b/idnumbers/nationalid/ISR.py
@@ -0,0 +1,40 @@
+import re
+from types import SimpleNamespace
+from typing import Optional
+
+from .util import CHECK_DIGIT, validate_regexp, luhn_digit
+
+
+class NationalID:
+    """
+    Israel Identity Number, מספר זהות, Mispar Zehut
+    https://en.wikipedia.org/wiki/National_identification_number#Israel
+    https://taxid.pro/docs/countries/israel
+    """
+    METADATA = SimpleNamespace(**{
+        'iso3166_alpha2': 'IL',
+        # length without insignificant chars
+        'min_length': 9,
+        'max_length': 9,
+        # has parse function
+        'parsable': False,
+        # has checksum function
+        'checksum': True,
+        # regular expression to validate the id
+        'regexp': re.compile(r'^(\d{9})$')
+    })
+
+    @staticmethod
+    def validate(id_number: str) -> bool:
+        """
+        Validate
+        """
+        return str(NationalID.checksum(id_number)) == id_number[-1]
+
+    @staticmethod
+    def checksum(id_number: str) -> Optional[CHECK_DIGIT]:
+        if not validate_regexp(id_number, NationalID.METADATA.regexp):
+            return None
+        """Calculate national id checksum"""
+        numbers = [int(i) for i in id_number]
+        return luhn_digit(numbers[:-1], False)


Test patch:
diff --git a/tests/nationalid/test_ISR.py b/tests/nationalid/test_ISR.py
new file mode 100644
index 00000000..08880f0e
--- /dev/null
+++ b/tests/nationalid/test_ISR.py
@@ -0,0 +1,12 @@
+from unittest import TestCase
+from idnumbers.nationalid import ISR
+
+
+class TestISRValidation(TestCase):
+    def test_normal_case(self):
+        self.assertTrue(ISR.NationalID.validate('523656783'))
+        self.assertTrue(ISR.NationalID.validate('231740705'))
+        self.assertTrue(ISR.NationalID.validate('339677395'))
+
+    def test_error_case(self):
+        self.assertFalse(ISR.NationalID.validate('523656782'))