Skip to content

Commit

Permalink
PylobidWork exposes more dates
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Oct 29, 2024
1 parent 7ddcc59 commit 642d15c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
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])

0 comments on commit 642d15c

Please sign in to comment.