/usr/lib/python2.7/dist-packages/formencode/tests/test_cc.py is in python-formencode 1.3.0-0ubuntu5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | # -*- coding: utf-8 -*-
import unittest
from formencode import Invalid
from formencode.validators import CreditCardValidator, CreditCardExpires
class TestCreditCardValidator(unittest.TestCase):
def setUp(self):
self.validator = CreditCardValidator()
def validate(self, cctype, ccnumber):
try:
self.validator.to_python(
dict(ccNumber=ccnumber, ccType=cctype), None)
except Invalid as e:
return e.unpack_errors()['ccNumber']
def message(self, key):
return self.validator.message(key, None)
def test_validate(self):
validate, message = self.validate, self.message
self.assertTrue(validate('visa', '4' + '1' * 15) is None)
self.assertEqual(validate('visa', '5' + '1' * 12),
message('invalidNumber'))
self.assertEqual(validate('visa', '4' + '1' * 11 + '2'),
message('invalidNumber'))
self.assertEqual(validate('visa', 'test'),
message('notANumber'))
self.assertEqual(validate('visa', '4' + '1' * 10),
message('badLength'))
class TestCreditCardExpires(unittest.TestCase):
def setUp(self):
self.validator = CreditCardExpires()
def validate(self, month, year):
try:
self.validator.to_python(
dict(ccExpiresMonth=month, ccExpiresYear=year), None)
except Invalid as e:
return e.unpack_errors()['ccExpiresMonth']
def message(self, key):
return self.validator.message(key, None)
def test_validate(self):
validate, message = self.validate, self.message
self.assertTrue(validate('11', '2250') is None)
self.assertEqual(validate('11', 'test'), message('notANumber'))
self.assertEqual(validate('test', '2250'), message('notANumber'))
self.assertEqual(validate('10', '2005'), message('invalidNumber'))
self.assertEqual(validate('10', '05'), message('invalidNumber'))
|