modify api client to use request instead of send
This commit is contained in:
parent
0134631ab3
commit
08df6f8a46
@ -41,10 +41,10 @@ class APIClient(object):
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
|
||||
return self.session.send(method,
|
||||
request_url,
|
||||
headers=request_headers,
|
||||
data=data)
|
||||
return self.session.request(method,
|
||||
request_url,
|
||||
headers=request_headers,
|
||||
data=data)
|
||||
|
||||
def heartbeat(self, mac_addr, url, mode, version):
|
||||
path = '/{api_version}/agents/{mac_addr}'.format(
|
||||
|
@ -36,8 +36,8 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
'Heartbeat-Before': expected_heartbeat_before,
|
||||
})
|
||||
|
||||
self.api_client.session.send = mock.Mock()
|
||||
self.api_client.session.send.return_value = response
|
||||
self.api_client.session.request = mock.Mock()
|
||||
self.api_client.session.request.return_value = response
|
||||
|
||||
heartbeat_before = self.api_client.heartbeat(
|
||||
url='http://1.2.3.4:9999/',
|
||||
@ -47,18 +47,19 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
|
||||
self.assertEqual(heartbeat_before, expected_heartbeat_before)
|
||||
|
||||
send_args = self.api_client.session.send.call_args[0]
|
||||
self.assertEqual(send_args[0], 'PUT')
|
||||
self.assertEqual(send_args[1], API_URL + 'v1/agents/a:b:c:d')
|
||||
request_args = self.api_client.session.request.call_args[0]
|
||||
self.assertEqual(request_args[0], 'PUT')
|
||||
self.assertEqual(request_args[1], API_URL + 'v1/agents/a:b:c:d')
|
||||
|
||||
content = json.loads(self.api_client.session.send.call_args[1]['data'])
|
||||
data = self.api_client.session.request.call_args[1]['data']
|
||||
content = json.loads(data)
|
||||
self.assertEqual(content['url'], 'http://1.2.3.4:9999/')
|
||||
self.assertEqual(content['mode'], 'STANDBY')
|
||||
self.assertEqual(content['version'], '15')
|
||||
|
||||
def test_heartbeat_requests_exception(self):
|
||||
self.api_client.session.send = mock.Mock()
|
||||
self.api_client.session.send.side_effect = Exception('api is down!')
|
||||
self.api_client.session.request = mock.Mock()
|
||||
self.api_client.session.request.side_effect = Exception('api is down!')
|
||||
|
||||
self.assertRaises(errors.HeartbeatError,
|
||||
self.api_client.heartbeat,
|
||||
@ -69,8 +70,8 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
|
||||
def test_heartbeat_invalid_status_code(self):
|
||||
response = httmock.response(status_code=404)
|
||||
self.api_client.session.send = mock.Mock()
|
||||
self.api_client.session.send.return_value = response
|
||||
self.api_client.session.request = mock.Mock()
|
||||
self.api_client.session.request.return_value = response
|
||||
|
||||
self.assertRaises(errors.HeartbeatError,
|
||||
self.api_client.heartbeat,
|
||||
@ -81,8 +82,8 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
|
||||
def test_heartbeat_missing_heartbeat_before_header(self):
|
||||
response = httmock.response(status_code=204)
|
||||
self.api_client.session.send = mock.Mock()
|
||||
self.api_client.session.send.return_value = response
|
||||
self.api_client.session.request = mock.Mock()
|
||||
self.api_client.session.request.return_value = response
|
||||
|
||||
self.assertRaises(errors.HeartbeatError,
|
||||
self.api_client.heartbeat,
|
||||
@ -95,8 +96,8 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
response = httmock.response(status_code=204, headers={
|
||||
'Heartbeat-Before': 'tomorrow',
|
||||
})
|
||||
self.api_client.session.send = mock.Mock()
|
||||
self.api_client.session.send.return_value = response
|
||||
self.api_client.session.request = mock.Mock()
|
||||
self.api_client.session.request.return_value = response
|
||||
|
||||
self.assertRaises(errors.HeartbeatError,
|
||||
self.api_client.heartbeat,
|
||||
|
Loading…
x
Reference in New Issue
Block a user