Ejemplo n.º 1
0
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'))
Ejemplo n.º 2
0
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'))
Ejemplo n.º 3
0
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, e:
            return e.unpack_errors()['ccNumber']
Ejemplo n.º 4
0
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, e:
            return e.unpack_errors()['ccNumber']
Ejemplo n.º 5
0
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"))
Ejemplo n.º 6
0
 def setUp(self):
     self.validator = CreditCardValidator()
Ejemplo n.º 7
0
from formencode.validators import CreditCardValidator, Invalid

cc = CreditCardValidator()


def validate(cctype, ccnumber):
    try:
        cc.validate_python({'ccNumber': ccnumber, 'ccType': cctype}, None)
    except Invalid, e:
        return e.unpack_errors()['ccNumber']


messages = cc.message


def test_cc():
    assert validate('visa', '4' + ('1' * 15)) is None
    assert validate('visa',
                    '5' + ('1' * 12)) == messages('invalidNumber', None)
    assert validate('visa',
                    '4' + ('1' * 11) + '2') == messages('invalidNumber', None)
    assert validate('visa', 'test') == messages('notANumber', None)
    assert validate('visa', '4' + ('1' * 10)) == messages('badLength', None)
Ejemplo n.º 8
0
 def setUp(self):
     self.validator = CreditCardValidator()