original_docstring: Use some MagicMocks to patch get and post methods for requests
  
          This uses a dynamic function for the 'side_effect' to for custom responses
          
docstring: Use some MagicMocks to patch get and post methods for requests
  This uses a dynamic function for the 'side_effect' to for custom responses
docstring_tokens: Use some MagicMocks to patch get and post methods for requests This uses a dynamic function for the ' side_effect ' to for custom responses
code: def _setup_api_mocks():
          """Use some MagicMocks to patch get and post methods for requests
  
          This uses a dynamic function for the 'side_effect' to for custom responses
          """
          def _mock_side_effect(mocker):
  
              def _mock_by_service():
                  url = mocker.call_args[0][0]
                  url_path = os.path.split(url)[1]
                  if mocker.method == 'post':
                      if 'jira' in url:
                          if 'auth' in url:
                              return {'session': {'name': 'cookie_name', 'value': 'cookie_value'}}
  
                          return {'id': 3005}
  
                      elif 'phantom' in url:
                          return {'id': 1948}
  
                      elif 'api.pagerduty' in url:
                          if 'incidents' in url_path:
                              return {'incident': {'id': 'incident_id'}}
  
                      elif 'events.pagerduty' in url:
                          if 'enqueue' in url_path:
                              return {'dedup_key': 'returned_dedup_key'}
  
                  elif mocker.method == 'get':
                      if 'phantom' in 'url':
                          return {'count': 0, 'data': []}
  
                      elif 'api.pagerduty' in url:
                          return {url_path: [{'id': 1234, 'name': 'foobar'}]}
  
                  # Default to returning an empty dict in case this was not implemented for a service
                  return dict()
  
              return _mock_by_service
  
          get_patcher = patch('requests.get')
          get_mock = get_patcher.start()
          get_mock.method = 'get'
  
          # Set the patched request.get return value to 200
          get_mock.return_value.status_code = 200
  
          # Set the side_effect of the json method to our dynamic function
          # Passing in the get_mock object lets us access the calls to it
          get_mock.return_value.json.side_effect = _mock_side_effect(get_mock)
  
          post_patcher = patch('requests.post')
          post_mock = post_patcher.start()
          post_mock.method = 'post'
  
          # Set the patched requests.post return value to 200
          post_mock.return_value.status_code = 200
  
          # Set the side_effect of the json method to our dynamic function
          # Passing in the post_mock object lets us access the calls to it
          post_mock.return_value.json.side_effect = _mock_side_effect(post_mock)
  
          put_patcher = patch('requests.put')
          put_mock = put_patcher.start()
          put_mock.method = 'put'
  
          # Set the patched requests.put return value to 200
          put_mock.return_value.status_code = 200
  
          cb_patcher = patch.object(carbonblack, 'CbResponseAPI', side_effect=helpers.MockCBAPI)
          cb_patcher.start()
code_tokens: def _setup_api_mocks ( ) : def _mock_side_effect ( mocker ) : def _mock_by_service ( ) : url = mocker . call_args [ 0 ] [ 0 ] url_path = os . path . split ( url ) [ 1 ] if mocker . method == 'post' : if 'jira' in url : if 'auth' in url : return { 'session' : { 'name' : 'cookie_name' , 'value' : 'cookie_value' } } return { 'id' : 3005 } elif 'phantom' in url : return { 'id' : 1948 } elif 'api.pagerduty' in url : if 'incidents' in url_path : return { 'incident' : { 'id' : 'incident_id' } } elif 'events.pagerduty' in url : if 'enqueue' in url_path : return { 'dedup_key' : 'returned_dedup_key' } elif mocker . method == 'get' : if 'phantom' in 'url' : return { 'count' : 0 , 'data' : [ ] } elif 'api.pagerduty' in url : return { url_path : [ { 'id' : 1234 , 'name' : 'foobar' } ] } return dict ( ) return _mock_by_service get_patcher = patch ( 'requests.get' ) get_mock = get_patcher . start ( ) get_mock . method = 'get' get_mock . return_value . status_code = 200 get_mock . return_value . json . side_effect = _mock_side_effect ( get_mock ) post_patcher = patch ( 'requests.post' ) post_mock = post_patcher . start ( ) post_mock . method = 'post' post_mock . return_value . status_code = 200 post_mock . return_value . json . side_effect = _mock_side_effect ( post_mock ) put_patcher = patch ( 'requests.put' ) put_mock = put_patcher . start ( ) put_mock . method = 'put' put_mock . return_value . status_code = 200 cb_patcher = patch . object ( carbonblack , 'CbResponseAPI' , side_effect = helpers . MockCBAPI ) cb_patcher . start ( )
short_docstring: Use some MagicMocks to patch get and post methods for requests
  This uses a dynamic function for the 'side_effect' to for custom responses
short_docstring_tokens: Use some MagicMocks to patch get and post methods for requests This uses a dynamic function for the ' side_effect ' to for custom responses
comment: """Use some MagicMocks to patch get and post methods for requests
  
          This uses a dynamic function for the 'side_effect' to for custom responses
          """$SEP$# Default to returning an empty dict in case this was not implemented for a service$SEP$# Set the patched request.get return value to 200$SEP$# Set the side_effect of the json method to our dynamic function$SEP$# Passing in the get_mock object lets us access the calls to it$SEP$# Set the patched requests.post return value to 200$SEP$# Set the side_effect of the json method to our dynamic function$SEP$# Passing in the post_mock object lets us access the calls to it$SEP$# Set the patched requests.put return value to 200