Commit 0c13117b authored by Jo Sama's avatar Jo Sama 😱
Browse files

Fix create_operator()

Don't serialize unset attributes, as this will break TopDesks schema for
POST request to /operators.
parent 1bb84aba
......@@ -46,6 +46,12 @@ def operator():
return Operator.from_dict(d)
@pytest.fixture
def uncreated_operator():
return Operator.from_dict(
load_json_file('uncreated_operator.json'))
@pytest.fixture
def operator_list_data():
return load_json_file('operator_list.json')
......@@ -23,12 +23,11 @@ def test_list_operators(client, base_url, requests_mock, operator_list_data):
def test_create_operator(client,
base_url,
requests_mock,
operator_data,
operator):
uncreated_operator):
m = requests_mock.post(client.urls.get_operators())
client.create_operator(operator)
client.create_operator(uncreated_operator)
object_sent = m.request_history[-1].text
sent_operator = Operator.from_json(object_sent)
assert(sent_operator == operator)
assert(sent_operator.dict() == operator.dict())
assert(sent_operator == uncreated_operator)
......@@ -79,7 +79,7 @@ class TopDeskClient:
url = self.urls.get_operators()
self.post(url,
return_response=True,
data=operator.json(by_alias=True))
data=operator.json())
def list_operators(self):
for x in self.get(self.urls.get_operators()):
......
......@@ -16,6 +16,18 @@ class BaseModel(pydantic.BaseModel):
data = json.loads(json_data)
return cls.from_dict(data)
def _force_serialization_arguments(func):
def fun(self, *args, **kwargs):
kwargs['by_alias'] = True
kwargs['skip_defaults'] = True
return func(self, *args, **kwargs)
return fun
# TBD: Do we want to do the following for copy() and json()?
@_force_serialization_arguments
def dict(self, *args, **kwargs):
return super(BaseModel, self).dict(*args, **kwargs)
class Identifier(BaseModel):
""" An object with only an ID that references some entity. """
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment