Skip to content

Commit

Permalink
bump coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
yezz123 committed Jan 8, 2024
1 parent ea24cd0 commit 177d866
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 4 additions & 6 deletions pydantic_extra_types/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class PaymentCardBrand(str, Enum):
visa = 'Visa'
mir = 'Mir'
maestro = 'Maestro'
maestro_uk = 'Maestro UK'
discover = 'Discover'
verve = 'Verve'
dankort = 'Dankort'
Expand Down Expand Up @@ -157,14 +156,13 @@ def validate_brand(card_number: str) -> PaymentCardBrand:
elif 2200 <= int(card_number[:4]) <= 2204:
brand = PaymentCardBrand.mir
required_length = list(range(16, 20))
elif card_number[:4] in {'5018', '5020', '5038', '5893', '6304', '6759', '6761', '6762', '6763'}:
brand = PaymentCardBrand.maestro
required_length = list(range(12, 20))
elif card_number.startswith('6759') or card_number[:6] in (
elif card_number[:4] in {'5018', '5020', '5038', '5893', '6304', '6759', '6761', '6762', '6763'} or card_number[
:6
] in (
'676770',
'676774',
):
brand = PaymentCardBrand.maestro_uk
brand = PaymentCardBrand.maestro
required_length = list(range(12, 20))
elif card_number.startswith('65') or 644 <= int(card_number[:3]) <= 649 or card_number.startswith('6011'):
brand = PaymentCardBrand.discover
Expand Down
8 changes: 7 additions & 1 deletion tests/test_types_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
VALID_MIR_17 = '22000000000000004'
VALID_MIR_18 = '220000000000000004'
VALID_MIR_19 = '2200000000000000004'
VALID_OTHER = '2000000000000000008'
VALID_DISCOVER = '6011000000000004'
VALID_VERVE_16 = '5061000000000001'
VALID_VERVE_18 = '506100000000000001'
Expand All @@ -26,6 +25,9 @@
VALID_UNIONPAY_19 = '8100000000000000001'
VALID_JCB_16 = '3528000000000001'
VALID_JCB_19 = '3528000000000000001'
VALID_MAESTRO = '6759649826438453'
VALID_TROY = '9792000000000001'
VALID_OTHER = '2000000000000000008'
LUHN_INVALID = '4000000000000000'
LEN_INVALID = '40000000000000006'

Expand Down Expand Up @@ -113,6 +115,8 @@ def test_validate_luhn_check_digit(card_number: str, valid: bool):
(VALID_JCB_16, PaymentCardBrand.jcb, True),
(VALID_JCB_19, PaymentCardBrand.jcb, True),
(LEN_INVALID, PaymentCardBrand.visa, False),
(VALID_MAESTRO, PaymentCardBrand.maestro, True),
(VALID_TROY, PaymentCardBrand.troy, True),
(VALID_OTHER, PaymentCardBrand.other, True),
],
)
Expand All @@ -139,6 +143,8 @@ def test_length_for_brand(card_number: str, brand: PaymentCardBrand, valid: bool
(VALID_UNIONPAY_16, PaymentCardBrand.unionpay),
(VALID_JCB_16, PaymentCardBrand.jcb),
(VALID_OTHER, PaymentCardBrand.other),
(VALID_MAESTRO, PaymentCardBrand.maestro),
(VALID_TROY, PaymentCardBrand.troy),
],
)
def test_get_brand(card_number: str, brand: PaymentCardBrand):
Expand Down

0 comments on commit 177d866

Please sign in to comment.