data: fix url not showing in PublicationEntry (#128)

This commit is contained in:
Sina Atalay
2024-07-19 01:18:24 +03:00
parent 83df79f9db
commit bf581a6179
4 changed files with 27 additions and 5 deletions

View File

@@ -226,6 +226,10 @@ def print_validation_errors(exception: pydantic.ValidationError):
"This is not a valid date! Please use either YYYY-MM-DD, YYYY-MM, or YYYY"
" format!"
),
"String should match pattern '\\b10\\..*'": (
'A DOI prefix should always start with "10.". For example,'
' "10.1109/TASC.2023.3340648".'
),
"URL scheme should be 'http' or 'https'": "This is not a valid URL!",
"Field required": "This field is required!",
"value is not a valid phone number": "This is not a valid phone number!",

View File

@@ -233,7 +233,7 @@ def make_a_url_clean(url: str) -> str:
Returns:
str: The clean URL.
"""
url = url.replace("https://", "").replace("http://", "").replace("www.", "")
url = url.replace("https://", "").replace("http://", "")
if url.endswith("/"):
url = url[:-1]

View File

@@ -229,7 +229,7 @@ class PublicationEntryBase(RenderCVBaseModelWithExtraKeys):
title="Authors",
description="The authors of the publication in order as a list of strings.",
)
doi: Optional[str] = pydantic.Field(
doi: Optional[Annotated[str, pydantic.Field(pattern=r"\b10\..*")]] = pydantic.Field(
default=None,
title="DOI",
description="The DOI of the publication.",
@@ -252,8 +252,8 @@ class PublicationEntryBase(RenderCVBaseModelWithExtraKeys):
def ignore_url_if_doi_is_given(self) -> "PublicationEntryBase":
"""Check if DOI is provided and ignore the URL if it is provided."""
doi_is_provided = self.doi is not None
url_is_provided = self.url is not None
if doi_is_provided and url_is_provided:
if doi_is_provided:
self.url = None
return self
@@ -278,7 +278,7 @@ class PublicationEntryBase(RenderCVBaseModelWithExtraKeys):
url_is_provided = self.url is not None
if url_is_provided:
return computers.make_a_url_clean(self.url) # type: ignore
return computers.make_a_url_clean(str(self.url)) # type: ignore
else:
return ""

View File

@@ -767,3 +767,21 @@ def test_dictionary_key_to_proper_section_title(key, expected_section_title):
# def test_if_available_themes_and_avaialble_theme_options_has_the_same_length():
@pytest.mark.parametrize(
"url, expected_clean_url",
[
("https://example.com", "example.com"),
("https://example.com/", "example.com"),
("https://example.com/test", "example.com/test"),
("https://example.com/test/", "example.com/test"),
("https://www.example.com/test/", "www.example.com/test"),
],
)
def test_make_a_url_clean(url, expected_clean_url):
assert computers.make_a_url_clean(url) == expected_clean_url
assert (
data.PublicationEntry(title="Test", authors=["test"], url=url).clean_url
== expected_clean_url
)