Skip to content

Commit

Permalink
adds support for OPTIONS method (#7804)
Browse files Browse the repository at this point in the history
* adds support for OPTIONS method
  • Loading branch information
Fanny Jiang authored Oct 29, 2020
1 parent 0b99097 commit fde1404
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions datadog_checks_base/datadog_checks/base/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ def patch(self, url, **options):
def delete(self, url, **options):
return self._request('delete', url, options)

def options_method(self, url, **options):
return self._request('options', url, options)

def _request(self, method, url, options):
if self.log_requests:
self.logger.debug(u'Sending %s request to %s', method.upper(), url)
Expand Down
32 changes: 32 additions & 0 deletions datadog_checks_base/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,38 @@ def test_delete_session_option_override(self):
http.delete('https://www.google.com', persist=True, auth=options['auth'])
http.session.delete.assert_called_once_with('https://www.google.com', **options)

def test_options(self):
http = RequestsWrapper({}, {})

with mock.patch('requests.options'):
http.options_method('https://www.google.com')
requests.options.assert_called_once_with('https://www.google.com', **http.options)

def test_options_session(self):
http = RequestsWrapper({'persist_connections': True}, {})

with mock.patch('datadog_checks.base.utils.http.RequestsWrapper.session'):
http.options_method('https://www.google.com')
http.session.options.assert_called_once_with('https://www.google.com', **DEFAULT_OPTIONS)

def test_options_option_override(self):
http = RequestsWrapper({}, {})
options = http.options.copy()
options['auth'] = ('user', 'pass')

with mock.patch('requests.options'):
http.options_method('https://www.google.com', auth=options['auth'])
requests.options.assert_called_once_with('https://www.google.com', **options)

def test_options_session_option_override(self):
http = RequestsWrapper({}, {})
options = DEFAULT_OPTIONS.copy()
options.update({'auth': ('user', 'pass')})

with mock.patch('datadog_checks.base.utils.http.RequestsWrapper.session'):
http.options_method('https://www.google.com', persist=True, auth=options['auth'])
http.session.options.assert_called_once_with('https://www.google.com', **options)


class TestIntegration:
def test_session_timeout(self):
Expand Down

0 comments on commit fde1404

Please sign in to comment.