Skip to content

Commit 347332a

Browse files
committed
CR corrections
1 parent 8881304 commit 347332a

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

alinka/schemas/document_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pydantic import BaseModel, Field, computed_field, model_validator
55

66
from alinka.constants import ActivityForm, Issue, Reason
7-
from alinka.utils import pesel_to_date_of_birth
7+
from alinka.utils import extract_date_of_birth_from_pesel
88

99

1010
class AddressData(BaseModel):
@@ -47,7 +47,7 @@ def calculate_date_of_birth(self) -> "ChildData":
4747
if self.birth_date:
4848
return self
4949
pesel = self.pesel
50-
self.birth_date = pesel_to_date_of_birth(pesel)
50+
self.birth_date = extract_date_of_birth_from_pesel(pesel)
5151
return self
5252

5353

alinka/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from datetime import date
22

33

4-
def pesel_to_date_of_birth(pesel: str) -> date:
4+
def extract_date_of_birth_from_pesel(pesel: str) -> date:
55
year_part, month_part, day = int(pesel[0:2]), int(pesel[2:4]), int(pesel[4:6])
66
year = 2000 + year_part if month_part > 20 else 1900 + year_part
77
month = month_part - 20 if month_part > 20 else month_part
88
return date(year, month, day)
99

1010

11-
def validate_pesel(pesel: str) -> bool:
11+
def is_valid_pesel(pesel: str) -> bool:
1212
if len(pesel) != 11 or not pesel.isdigit():
1313
return False
1414
weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]

alinka/widget/validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from PySide6.QtGui import QValidator
22

3-
from alinka.utils import validate_pesel
3+
from alinka.utils import is_valid_pesel
44

55

66
class RequiredValidator(QValidator):
@@ -24,7 +24,7 @@ def validate(self, input_str: str, pos: int) -> tuple[QValidator.State, str, int
2424
return QValidator.Invalid, input_str, pos
2525
if len(input_str) < 11:
2626
return QValidator.Intermediate, input_str, pos
27-
if validate_pesel(input_str):
27+
if is_valid_pesel(input_str):
2828
return QValidator.Acceptable, input_str, pos
2929
else:
3030
return QValidator.Intermediate, input_str, pos

tests/test_utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from alinka.utils import pesel_to_date_of_birth, validate_pesel
5+
from alinka.utils import extract_date_of_birth_from_pesel, is_valid_pesel
66

77

88
class TestValidatePesel:
@@ -15,7 +15,7 @@ class TestValidatePesel:
1515
],
1616
)
1717
def test_validate_pesel__valid_pesel(self, pesel):
18-
assert validate_pesel(pesel)
18+
assert is_valid_pesel(pesel)
1919

2020
@pytest.mark.parametrize(
2121
"pesel",
@@ -31,7 +31,7 @@ def test_validate_pesel__valid_pesel(self, pesel):
3131
],
3232
)
3333
def test_validate_pesel__invalid_pesel(self, pesel):
34-
assert not validate_pesel(pesel)
34+
assert not is_valid_pesel(pesel)
3535

3636

3737
class TestPeselToDateOfBirth:
@@ -46,6 +46,6 @@ class TestPeselToDateOfBirth:
4646
("05212294647", date(2005, 1, 22)),
4747
],
4848
)
49-
def test_pesel_to_date_of_birth__success(self, pesel, expected_date):
50-
assert validate_pesel(pesel)
51-
assert pesel_to_date_of_birth(pesel) == expected_date
49+
def test_extract_date_of_birth_from_pesel__success(self, pesel, expected_date):
50+
assert is_valid_pesel(pesel)
51+
assert extract_date_of_birth_from_pesel(pesel) == expected_date

0 commit comments

Comments
 (0)