mock an HTTP call to fix busted unit tests

This commit is contained in:
Ryan Petrello 2018-11-28 09:09:08 -05:00
parent 87b55dc413
commit 4e45c3a66c
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777

View File

@ -221,8 +221,12 @@ class TestHostInsights():
assert resp.status_code == 404
def test_get_insights_user_agent(self, patch_parent, mocker):
resp = HostInsights()._get_insights('https://example.org', 'joe', 'example')
assert re.match(r'AWX [^\s]+ \(open\)', resp.request.headers['User-Agent'])
with mock.patch.object(requests.Session, 'get') as get:
HostInsights()._get_insights('https://example.org', 'joe', 'example')
assert get.call_count == 1
args, kwargs = get.call_args_list[0]
assert args == ('https://example.org',)
assert re.match(r'AWX [^\s]+ \(open\)', kwargs['headers']['User-Agent'])
class TestSurveySpecValidation: