/tests/regressiontests/utils/checksums.py

https://code.google.com/p/mango-py/ · Python · 29 lines · 21 code · 4 blank · 4 comment · 2 complexity · 0e1070e7283d55de530919bb4e6f4cd3 MD5 · raw file

  1. import unittest
  2. from django.utils import checksums
  3. class TestUtilsChecksums(unittest.TestCase):
  4. def check_output(self, function, value, output=None):
  5. """
  6. Check that function(value) equals output. If output is None,
  7. check that function(value) equals value.
  8. """
  9. if output is None:
  10. output = value
  11. self.assertEqual(function(value), output)
  12. def test_luhn(self):
  13. f = checksums.luhn
  14. items = (
  15. (4111111111111111, True), ('4111111111111111', True),
  16. (4222222222222, True), (378734493671000, True),
  17. (5424000000000015, True), (5555555555554444, True),
  18. (1008, True), ('0000001008', True), ('000000001008', True),
  19. (4012888888881881, True), (1234567890123456789012345678909, True),
  20. (4111111111211111, False), (42222222222224, False),
  21. (100, False), ('100', False), ('0000100', False),
  22. ('abc', False), (None, False), (object(), False),
  23. )
  24. for value, output in items:
  25. self.check_output(f, value, output)