Skip to content

Commit

Permalink
Merge pull request #34 from aaraney/fix_33
Browse files Browse the repository at this point in the history
Handle User subject_areas field null case
  • Loading branch information
sblack-usu authored Nov 18, 2021
2 parents 1a1c0e8 + 0226da7 commit c5c984f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 2 additions & 4 deletions hsclient/json_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ class User(BaseModel):
subject_areas: List[str] = []
date_joined: datetime = None

@validator('subject_areas', pre=True)
@validator("subject_areas", pre=True)
def split_subject_areas(cls, value):
if value:
return value.split(", ")
return value
return value.split(", ") if value else []


class ResourcePreview(BaseModel):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_json_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def user(change_test_dir):
return User(**json.loads(f.read()))


def test_null_subject_areas():
fields = {"subject_areas": None}
o = User(**fields)
assert o.subject_areas == []


def test_resource_preview_authors_field_default_is_empty_list():
"""verify all `authors` fields are instantiated with [] values."""
test_data_dict = {"authors": None}
Expand Down

0 comments on commit c5c984f

Please sign in to comment.