def test_non_registered_caller_incident_touch_commands(client, requests_mock, create_func, command_args, command_api_url, mock_response_file, expected_last_request_body): """Unit test Given - whether the command is Create or Update - command args When - running the command with a caller as a non registered caller. Then - validate 2 requests were called. - validate the entry context. """ client_func = client.update_incident request_method = "put" action = "updating" if create_func: client_func = client.create_incident request_method = "post" action = "creating" mock_topdesk_node = util_load_json(mock_response_file) response_incident = mock_topdesk_node.copy() request_command = getattr(requests_mock, request_method) def callback_func(request, _): if 'callerLookup' in request.json(): return {"message": "The value for the field 'callerLookup.id' cannot be parsed."} else: return response_incident request_command(command_api_url, json=callback_func) command_results = incident_touch_command(client=client, args=command_args, client_func=client_func, action=action) assert requests_mock.call_count == 3 assert requests_mock.last_request.json() == expected_last_request_body assert command_results.outputs_prefix == f'{INTEGRATION_NAME}.Incident' assert command_results.outputs_key_field == 'Id' assert command_results.outputs == capitalize_for_outputs([response_incident])
def test_caller_lookup_incident_touch_commands(client, requests_mock, create_func, command_args, command_api_url, mock_response_file, expected_last_request_body): """Unit test Given - whether the command is Create or Update - command args When - running the command with a caller as a registered caller. Then - validate 1 request was called. - validate the correct request was called. - validate the entry context. """ client_func = client.update_incident request_method = "put" action = "updating" if create_func: client_func = client.create_incident request_method = "post" action = "creating" mock_topdesk_node = util_load_json(mock_response_file) response_incident = mock_topdesk_node.copy() request_command = getattr(requests_mock, request_method) request_command(command_api_url, json=response_incident) command_results = incident_touch_command(client=client, args=command_args, client_func=client_func, action=action) assert requests_mock.call_count == 2 assert requests_mock.last_request.json() == expected_last_request_body assert command_results.outputs_prefix == f'{INTEGRATION_NAME}.Incident' assert command_results.outputs_key_field == 'Id' assert command_results.outputs == capitalize_for_outputs([response_incident])