Skip to content

Commit

Permalink
Fix: empty payload (#1105)
Browse files Browse the repository at this point in the history
Closes #1081

Signed-off-by: Ludovic Rivallain <[email protected]>
  • Loading branch information
lrivallain authored and cartertinney committed Aug 28, 2023
1 parent d74b222 commit 0144401
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def on_request_response(op, error):
)
error = map_http_error(error=error, http_op=op)
if not error:
op_waiting_for_response.method_response = json.loads(op.response_body)
op_waiting_for_response.method_response = json.loads(op.response_body or 'null')
op_waiting_for_response.complete(error=error)

self.send_op_down(
Expand Down Expand Up @@ -122,7 +122,7 @@ def on_request_response(op, error):
)
error = map_http_error(error=error, http_op=op)
if not error:
op_waiting_for_response.storage_info = json.loads(op.response_body)
op_waiting_for_response.storage_info = json.loads(op.response_body or 'null')
op_waiting_for_response.complete(error=error)

self.send_op_down(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _handle_pipeline_event(self, event):
method_received = MethodRequest(
request_id=request_id,
name=method_name,
payload=json.loads(event.payload.decode("utf-8")),
payload=json.loads(event.payload.decode("utf-8") or 'null'),
)
self.send_event_up(pipeline_events_iothub.MethodRequestEvent(method_received))

Expand All @@ -219,7 +219,7 @@ def _handle_pipeline_event(self, event):
elif mqtt_topic_iothub.is_twin_desired_property_patch_topic(topic):
self.send_event_up(
pipeline_events_iothub.TwinDesiredPropertiesPatchEvent(
patch=json.loads(event.payload.decode("utf-8"))
patch=json.loads(event.payload.decode("utf-8") or 'null')
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ def test_method_request(self, event, stage, method_name, rid):
assert new_event.method_request.name == method_name
assert new_event.method_request.request_id == rid
# This is expanded on in in the next test
assert new_event.method_request.payload == json.loads(event.payload.decode("utf-8"))
assert new_event.method_request.payload == json.loads(event.payload.decode("utf-8") or 'null')

@pytest.mark.it(
"Derives the MethodRequestEvent's payload by converting the original event's payload from bytes into a JSON object"
Expand All @@ -904,6 +904,7 @@ def test_method_request(self, event, stage, method_name, rid):
pytest.param(b'"payload"', "payload", id="String JSON"),
pytest.param(b"1234", 1234, id="Int JSON"),
pytest.param(b"null", None, id="None JSON"),
pytest.param(b"", None, id="Empty JSON"),
],
)
def test_json_payload(self, event, stage, original_payload, derived_payload):
Expand Down Expand Up @@ -975,6 +976,7 @@ def event(self):
pytest.param(b'"payload"', "payload", id="String JSON"),
pytest.param(b"1234", 1234, id="Int JSON"),
pytest.param(b"null", None, id="None JSON"),
pytest.param(b"", None, id="Empty JSON"),
],
)
def test_twin_patch_event(self, event, stage, original_payload, derived_payload):
Expand Down

0 comments on commit 0144401

Please sign in to comment.