def test_report_indicator_should_raise_reporter_exception_if_reporter_exception(self): reporter = WebServiceReporter("url", "api_key") with patch('genweb.core.indicators.client.Client.update_indicator', side_effect=(None,)): with patch('genweb.core.indicators.reporter.WebServiceReporter._report_indicator_categories', side_effect=ReporterException): with self.assertRaises(ReporterException): reporter._report_indicator(Mock(), report_categories=True)
def test_report_indicator_should_not_update_categories_if_specified(self): reporter = WebServiceReporter("url", "api_key") mock_update_indicator = Mock() mock_report_categories = Mock() with patch('genweb.core.indicators.client.Client.update_indicator', side_effect=mock_update_indicator): with patch('genweb.core.indicators.reporter.WebServiceReporter._report_indicator_categories', side_effect=mock_report_categories): reporter._report_indicator(Mock(), report_categories=False) self.assertEqual(1, mock_update_indicator.call_count) self.assertEqual(0, mock_report_categories.call_count)
def test_report_indicator_should_raise_reporter_exception_if_calculator_exception(self): reporter = WebServiceReporter("url", "api_key") with patch('genweb.core.indicators.client.Client.update_indicator'): with patch('genweb.core.indicators.client.Client.update_category', side_effect=CalculatorException('Oh!')): with self.assertRaises(ReporterException) as context: reporter._report_indicator( Mock(categories={'c1': Mock(), '2': Mock()}), report_categories=True) self.assertEqual( "Error when calculating category (Oh!)", context.exception.message)