Django

Code

Changeset 6569

Show
Ignore:
Timestamp:
10/20/07 08:40:20 (11 months ago)
Author:
mtredinnick
Message:

Fixed #5475 -- Added the Luhn check algorithm to django.utils.checksums so that
localflavors don't have to reimplement it each time. Thanks, hawkeye.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/regressiontests/utils/tests.py

    r6366 r6569  
    55from unittest import TestCase 
    66 
    7 from django.utils import html 
     7from django.utils import html, checksums 
    88 
    99from timesince import timesince_tests 
     
    117117            self.check_output(f, value, output) 
    118118 
     119class TestUtilsChecksums(TestCase): 
     120 
     121    def check_output(self, function, value, output=None): 
     122        """ 
     123        Check that function(value) equals output.  If output is None, 
     124        check that function(value) equals value. 
     125        """ 
     126        if output is None: 
     127            output = value 
     128        self.assertEqual(function(value), output) 
     129 
     130    def test_luhn(self): 
     131        f = checksums.luhn 
     132        items = ( 
     133            (4111111111111111, True), ('4111111111111111', True), 
     134            (4222222222222, True), (378734493671000, True), 
     135            (5424000000000015, True), (5555555555554444, True), 
     136            (1008, True), ('0000001008', True), ('000000001008', True), 
     137            (4012888888881881, True), (1234567890123456789012345678909, True), 
     138            (4111111111211111, False), (42222222222224, False), 
     139            (100, False), ('100', False), ('0000100', False), 
     140            ('abc', False), (None, False), (object(), False), 
     141        ) 
     142        for value, output in items: 
     143            self.check_output(f, value, output) 
     144 
    119145__test__ = { 
    120146    'timesince_tests': timesince_tests,