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],
|
||||
)
|
||||
journal: Optional[str] = Field(
|
||||
default=None,
|
||||
title="Journal",
|
||||
description="The journal or the conference name.",
|
||||
examples=[
|
||||
|
@ -788,8 +789,9 @@ class PublicationEntry(Event):
|
|||
def check_doi(cls, doi: str) -> str:
|
||||
doi_url = f"https://doi.org/{doi}"
|
||||
|
||||
html = urllib.request.urlopen(doi_url).read().decode("utf-8")
|
||||
if "DOI NOT FOUND" in html:
|
||||
try:
|
||||
urllib.request.urlopen(doi_url)
|
||||
except:
|
||||
raise ValueError(f"{doi} cannot be found in the DOI System.")
|
||||
|
||||
return doi
|
||||
|
|
|
@ -338,7 +338,7 @@ class TestRendercv(unittest.TestCase):
|
|||
with self.subTest(msg="date is provided"):
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def test_data_education_highlight_strings(self):
|
||||
def test_data_education_entry_highlight_strings(self):
|
||||
input = {
|
||||
"institution": "My Institution",
|
||||
"area": "My Area",
|
||||
|
@ -439,7 +439,8 @@ class TestRendercv(unittest.TestCase):
|
|||
with self.subTest(msg="gpa, transcript_url, and highlights are provided"):
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def test_data_publication_netry_doi_url(self):
|
||||
def test_data_publication_entry_check_doi(self):
|
||||
# Invalid DOI:
|
||||
input = {
|
||||
"title": "My Publication",
|
||||
"authors": [
|
||||
|
@ -449,6 +450,37 @@ class TestRendercv(unittest.TestCase):
|
|||
"doi": "invalidDoi",
|
||||
"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__":
|
||||
|
|
Loading…
Reference in New Issue