Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,11 @@ def call_http(self, method: str, uri: str, content: Optional[str] = None,
The durable HTTP request to schedule.
"""
json_content: Optional[str] = None
if content and content is not isinstance(content, str):
json_content = json.dumps(content)
else:
json_content = content
if content is not None:
if not isinstance(content, str):
json_content = json.dumps(content)
else:
json_content = content

request = DurableHttpRequest(method, uri, json_content, headers, token_source)
action = CallHttpAction(request)
Expand Down
30 changes: 30 additions & 0 deletions tests/orchestrator/test_call_http.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from azure.durable_functions.models.ReplaySchema import ReplaySchema
import json
import pytest
from typing import Dict

from azure.durable_functions.constants import HTTP_ACTION_NAME
Expand Down Expand Up @@ -174,3 +175,32 @@ def test_post_completed_state():
# assert_valid_schema(result)
assert_orchestration_state_equals(expected, result)
validate_result_http_request(result)

@pytest.mark.parametrize("content, expected_content", [
(None, None),
("string data", "string data"),
('{"key": "value"}', '{"key": "value"}'),
('["list", "content"]', '["list", "content"]'),
('[]', '[]'),
('42', '42'),
('true', 'true'),
# Cases that test actual behavior (not strictly adhering to Optional[str])
({"key": "value"}, '{"key": "value"}'),
(["list", "content"], '["list", "content"]'),
([], '[]'),
(42, '42'),
(True, 'true'),
])
def test_call_http_content_handling(content, expected_content):
def orchestrator_function(context):
yield context.call_http("POST", TEST_URI, content)

context_builder = ContextBuilder('test_call_http_content_handling')
result = get_orchestration_state_result(context_builder, orchestrator_function)

assert len(result['actions']) == 1
http_action = result['actions'][0][0]['httpRequest']

assert http_action['method'] == "POST"
assert http_action['uri'] == TEST_URI
assert http_action['content'] == expected_content
Loading