Skip to content

Commit

Permalink
Fix test for Anyurl.
Browse files Browse the repository at this point in the history
  • Loading branch information
vsmalladi committed Apr 16, 2024
1 parent 18a2411 commit d1bb112
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
13 changes: 8 additions & 5 deletions compliance_suite/models/v1_0_0_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,17 @@ class Service(BaseModel):
def check_url_or_email(cls, value):
if value.startswith("mailto:"):
email = value[len("mailto:"):]
if EmailStr.validate(email):
try:
EmailStr.validate(email)
return value
else:
except ValidationError:
raise ValueError("Invalid email address")
elif AnyUrl.validate(value):
return value
else:
raise ValueError("Invalid URL")
try:
parse_obj_as(AnyUrl, value)
return value
except ValidationError:
raise ValueError("Invalid URL")


class TesServiceType(ServiceType):
Expand Down
13 changes: 8 additions & 5 deletions compliance_suite/models/v1_1_0_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,17 @@ class Service(BaseModel):
def check_url_or_email(cls, value):
if value.startswith("mailto:"):
email = value[len("mailto:"):]
if EmailStr.validate(email):
try:
EmailStr.validate(email)
return value
else:
except ValidationError:
raise ValueError("Invalid email address")
elif AnyUrl.validate(value):
return value
else:
raise ValueError("Invalid URL")
try:
parse_obj_as(AnyUrl, value)
return value
except ValidationError:
raise ValueError("Invalid URL")


class TesServiceType(ServiceType):
Expand Down

0 comments on commit d1bb112

Please sign in to comment.