| 123456789101112131415161718 |
- 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
|