def test_get_start_new_url(binding_string):
    client = DurableOrchestrationClient(binding_string)
    instance_id = "2e2568e7-a906-43bd-8364-c81733c5891e"
    function_name = "my_function"
    start_new_url = client._get_start_new_url(instance_id, function_name)
    expected_url = replace_stand_in_bits(
        f"{RPC_BASE_URL}orchestrators/{function_name}/{instance_id}")
    assert expected_url == start_new_url
def test_create_check_status_response(binding_string):
    client = DurableOrchestrationClient(binding_string)
    instance_id = "2e2568e7-a906-43bd-8364-c81733c5891e"
    request = Mock(
        url=
        "http://test_azure.net/api/orchestrators/DurableOrchestrationTrigger")
    returned_response = client.create_check_status_response(
        request, instance_id)

    http_management_payload = {
        "id":
        instance_id,
        "statusQueryGetUri":
        r"http://test_azure.net/runtime/webhooks/durabletask/instances/"
        r"2e2568e7-a906-43bd-8364-c81733c5891e?taskHub"
        r"=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE",
        "sendEventPostUri":
        r"http://test_azure.net/runtime/webhooks/durabletask/instances/"
        r"2e2568e7-a906-43bd-8364-c81733c5891e/raiseEvent/{"
        r"eventName}?taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE",
        "terminatePostUri":
        r"http://test_azure.net/runtime/webhooks/durabletask/instances/"
        r"2e2568e7-a906-43bd-8364-c81733c5891e/terminate"
        r"?reason={text}&taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE",
        "rewindPostUri":
        r"http://test_azure.net/runtime/webhooks/durabletask/instances/"
        r"2e2568e7-a906-43bd-8364-c81733c5891e/rewind?reason"
        r"={text}&taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE",
        "purgeHistoryDeleteUri":
        r"http://test_azure.net/runtime/webhooks/durabletask/instances/"
        r"2e2568e7-a906-43bd-8364-c81733c5891e"
        r"?taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE"
    }
    for key, _ in http_management_payload.items():
        http_management_payload[key] = replace_stand_in_bits(
            http_management_payload[key])
    expected_response = {
        "status_code": 202,
        "body": json.dumps(http_management_payload),
        "headers": {
            "Content-Type": "application/json",
            "Location": http_management_payload["statusQueryGetUri"],
            "Retry-After": "10",
        },
    }

    for k, v in expected_response.get("headers").items():
        assert v == returned_response.headers.get(k)
    assert expected_response.get(
        "status_code") == returned_response.status_code
    assert expected_response.get(
        "body") == returned_response.get_body().decode()
def test_get_raise_event_url(binding_string):
    client = DurableOrchestrationClient(binding_string)
    instance_id = "2e2568e7-a906-43bd-8364-c81733c5891e"
    event_name = "test_event_name"
    task_hub_name = "test_task_hub"
    connection_name = "test_connection"
    raise_event_url = client._get_raise_event_url(instance_id, event_name, task_hub_name,
                                                  connection_name)

    expected_url = replace_stand_in_bits(
        f"{RPC_BASE_URL}instances/{instance_id}/raiseEvent/{event_name}"
        f"?taskHub=test_task_hub&connection=test_connection")

    assert expected_url == raise_event_url
def test_extracts_create_new_instance_post_uri(binding_info):
    expected_url = replace_stand_in_bits(
        "BASE_URL/orchestrators/{functionName}[/{instanceId}]?code=AUTH_CODE")
    assert \
        expected_url == binding_info.creation_urls["createNewInstancePostUri"]
def test_extracts_purge_history_delete_uri(binding_info):
    expected_url = replace_stand_in_bits(
        "BASE_URL/instances/INSTANCEID?taskHub=TASK_HUB_NAME&connection"
        "=Storage&code=AUTH_CODE")
    assert expected_url == binding_info.management_urls[
        "purgeHistoryDeleteUri"]
def test_extracts_rewind_post_uri(binding_info):
    expected_url = replace_stand_in_bits(
        "BASE_URL/instances/INSTANCEID/rewind?reason={"
        "text}&taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE")
    assert expected_url == binding_info.management_urls["rewindPostUri"]
def test_extracts_send_event_post_uri(binding_info):
    expected_url = replace_stand_in_bits(
        "BASE_URL/instances/INSTANCEID/raiseEvent/{"
        "eventName}?taskHub=TASK_HUB_NAME&connection=Storage&code=AUTH_CODE")
    assert expected_url == binding_info.management_urls["sendEventPostUri"]
def test_extracts_status_query_get_uri(binding_info):
    expected_url = replace_stand_in_bits(
        "BASE_URL/instances/INSTANCEID?taskHub=TASK_HUB_NAME&connection"
        "=Storage&code=AUTH_CODE")
    assert expected_url == binding_info.management_urls["statusQueryGetUri"]
def test_extracts_create_and_wait_on_new_instance_post_uri(binding_info):
    expected_url = replace_stand_in_bits(
        "BASE_URL/orchestrators/{functionName}[/{instanceId}]?timeout={"
        "timeoutInSeconds}&pollingInterval={intervalInSeconds}&code=AUTH_CODE")
    assert expected_url == binding_info.creation_urls[
        "createAndWaitOnNewInstancePostUri"]