mirror of https://github.com/eyhc1/rendercv.git
add tests for PublicationEntry class
This commit is contained in:
parent
726e03fa05
commit
ae2a21aa1a
|
@ -775,6 +775,7 @@ class PublicationEntry(Event):
|
||||||
examples=[10, 100],
|
examples=[10, 100],
|
||||||
)
|
)
|
||||||
journal: Optional[str] = Field(
|
journal: Optional[str] = Field(
|
||||||
|
default=None,
|
||||||
title="Journal",
|
title="Journal",
|
||||||
description="The journal or the conference name.",
|
description="The journal or the conference name.",
|
||||||
examples=[
|
examples=[
|
||||||
|
@ -787,11 +788,12 @@ class PublicationEntry(Event):
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_doi(cls, doi: str) -> str:
|
def check_doi(cls, doi: str) -> str:
|
||||||
doi_url = f"https://doi.org/{doi}"
|
doi_url = f"https://doi.org/{doi}"
|
||||||
|
|
||||||
html = urllib.request.urlopen(doi_url).read().decode("utf-8")
|
try:
|
||||||
if "DOI NOT FOUND" in html:
|
urllib.request.urlopen(doi_url)
|
||||||
|
except:
|
||||||
raise ValueError(f"{doi} cannot be found in the DOI System.")
|
raise ValueError(f"{doi} cannot be found in the DOI System.")
|
||||||
|
|
||||||
return doi
|
return doi
|
||||||
|
|
||||||
@computed_field
|
@computed_field
|
||||||
|
|
|
@ -338,7 +338,7 @@ class TestRendercv(unittest.TestCase):
|
||||||
with self.subTest(msg="date is provided"):
|
with self.subTest(msg="date is provided"):
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
def test_data_education_highlight_strings(self):
|
def test_data_education_entry_highlight_strings(self):
|
||||||
input = {
|
input = {
|
||||||
"institution": "My Institution",
|
"institution": "My Institution",
|
||||||
"area": "My Area",
|
"area": "My Area",
|
||||||
|
@ -439,7 +439,8 @@ class TestRendercv(unittest.TestCase):
|
||||||
with self.subTest(msg="gpa, transcript_url, and highlights are provided"):
|
with self.subTest(msg="gpa, transcript_url, and highlights are provided"):
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
def test_data_publication_netry_doi_url(self):
|
def test_data_publication_entry_check_doi(self):
|
||||||
|
# Invalid DOI:
|
||||||
input = {
|
input = {
|
||||||
"title": "My Publication",
|
"title": "My Publication",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
@ -449,6 +450,37 @@ class TestRendercv(unittest.TestCase):
|
||||||
"doi": "invalidDoi",
|
"doi": "invalidDoi",
|
||||||
"date": "2020-01-01",
|
"date": "2020-01-01",
|
||||||
}
|
}
|
||||||
|
with self.subTest(msg="invalid doi"):
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
data_model.PublicationEntry(**input)
|
||||||
|
|
||||||
|
# Valid DOI:
|
||||||
|
input = {
|
||||||
|
"title": "My Publication",
|
||||||
|
"authors": [
|
||||||
|
"Author 1",
|
||||||
|
"Author 2",
|
||||||
|
],
|
||||||
|
"doi": "10.1103/PhysRevB.76.054309",
|
||||||
|
"date": "2007-08-01",
|
||||||
|
}
|
||||||
|
with self.subTest(msg="valid doi"):
|
||||||
|
data_model.PublicationEntry(**input)
|
||||||
|
|
||||||
|
def test_data_publication_entry_doi_url(self):
|
||||||
|
input = {
|
||||||
|
"title": "My Publication",
|
||||||
|
"authors": [
|
||||||
|
"Author 1",
|
||||||
|
"Author 2",
|
||||||
|
],
|
||||||
|
"doi": "10.1103/PhysRevB.76.054309",
|
||||||
|
"date": "2007-08-01",
|
||||||
|
}
|
||||||
|
expected = "https://doi.org/10.1103/PhysRevB.76.054309"
|
||||||
|
publication = data_model.PublicationEntry(**input)
|
||||||
|
result = publication.doi_url
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue