~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/utils_tests/test_checksums.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

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