diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-09-27 15:34:41 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-09-27 15:34:41 +0000 |
| commit | 4cd11f8681db0ec8efabbdcb3ebf73f650d1635c (patch) | |
| tree | e165bb1978a982a1bd3caca414e1f57ac406ae30 /tests/regressiontests/utils/checksums.py | |
| parent | 494933a36bbd78d041c8c3ac60da418392d50860 (diff) | |
[1.2.X] Reorganized utils tests so it's all in separate modules. Thanks to Stephan Jaekel.
Backport of r13889 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13910 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/utils/checksums.py')
| -rw-r--r-- | tests/regressiontests/utils/checksums.py | 29 |
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) |
