Skip to content

Commit

Permalink
Mock out httpbin.org responses to fix flaky tests (#14630)
Browse files Browse the repository at this point in the history
  • Loading branch information
alopezz authored Jun 5, 2023
1 parent 949e262 commit 07e3746
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2678,7 +2678,7 @@ def test_ssl_verify_not_raise_warning(caplog, mocked_openmetrics_check_factory,
check = mocked_openmetrics_check_factory(instance)
scraper_config = check.get_scraper_config(instance)

with caplog.at_level(logging.DEBUG):
with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')):
resp = check.send_request('https://httpbin.org/get', scraper_config)

assert "httpbin.org" in resp.content.decode('utf-8')
Expand All @@ -2703,7 +2703,7 @@ def test_send_request_with_dynamic_prometheus_url(caplog, mocked_openmetrics_che
# `prometheus_url` changed just before calling `send_request`
scraper_config['prometheus_url'] = 'https://www.example.com/foo/bar'

with caplog.at_level(logging.DEBUG):
with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')):
resp = check.send_request('https://httpbin.org/get', scraper_config)

assert "httpbin.org" in resp.content.decode('utf-8')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1964,9 +1964,11 @@ def test_text_filter_input():


def test_ssl_verify_not_raise_warning(caplog, mocked_prometheus_check, text_data):
from datadog_checks.dev.http import MockResponse

check = mocked_prometheus_check

with caplog.at_level(logging.DEBUG):
with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')):
resp = check.poll('https://httpbin.org/get')

assert 'httpbin.org' in resp.content.decode('utf-8')
Expand All @@ -1977,10 +1979,12 @@ def test_ssl_verify_not_raise_warning(caplog, mocked_prometheus_check, text_data


def test_ssl_verify_not_raise_warning_cert_false(caplog, mocked_prometheus_check, text_data):
from datadog_checks.dev.http import MockResponse

check = mocked_prometheus_check
check.ssl_ca_cert = False

with caplog.at_level(logging.DEBUG):
with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')):
resp = check.poll('https://httpbin.org/get')

assert 'httpbin.org' in resp.content.decode('utf-8')
Expand Down

0 comments on commit 07e3746

Please sign in to comment.