Skip to content

Commit

Permalink
Merge pull request #50 from fernflower/restrictsuffixto2
Browse files Browse the repository at this point in the history
Restrict suffix to 2 digits only
  • Loading branch information
olegeech-me authored Sep 5, 2024
2 parents 2c08168 + d07063c commit 4bfe572
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bot/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _parse_application_number_full(num_str: str):
This function returns a tuple (number, suffix, type, year) in case of success or None otherwise.
"""
num_str = num_str.replace(" ", "").upper()
num_regex = r"^(OAM-){0,1}0{0,5}([1-9]{1}[0-9]{0,4})(-[0-9]+){0,1}/([A-Z]{2})-([0-9]{4})$"
num_regex = r"^(OAM-){0,1}0{0,5}([1-9]{1}[0-9]{0,4})(-[0-9]{1,2}){0,1}/([A-Z]{2})-([0-9]{4})$"
matched = re.match(num_regex, num_str)
if not matched:
return
Expand All @@ -246,7 +246,7 @@ def _parse_application_number(num_str: str):
This function returns a tuple (number, suffix) in case of success or None otherwise.
"""
num_str = num_str.replace(" ", "").upper()
num_regex = r"^(OAM-){0,1}0{0,5}([1-9]{1}[0-9]{0,4})(-[0-9]+){0,1}$"
num_regex = r"^(OAM-){0,1}0{0,5}([1-9]{1}[0-9]{0,4})(-[0-9]{1,2}){0,1}$"
matched = re.match(num_regex, num_str)
if not matched:
return
Expand Down
8 changes: 8 additions & 0 deletions src/tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@
"num_str, app_num, app_suffix, app_type, app_year",
[
("OAM-4242/TP-2042", "4242", "0", "TP", "2042"),
("12345/TP-2023", "12345", "0", "TP", "2023"),
("4242-5/DO-2020", "4242", "5", "DO", "2020"),
("oAM-12345-9/MK-2023", "12345", "9", "MK", "2023"),
("BAD-NUMBER/MK-2023", None, None, None, None),
("oam-4242-6/MK-1999", None, None, None, None),
("oam-4242-6/NT-2021", None, None, None, None),
("OAM-00004-1/MK-2020", "4", "1", "MK", "2020"),
("OAM-00004-99/MK-2020", "4", "99", "MK", "2020"),
# suffix too long
("oAM-12345-911/MK-2023", None, None, None, None),
],
)
def test__parse_application_number_full(num_str, app_num, app_suffix, app_type, app_year):
Expand All @@ -53,10 +57,14 @@ def test__parse_application_number_full(num_str, app_num, app_suffix, app_type,
"num_str, app_num, app_suffix",
[
("OAM-4242/TP-2042", "4242", "0"),
("12345/TP-2023", "12345", "0"),
("4242-5/DO-2020", "4242", "5"),
("oAM-12345-9/MK-2023", "12345", "9"),
("BAD-NUMBER/MK-2023", None, None),
("OAM-00004-1", "4", "1"),
("OAM-00004-99", "4", "99"),
# suffix too long
("OAM-00004-108", None, None),
],
)
def test__parse_application_number(num_str, app_num, app_suffix):
Expand Down

0 comments on commit 4bfe572

Please sign in to comment.