Ejemplo n.º 1
0
    def test_email_field(self):
        # data type
        f = EmailField()
        self.assertRaises(ValidationError, f.validate, 123)

        # max length
        f = EmailField(max_length=15)
        self.assertRaises(ValidationError, f.validate, "*****@*****.**")
        self.assertEqual(f.validate("*****@*****.**"), "*****@*****.**")

        # email format
        f = EmailField()
        for item in ["123", "123@", "@qq.com", "@qq", "123@", "123@qq", "123#qq.com"]:
            self.assertRaises(ValidationError, f.validate, item)

        for item in ["*****@*****.**", "*****@*****.**"]:
            self.assertEqual(f.validate(item), item)
Ejemplo n.º 2
0
def test_emailsfield_valid(required, nullable, value):
    field = EmailField(required, nullable)
    assert not field.validate(value)
Ejemplo n.º 3
0
def test_emailfield_not_valid(required, nullable, value, ex_mes):
    field = EmailField(required, nullable)
    with pytest.raises(ValidationError) as e:
        field.validate(value)
    assert str(e.value) == ex_mes