Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PylobidWork exposes more dates #17

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions pylobid/pylobid.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,21 +282,39 @@ def creators(self) -> list:

@property
def date_of_creation(self) -> str:
"""returns the date of the works creations using `dateOfProduction`
if `dateOfProduction` is not provided `dateOfPublication` is used
"""returns the date of the works creations using `dateOfPublication`
if `dateOfPublication` is not provided `dateOfProduction` is used

Returns:
str: the prodcution or publication date of the work
"""
date = ""
for x in ["dateOfProduction", "dateOfPublication"]:
for x in ["dateOfPublication", "dateOfProduction"]:
try:
date = self.ent_dict[x][0]
break
except (KeyError, IndexError):
continue
return date

@property
def date_of_production(self) -> str:
"""returns the date of the works creations using `dateOfProduction`

Returns:
str: the prodcution date of the work
"""
return self.ent_dict.get("dateOfProduction", [""])[0]

@property
def date_of_publication(self) -> str:
"""returns the date of the works creations using `dateOfPublication`

Returns:
str: the publication date of the work
"""
return self.ent_dict.get("dateOfPublication", [""])[0]


class PyLobidPerson(PyLobidClient):
"""A python class representing a Person Entity."""
Expand Down
16 changes: 12 additions & 4 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@
TEST_WORK_FIXTURES = [
[
"300102224",
"1833",
[
{
"id": "https://d-nb.info/gnd/118580779",
Expand All @@ -187,10 +186,12 @@
"role": "librettist",
},
],
"1835",
"1833",
"1835",
],
[
"300109849",
"1786",
[
{
"id": "https://d-nb.info/gnd/118584596",
Expand All @@ -203,10 +204,12 @@
"role": "librettist",
},
],
"1786",
"1786",
"1786",
],
[
"300229550",
"1823",
[
{
"id": "https://d-nb.info/gnd/118610961",
Expand All @@ -219,16 +222,21 @@
"role": "librettist",
},
],
"1823",
"1823",
"",
],
[
"4006818-3",
"",
[
{
"id": "https://d-nb.info/gnd/118641549",
"label": "Paulus, Apostel, Heiliger",
"role": "author",
}
],
"",
"",
"",
],
]
6 changes: 4 additions & 2 deletions tests/test_pylobid.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,7 @@ def test_001_works(self):
for x in TEST_WORK_FIXTURES:
pl_ent = pl.PyLobidClient(x[0])
item = pl_ent.factory()
self.assertEqual(item.date_of_creation, x[1])
self.assertEqual(item.creators, x[2])
self.assertEqual(item.creators, x[1])
self.assertEqual(item.date_of_creation, x[2])
self.assertEqual(item.date_of_production, x[3])
self.assertEqual(item.date_of_publication, x[4])