summaryrefslogtreecommitdiff
path: root/tests/regressiontests/utils/checksums.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-09-27 15:15:04 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-09-27 15:15:04 +0000
commitba53cd30d1427dbbd564b1791ef6348db93cf37f (patch)
tree0a00ba3853afce4c8cabb45de03a577e9e2d6688 /tests/regressiontests/utils/checksums.py
parentb4a8c77e7c4035f0ecc2151835bf5ceb0be2f392 (diff)
Reorganized utils tests so it's all in separate modules. Thanks to Stephan Jaekel.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13889 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/utils/checksums.py')
-rw-r--r--tests/regressiontests/utils/checksums.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/regressiontests/utils/checksums.py b/tests/regressiontests/utils/checksums.py
new file mode 100644
index 0000000000..bb73576a80
--- /dev/null
+++ b/tests/regressiontests/utils/checksums.py
@@ -0,0 +1,29 @@
+from django.test import TestCase
+
+from django.utils import checksums
+
+class TestUtilsChecksums(TestCase):
+
+ def check_output(self, function, value, output=None):
+ """
+ Check that function(value) equals output. If output is None,
+ check that function(value) equals value.
+ """
+ if output is None:
+ output = value
+ self.assertEqual(function(value), output)
+
+ def test_luhn(self):
+ f = checksums.luhn
+ items = (
+ (4111111111111111, True), ('4111111111111111', True),
+ (4222222222222, True), (378734493671000, True),
+ (5424000000000015, True), (5555555555554444, True),
+ (1008, True), ('0000001008', True), ('000000001008', True),
+ (4012888888881881, True), (1234567890123456789012345678909, True),
+ (4111111111211111, False), (42222222222224, False),
+ (100, False), ('100', False), ('0000100', False),
+ ('abc', False), (None, False), (object(), False),
+ )
+ for value, output in items:
+ self.check_output(f, value, output)