Esempio n. 1
0
    def test_min_integer(self):
        validator = validators.Integer(minimum=2)
        self.assertEqual(2, validator.validate('2', None))
        self.assertEqual(42, validator.validate(42, None))

        self.assertRaises(validators.ValidationError, validator.validate, 1,
                          None)
Esempio n. 2
0
    def test_max_integer(self):
        validator = validators.Integer(maximum=42)
        self.assertEqual(1, validator.validate('1', None))
        self.assertEqual(42, validator.validate(42, None))

        self.assertRaises(validators.ValidationError, validator.validate, 43,
                          None)

        self.assertRaises(validators.ValidationError, validator.validate,
                          10000000, None)
Esempio n. 3
0
    def test_not_an_integer(self):
        validator = validators.Integer()

        self.assertRaises(validators.ValidationError, validator.validate, 31.2,
                          None)
        self.assertRaises(validators.ValidationError, validator.validate,
                          '42.1', None)
        self.assertRaises(validators.ValidationError, validator.validate,
                          'foo', None)
        self.assertRaises(validators.ValidationError, validator.validate,
                          '10-21', None)
Esempio n. 4
0
    def test_min_and_max_integer(self):
        validator = validators.Integer(minimum=2, maximum=42)

        self.assertRaises(validators.ValidationError, validator.validate, 1,
                          None)

        self.assertEqual(2, validator.validate('2', None))
        self.assertEqual(10, validator.validate('10', None))
        self.assertEqual(42, validator.validate(42, None))

        self.assertRaises(validators.ValidationError, validator.validate, 43,
                          None)
Esempio n. 5
0
 def test_basic_integer(self):
     validator = validators.Integer()
     self.assertEqual(42, validator.validate('42', None))
     self.assertEqual(42, validator.validate(42, None))
     self.assertEqual(0, validator.validate('0', None))
     self.assertEqual(-10, validator.validate('-10', None))