Add return value for mocked urllib3 request()
Mocked request() was returning MagicMock object, which caused test_do_get() to fail. This was caused by what seems to be inconsistent behaviour of MagicMock object on different platforms in Python 2.7 [1]. Ubuntu 18.04, Python 2.7.5, mock 3.0.5: MagicMock() >= 400 -> True CentOS-7, Python 2.7.5, mock 3.0.5: MagicMock() >= 400 -> False Story: 2001245 Task: 36038 [1] https://github.com/testing-cabal/mock/issues/196 Change-Id: I7d41ec9abd87b4c799f4c7797d76da5350ca90bd
This commit is contained in:
parent
06acccf446
commit
d6fa304bed
@ -59,8 +59,9 @@ class Service(object):
|
||||
r = http.request('GET', url, headers=self.headers)
|
||||
except Exception as e:
|
||||
LOG.error("Request on service '%s' with url '%s' failed",
|
||||
(self.s_type, url))
|
||||
self.s_type, url)
|
||||
raise e
|
||||
|
||||
if r.status >= 400:
|
||||
raise ServiceError("Request on service '%s' with url '%s' failed"
|
||||
" with code %d" % (self.s_type, url, r.status))
|
||||
|
@ -14,7 +14,6 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
import unittest
|
||||
|
||||
from config_tempest.services.base import Service
|
||||
from config_tempest.services.base import VersionedService
|
||||
@ -37,9 +36,14 @@ class TestService(BaseServiceTest):
|
||||
self.FAKE_HEADERS)
|
||||
return expected_resp.data
|
||||
|
||||
@unittest.skip('Failing due to Storyboard: 2001245')
|
||||
@mock.patch('config_tempest.api_discovery.urllib3')
|
||||
@mock.patch('config_tempest.services.base.urllib3')
|
||||
def test_do_get(self, mock_urllib3):
|
||||
mock_http = mock.Mock()
|
||||
mock_r = mock.Mock()
|
||||
mock_r.status = 200
|
||||
mock_http.request.return_value = mock_r
|
||||
mock_urllib3.PoolManager.return_value = mock_http
|
||||
|
||||
resp = self.Service.do_get(self.FAKE_URL)
|
||||
expected_resp = self._mocked_do_get(mock_urllib3)
|
||||
self.assertEqual(resp, expected_resp)
|
||||
|
Loading…
x
Reference in New Issue
Block a user