async def test_rewind_works_under_200_and_200_http_codes(binding_string): """Tests that the rewind API works as expected under 'successful' http codes: 200, 202""" client = DurableOrchestrationClient(binding_string) for code in [200, 202]: mock_request = MockRequest( expected_url=f"{RPC_BASE_URL}instances/{INSTANCE_ID}/rewind?reason={REASON}", response=[code, ""]) client._post_async_request = mock_request.post result = await client.rewind(INSTANCE_ID, REASON) assert result is None
async def test_post_500_terminate(binding_string): raw_reason = 'stuff and things' reason = 'stuff%20and%20things' mock_request = MockRequest( expected_url=f"{RPC_BASE_URL}instances/{TEST_INSTANCE_ID}/terminate?reason={reason}", response=[500, MESSAGE_500]) client = DurableOrchestrationClient(binding_string) client._post_async_request = mock_request.post with pytest.raises(Exception): await client.terminate(TEST_INSTANCE_ID, raw_reason)
async def test_post_410_terminate(binding_string): raw_reason = 'stuff and things' reason = 'stuff%20and%20things' mock_request = MockRequest( expected_url=f"{RPC_BASE_URL}instances/{TEST_INSTANCE_ID}/terminate?reason={reason}", response=[410, None]) client = DurableOrchestrationClient(binding_string) client._post_async_request = mock_request.post result = await client.terminate(TEST_INSTANCE_ID, raw_reason) assert result is None
async def test_rewind_with_no_rpc_endpoint(binding_string): """Tests the behaviour of rewind without an RPC endpoint / under the legacy HTTP endpoint.""" client = DurableOrchestrationClient(binding_string) mock_request = MockRequest( expected_url=f"{RPC_BASE_URL}instances/{INSTANCE_ID}/rewind?reason={REASON}", response=[-1, ""]) client._post_async_request = mock_request.post client._orchestration_bindings._rpc_base_url = None expected_exception_str = "The Python SDK only supports RPC endpoints."\ + "Please remove the `localRpcEnabled` setting from host.json" with pytest.raises(Exception) as ex: await client.rewind(INSTANCE_ID, REASON) ex_message = str(ex.value) assert ex_message == expected_exception_str
async def test_start_new_orchestrator_not_found(binding_string): """Test that we throw the right exception when the orchestrator is not found. """ status = dict(ExceptionMessage=EXCEPTION_ORCHESTRATOR_NOT_FOUND_EXMESSAGE, StackTrace=STACK_TRACE, Message=EXCEPTION_ORCHESTRATOR_NOT_FOUND_MESSAGE, ExceptionType=EXCEPTION_TYPE_ORCHESTRATOR_NOT_FOUND) mock_request = MockRequest(expected_url=f"{RPC_BASE_URL}orchestrators/{TEST_ORCHESTRATOR}", response=[400, status]) client = DurableOrchestrationClient(binding_string) client._post_async_request = mock_request.post with pytest.raises(Exception) as ex: await client.start_new(TEST_ORCHESTRATOR) ex.match(EXCEPTION_ORCHESTRATOR_NOT_FOUND_EXMESSAGE)
async def test_rewind_throws_exception_during_404_410_and_500_errors(binding_string): """Tests the behaviour of rewind under 'exception' http codes: 404, 410, 500""" client = DurableOrchestrationClient(binding_string) codes = [404, 410, 500] exception_strs = [ f"No instance with ID {INSTANCE_ID} found.", "The rewind operation is only supported on failed orchestration instances.", "Something went wrong" ] for http_code, expected_exception_str in zip(codes, exception_strs): mock_request = MockRequest( expected_url=f"{RPC_BASE_URL}instances/{INSTANCE_ID}/rewind?reason={REASON}", response=[http_code, "Something went wrong"]) client._post_async_request = mock_request.post with pytest.raises(Exception) as ex: await client.rewind(INSTANCE_ID, REASON) ex_message = str(ex.value) assert ex_message == expected_exception_str