forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e57220
commit cb7ac13
Showing
6 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
packages/common-library/src/common_library/pydantic_networks_extension.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from typing import Annotated, TypeAlias | ||
from pydantic import AfterValidator, AnyHttpUrl | ||
|
||
|
||
AnyHttpUrlLegacy: TypeAlias = Annotated[str, AnyHttpUrl, AfterValidator(lambda u: u.rstrip("/"))] |
2 changes: 1 addition & 1 deletion
2
...src/common_library/utils/serialization.py → ...brary/src/common_library/serialization.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 1 addition & 5 deletions
6
...ry/tests/test_utils_pydantic_extension.py → ...y/tests/test_pydantic_fields_extension.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/common-library/tests/test_pydantic_networks_extension.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from common_library.pydantic_networks_extension import AnyHttpUrlLegacy | ||
from pydantic import AnyHttpUrl, TypeAdapter | ||
from pydantic_core import Url | ||
|
||
|
||
def test_any_http_url(): | ||
url = TypeAdapter(AnyHttpUrl).validate_python( | ||
"http://backgroud.testserver.io", | ||
) | ||
|
||
assert isinstance(url, Url) | ||
assert f"{url}" == "http://backgroud.testserver.io/" # NOTE: trailing '/' added in Pydantic v2 | ||
|
||
def test_any_http_url_legacy(): | ||
url = TypeAdapter(AnyHttpUrlLegacy).validate_python( | ||
"http://backgroud.testserver.io", | ||
) | ||
|
||
assert isinstance(url, str) | ||
assert url == "http://backgroud.testserver.io" |
2 changes: 1 addition & 1 deletion
2
...library/tests/test_utils_serialization.py → ...ommon-library/tests/test_serialization.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters