Skip to content

Commit

Permalink
Merge pull request #67 from datacite/issue-66
Browse files Browse the repository at this point in the history
Issue 66
  • Loading branch information
jrhoads authored Jan 28, 2022
2 parents 9aac9d8 + 6931b68 commit 441fa40
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 64 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ factory-boy = "*"
termcolor = "*"
python-dotenv = "*"
pytest-env = "*"
pytest-sugar = "*"

[packages]
flask = "*"
Expand Down
9 changes: 8 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

177 changes: 177 additions & 0 deletions tests/integration/fixtures/datacite_api_doi_dateproblems.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
{
"data": {
"id": "10.5438/prvv-nv23",
"type": "dois",
"attributes": {
"doi": "10.5438/prvv-nv23",
"prefix": "10.5438",
"suffix": "prvv-nv23",
"identifiers": [
{
"identifier": "https://doi.org/10.5438/prvv-nv23",
"identifierType": "DOI"
}
],
"creators": [
{
"name": "Fenner, Martin",
"nameType": "Personal",
"givenName": "Martin",
"familyName": "Fenner",
"affiliation": ["DataCite"],
"nameIdentifiers": [
{
"schemeUri": "https://orcid.org",
"nameIdentifier": "https://orcid.org/0000-0003-1419-2405",
"nameIdentifierScheme": "ORCID"
}
]
},
{
"name": "Hallett, Richard",
"nameType": "Personal",
"givenName": "Richard",
"familyName": "Hallett",
"affiliation": ["DataCite"],
"nameIdentifiers": [
{
"schemeUri": "https://orcid.org",
"nameIdentifier": "https://orcid.org/0000-0002-8599-0773",
"nameIdentifierScheme": "ORCID"
}
]
}
],
"titles": [
{
"title": "Welcome to the DataCite Team, Richard!"
}
],
"publisher": "DataCite",
"container": {},
"publicationYear": 2018,
"subjects": [
{
"subject": "datacite"
}
],
"contributors": [],
"dates": [
{
"date": null,
"dateType": null
},
{
"date": "2018-01-18",
"dateType": "Updated"
}
],
"language": null,
"types": {
"ris": "GEN",
"bibtex": "article",
"citeproc": "post-weblog",
"schemaOrg": "BlogPosting",
"resourceTypeGeneral": "Text"
},
"relatedIdentifiers": [
{
"relationType": "IsPartOf",
"relatedIdentifier": "10.5438/0000-00ss",
"resourceTypeGeneral": "Text",
"relatedIdentifierType": "DOI"
}
],
"sizes": [],
"formats": null,
"version": "1.0",
"rightsList": [
{
"rights": null,
"rightsUri": null
}
],
"descriptions": [
{
"lang": null,
"description": "DataCite is pleased to welcome Richard Hallett to our team. Richard joined DataCite as application developer in December. Get to know him better via this interview. Richard Hallett Can you tell us a little bit about what you did before you started...",
"descriptionType": "Abstract"
}
],
"geoLocations": [{}],
"fundingReferences": null,
"xml": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHJlc291cmNlIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtNCIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtNCBodHRwOi8vc2NoZW1hLmRhdGFjaXRlLm9yZy9tZXRhL2tlcm5lbC00L21ldGFkYXRhLnhzZCI+CiAgPGlkZW50aWZpZXIgaWRlbnRpZmllclR5cGU9IkRPSSI+MTAuNTQzOC9QUlZWLU5WMjM8L2lkZW50aWZpZXI+CiAgPGNyZWF0b3JzPgogICAgPGNyZWF0b3I+CiAgICAgIDxjcmVhdG9yTmFtZSBuYW1lVHlwZT0iUGVyc29uYWwiPkZlbm5lciwgTWFydGluPC9jcmVhdG9yTmFtZT4KICAgICAgPGdpdmVuTmFtZT5NYXJ0aW48L2dpdmVuTmFtZT4KICAgICAgPGZhbWlseU5hbWU+RmVubmVyPC9mYW1pbHlOYW1lPgogICAgICA8bmFtZUlkZW50aWZpZXIgbmFtZUlkZW50aWZpZ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ldHRlciB2aWEgdGhpcyBpbnRlcnZpZXcuIFJpY2hhcmQgSGFsbGV0dCBDYW4geW91IHRlbGwgdXMgYSBsaXR0bGUgYml0IGFib3V0IHdoYXQgeW91IGRpZCBiZWZvcmUgeW91IHN0YXJ0ZWQuLi48L2Rlc2NyaXB0aW9uPgogIDwvZGVzY3JpcHRpb25zPgogIDxnZW9Mb2NhdGlvbnM+CiAgICA8Z2VvTG9jYXRpb24vPgogIDwvZ2VvTG9jYXRpb25zPgo8L3Jlc291cmNlPgo=",
"url": "https://blog.datacite.org/welcome-to-team-richard/",
"contentUrl": null,
"metadataVersion": 5,
"schemaVersion": null,
"source": null,
"isActive": true,
"state": "findable",
"reason": null,
"created": "2018-03-17T06:33:00.000Z",
"registered": "2018-10-17T05:48:57.000Z",
"published": "2018",
"updated": "2019-08-10T08:02:12.000Z"
},
"relationships": {
"client": {
"data": {
"id": "datacite.blog",
"type": "clients"
}
},
"provider": {
"data": {
"id": "dryad",
"type": "providers"
}
},
"media": {
"data": {
"id": "10.5438/prvv-nv23",
"type": "media"
}
}
}
},
"included": [
{
"id": "datacite.blog",
"type": "clients",
"attributes": {
"name": "DataCite Blog",
"symbol": "DATACITE.BLOG",
"year": 2019,
"contactEmail": "[email protected]",
"alternateName": null,
"description": null,
"language": null,
"clientType": "repository",
"domains": "*",
"issn": null,
"url": "https://blog.datacite.org",
"created": "2019-01-02T14:27:23.000Z",
"updated": "2019-01-02T17:22:42.000Z",
"isActive": true,
"hasPassword": true
},
"relationships": {
"provider": {
"data": {
"id": "datacite",
"type": "providers"
}
},
"prefixes": {
"data": [
{
"id": "10.5438",
"type": "prefixes"
}
]
}
}
}
]
}
17 changes: 17 additions & 0 deletions tests/integration/test_catalogs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import json
from viringo import catalogs
from viringo.services import datacite
def test_build_metadata_null_dates(mocker):
mocked_requests_get = mocker.patch('viringo.services.datacite.requests.get')
with open('tests/integration/fixtures/datacite_api_doi_dateproblems.json') as json_file:
data = json.load(json_file)
mocked_requests_get.return_value.status_code = 200
mocked_requests_get.return_value.json.return_value = data

result = datacite.get_metadata("10.5438/prvv-nv23")

oai_server = catalogs.DataCiteOAIServer()
meta = oai_server.build_metadata_map(
result
)
assert meta.get('date') == ['2018', 'Updated: 2018-01-18']
6 changes: 4 additions & 2 deletions viringo/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ def build_metadata_map(self, result):
dates = []
if result.publication_year:
dates.append(str(result.publication_year))
dates.extend([date['type'] + ": " + str(date['date'])
for date in result.dates])
date_strings = [
f"{d.get('type')}: {d.get('date')}" for d in result.dates
]
dates.extend(date_strings)

rights = []
for right in result.rights:
Expand Down
Loading

0 comments on commit 441fa40

Please sign in to comment.