Skip to content

Commit

Permalink
Merge pull request #17 from DeanWay/13-optional-id
Browse files Browse the repository at this point in the history
allow id on request structure
  • Loading branch information
DeanWay authored Nov 29, 2019
2 parents c0c013a + e3722b3 commit 46b859a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions pydantic_jsonapi/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class RequestDataModel(GenericModel, Generic[TypeT, AttributesT]):
"""
type: TypeT
attributes: AttributesT
id: Optional[str]
relationships: Optional[RequestRelationshipsType]


Expand Down
39 changes: 38 additions & 1 deletion tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_attributes_as_dict(self):
'type': 'item',
'attributes': {},
'relationships': None,
'id': None,
}
}

Expand All @@ -32,6 +33,7 @@ def test_attributes_as_item_model(self):
'price': 1.20
},
'relationships': None,
'id': None,
}
}
my_request_obj = ItemRequest(**obj_to_validate)
Expand Down Expand Up @@ -113,4 +115,39 @@ def test_request_with_relationships(self):
},
}
my_request_obj = MyRequest(**obj_to_validate)
assert my_request_obj.dict() == obj_to_validate
assert my_request_obj.dict() == {
'data': {
'type': 'item',
'attributes': {},
'relationships': {
'sold_at': {
'data': {
'type': 'store',
'id': 'abc123',
'meta': None
},
}
},
'id': None
},
}

def test_request_with_id(self):
MyRequest = JsonApiRequest('item', dict)
obj_to_validate = {
'data': {
'type': 'item',
'attributes': {},
'id': 'abc123'
},
}
my_request_obj = MyRequest(**obj_to_validate)
assert my_request_obj.dict() == {
'data': {
'type': 'item',
'attributes': {},
'relationships': None,
'id': 'abc123',
},
}

0 comments on commit 46b859a

Please sign in to comment.