Skip to content

Commit

Permalink
quickfix of partialdate/fuzzy date
Browse files Browse the repository at this point in the history
  • Loading branch information
nad2000 committed Aug 14, 2019
1 parent d168ffb commit 1ea58e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion orcid_hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ def create(cls, value):

return cls(*[int(v) for v in value0.split('-')])

return cls(**{k: int(v.get("value")) if v else None for k, v in value.items()})
return cls(
**{k: int(v.get("value")) if v and v.get("value") else None
for k, v in value.items()})

def as_datetime(self):
"""Get 'datetime' data representation."""
Expand Down
27 changes: 27 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,33 @@ def test_partial_date():
}
}
assert pd.year == 2003 and pd.month == 7 and pd.day == 31

pd = PartialDate.create({
"year": {
"value": "2003"
},
"month": {
"value": "11"
},
"day": {
"value": None
}
})
assert pd.year == 2003 and pd.month == 11 and pd.day is None

pd = PartialDate.create({
"year": {
"value": "2003"
},
"month": {
"value": None
},
"day": {
"value": None
}
})
assert pd.year == 2003 and pd.month is None and pd.day is None

assert PartialDate().as_orcid_dict() is None
assert PartialDate.create(None) is None
assert PartialDate.create({}) is None
Expand Down

0 comments on commit 1ea58e6

Please sign in to comment.