Ejemplo n.º 1
0
    def test_given_no_data_and_another_error_when_main_then_twitter_dm_sent(
            self, influx_mock, datetime_mock, publish_report_mock,
            update_database_mock, subtract_days_ignoring_weekends_mock,
            twitter_mock):

        exception_text = "exception text"
        update_database_mock.side_effect = Exception(exception_text * 100)
        influx_mock.get_stat_group_by_day.return_value = {}

        main()

        update_database_mock.assert_called_once_with(
            datetime_mock.now.return_value)
        publish_report_mock.assert_not_called()
        datetime_mock.now.assert_called_once_with()
        subtract_days_ignoring_weekends_mock.assert_called_once_with(
            datetime_mock.now.return_value, 1)
        influx_mock.get_stat_group_by_day.assert_called_once_with(
            Measurement.PCRS, datetime_mock.now.return_value)
        twitter_mock.send_dm.assert_called_once_with(ANY)
        dm_text = twitter_mock.send_dm.call_args[0][0]
        self.assertEqual(280, len(dm_text))
        self.assertTrue(
            dm_text.startswith(
                f"There was an unhandled exception. Trace:\n\n{exception_text}"
            ))
Ejemplo n.º 2
0
    def test_given_data_when_main_then_update_and_publish_not_called(
            self, influx_mock, datetime_mock, publish_report_mock,
            update_database_mock, subtract_days_ignoring_weekends_mock):

        influx_mock.get_stat_group_by_day.return_value = {"Madrid": 1}

        main()

        update_database_mock.assert_not_called()
        publish_report_mock.assert_not_called()
        datetime_mock.now.assert_called_once_with()
        subtract_days_ignoring_weekends_mock.assert_called_once_with(
            datetime_mock.now.return_value, 1)
        influx_mock.get_stat_group_by_day.assert_called_once_with(
            Measurement.PCRS, datetime_mock.now.return_value)
Ejemplo n.º 3
0
    def test_given_no_data_and_http_error_when_main_then_no_exception_raised(
            self, influx_mock, datetime_mock, publish_report_mock,
            update_database_mock, subtract_days_ignoring_weekends_mock):

        update_database_mock.side_effect = HTTPError("http://google.com", 404,
                                                     MagicMock(), MagicMock(),
                                                     MagicMock())
        influx_mock.get_stat_group_by_day.return_value = {}

        main()

        update_database_mock.assert_called_once_with(
            datetime_mock.now.return_value)
        publish_report_mock.assert_not_called()
        datetime_mock.now.assert_called_once_with()
        subtract_days_ignoring_weekends_mock.assert_called_once_with(
            datetime_mock.now.return_value, 1)
        influx_mock.get_stat_group_by_day.assert_called_once_with(
            Measurement.PCRS, datetime_mock.now.return_value)