def test_raises_original_error_if_not_404(self): data_api_client_mock = mock.Mock() data_api_client_mock.get_framework.side_effect = HTTPError(mock.Mock(status_code=400), 'Original exception') with pytest.raises(HTTPError) as original_exception: get_framework_or_500(data_api_client_mock, 'g-cloud-7') assert original_exception.value.message == 'Original exception' assert original_exception.value.status_code == 400
def test_aborts_with_500_if_framework_not_found(self, abort): data_api_client_mock = mock.Mock() data_api_client_mock.get_framework.side_effect = HTTPError(mock.Mock(status_code=404), 'Framework not found') abort.side_effect = CustomAbortException() with pytest.raises(CustomAbortException): get_framework_or_500(data_api_client_mock, 'g-cloud-7') assert abort.call_args_list == [ mock.call(500, 'Framework not found: g-cloud-7') ]
def test_calls_logger_if_provided(self, abort): data_api_client_mock = mock.Mock() logger_mock = mock.Mock() data_api_client_mock.get_framework.side_effect = HTTPError(mock.Mock(status_code=404), 'An error from the API') get_framework_or_500(data_api_client_mock, 'g-cloud-7', logger_mock) assert logger_mock.error.call_args_list == [ mock.call( 'Framework not found. Error: {error}, framework_slug: {framework_slug}', extra={'error': 'An error from the API (status: 404)', 'framework_slug': 'g-cloud-7'}, ) ]
def test_returns_framework(self): data_api_client_mock = mock.Mock() data_api_client_mock.get_framework.return_value = FrameworkStub( ).single_result_response() assert get_framework_or_500(data_api_client_mock, 'g-cloud-10')['slug'] == 'g-cloud-10'