def test_generate_token_exception(self): mock_requests = patch(TARGET).start() mock_requests.post = MagicMock(side_effect=Exception()) with self.assertRaises(exceptions.ApiError): Auth('http://localhost', 'test', '123')
def test_generate_token_error(self): mock_requests = patch(TARGET).start() response_mock = MagicMock(return_value={'message': 'Error'}) mock_requests.post.return_value = MagicMock(json=response_mock, status_code=500) with self.assertRaises(exceptions.ApiError): Auth('http://localhost', 'test', '123')
def test_generate_token_unauthorized(self): mock_requests = patch(self.TARGET).start() response_mock = MagicMock(return_value={'message': 'Error'}) mock_requests.return_value.request.return_value = MagicMock( json=response_mock, status_code=401) with self.assertRaises(exceptions.Unauthorized): Auth('http://localhost', 'test', '123')
def test_generate_token(self): mock_requests = patch(TARGET).start() token_data = { 'token': 'token123', 'expires_at': '2018-04-12T05:51:58.144271Z', } response_mock = MagicMock(return_value=token_data) mock_requests.post.return_value = MagicMock(json=response_mock, status_code=200) Auth('http://localhost', 'test', '123') data = {'username': '******', 'password': '******'} headers = {'Content-Type': 'application/json'} mock_requests.post.assert_called_once_with('http://localhost/v2/auth/', data=json.dumps(data), headers=headers)
import time import os from globomap_loader_api_client.auth import Auth from globomap_loader_api_client.update import Update GMAP_LOADER_API_PORT = os.getenv('GMAP_LOADER_API_PORT', '7010') auth_inst = Auth(api_url='http://localhost:{}'.format(GMAP_LOADER_API_PORT), username='******', password='******') update = Update(auth=auth_inst, driver_name='talk_globomap') data = { "action": "CLEAR", "collection": "vip", "element": [[{ "field": "timestamp", "operator": ">", "value": 1 }]], "type": "collections" } res = update.post(data) data = { "action": "CLEAR", "collection": "vip_vm", "element": [[{ "field": "timestamp", "operator": ">",