Пример #1
0
    def test_string_validator(self):
        v = String()
        self.assertEqual("foo", v.validate("foo"))
        with self.assertRaises(ValidationError) as c:
            v.validate(1)

        self.assertEqual("Expected str got int instead.", str(c.exception))
Пример #2
0
    def test_string_validator_min_len_kw(self):
        v = String(min_len=3)

        with self.assertRaises(ValidationError) as c:
            v.validate("fo")

        self.assertEqual("String must be at least length 3.", str(c.exception))
Пример #3
0
    def test_string_validator_max_len_kw(self):
        v = String(max_len=3)
        self.assertEqual("foo", v.validate("foo"))
        with self.assertRaises(ValidationError) as c:
            v.validate("foobar")

        self.assertEqual("String exceeds max length of 3.", str(c.exception))
Пример #4
0
    def test_string_validator(self):
        v = String()
        self.assertEqual("foo", v.validate("foo"))
        with self.assertRaises(ValidationError) as c:
            v.validate(1)

        self.assertEqual("Expected str got int instead.", str(c.exception))
Пример #5
0
    def test_string_validator_min_len_kw(self):
        v = String(min_len=3)

        with self.assertRaises(ValidationError) as c:
            v.validate("fo")

        self.assertEqual("String must be at least length 3.", str(c.exception))
Пример #6
0
    def test_string_validator_max_len_kw(self):
        v = String(max_len=3)
        self.assertEqual("foo", v.validate("foo"))
        with self.assertRaises(ValidationError) as c:
            v.validate("foobar")

        self.assertEqual("String exceeds max length of 3.", str(c.exception))