def test_request_risk_api_without_proxy(self, requests_mock): get_mock = mock.Mock(return_value=mock.MagicMock(status_code=200)) requests_mock.get = get_mock bridge = RiskIndicatorBridge(self.config) bridge.request(bridge.indicators_host + "some-path/") get_mock.assert_called_once_with(bridge.indicators_host + "some-path/", timeout=bridge.request_timeout)
def test_request_tender_api_with_proxy(self, requests_mock): get_mock = mock.Mock(return_value=mock.MagicMock(status_code=200)) requests_mock.get = get_mock new_config = deepcopy(self.config) new_config["main"]["indicators_proxy"] = "http://127.0.0.1:8080" bridge = RiskIndicatorBridge(new_config) bridge.request(bridge.monitors_host + "some-path/") get_mock.assert_called_once_with( bridge.monitors_host + "some-path/", timeout=bridge.request_timeout, )
def test_request_exception(self, requests_mock): requests_mock.get.side_effect = Exception("Shit happens") bridge = RiskIndicatorBridge(self.config) bridge.request_retries = 2 try: bridge.request("http://localhost") except bridge.TerminateExecutionException as e: print(str(e)) else: raise AssertionError("TerminateExecutionException expected") self.assertEqual(len(requests_mock.get.call_args_list), 2) requests_mock.get.assert_called_with('http://localhost', timeout=bridge.request_timeout)
def test_request_json_exception(self, requests_mock): requests_mock.get.return_value = requests.Response() requests_mock.get.return_value.status_code = 200 bridge = RiskIndicatorBridge(self.config) bridge.request_retries = 2 try: bridge.request("http://localhost") except bridge.TerminateExecutionException as e: print(str(e)) else: raise AssertionError("TerminateExecutionException expected") self.assertEqual(len(requests_mock.get.call_args_list), 2) requests_mock.get.assert_called_with('http://localhost', timeout=bridge.request_timeout)