From 4e45c3a66cd00f4dd4cd38bcf34c3ae707891d3c Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Wed, 28 Nov 2018 09:09:08 -0500 Subject: [PATCH] mock an HTTP call to fix busted unit tests --- awx/main/tests/unit/api/test_views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/awx/main/tests/unit/api/test_views.py b/awx/main/tests/unit/api/test_views.py index e9a3f177b9..fb4ce2e301 100644 --- a/awx/main/tests/unit/api/test_views.py +++ b/awx/main/tests/unit/api/test_views.py @@ -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: