You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bankcard_tests.py 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import nose.tools
  2. from oscar.apps.payment import bankcards
  3. fixture_data = {
  4. bankcards.VISA: ('4111111111111111',),
  5. bankcards.MASTERCARD: ('5500000000000004',),
  6. bankcards.DISCOVER: ('6011000000000004',),
  7. bankcards.AMEX: ('340000000000009',),
  8. }
  9. def test_bankcard_type_sniffing():
  10. def compare(number, type):
  11. nose.tools.eq_(bankcards.bankcard_type(number), type)
  12. for bankcard_type, numbers in fixture_data.items():
  13. for number in numbers:
  14. yield compare, number, bankcard_type
  15. valid_numbers = [
  16. '4111111111111111',
  17. '5500000000000004',
  18. '6011000000000004',
  19. '340000000000009']
  20. invalid_numbers = [
  21. '4111111111111110',
  22. '5500000000000009',
  23. '6011000000000000',
  24. '340000000000005']
  25. def test_luhn_check():
  26. def is_valid(n):
  27. assert bankcards.luhn(n) is True
  28. for number in valid_numbers:
  29. yield is_valid, number
  30. def is_not_valid(n):
  31. assert bankcards.luhn(n) is False
  32. for number in invalid_numbers:
  33. yield is_not_valid, number