Files
shanxia2.0/backend/tests/test_id_card_age.py
T
2026-08-19 22:20:42 +08:00

19 lines
722 B
Python

from datetime import date
from app.core.id_card import calc_age_from_chinese_id_card
def test_calc_age_from_18_digit_id():
# 1990-05-15
id_card = "340102199005151234"
assert calc_age_from_chinese_id_card(id_card, today=date(2026, 5, 14)) == 35
assert calc_age_from_chinese_id_card(id_card, today=date(2026, 5, 15)) == 36
assert calc_age_from_chinese_id_card(id_card, today=date(2026, 8, 19)) == 36
def test_calc_age_rejects_invalid():
assert calc_age_from_chinese_id_card("") is None
assert calc_age_from_chinese_id_card("34010219900515") is None
assert calc_age_from_chinese_id_card("340102199013151234") is None
assert calc_age_from_chinese_id_card("340102199002301234") is None