def validate_email(cls, v_field): # pylint: disable=no-self-argument, no-self-use if not v_field: raise ValueError('must not empty') for email in v_field.split(','): networks.validate_email(email) return v_field
def validate_email(cls, v_field): if not v_field: raise ValueError('must not empty') for email in v_field.split(','): networks.validate_email(email) return v_field
def validate( # type: ignore cls, value: str, field: "ModelField", config: "BaseConfig" ) -> Union["AnyUrl", str]: """ """ if value.startswith("mailto:"): schema = value[0:7] email = value[7:] realname = parseaddr(email)[0] name, email = validate_email(email) if realname: email = formataddr((name, email)) return schema + email elif value.startswith("mllp:") or value.startswith("llp:"): # xxx: find validation return value elif value in FHIR_PRIMITIVES: # Extensions may contain a valueUrl for a primitive FHIR type return value return AnyUrl.validate(value, field, config)
def test_email_validator_not_installed(): with pytest.raises(ImportError): validate_email('*****@*****.**')
def test_address_invalid(value): with pytest.raises(ValueError): validate_email(value)
def test_address_valid(value, name, email): assert validate_email(value) == (name, email)