Esempio n. 1
0
    def test_given_data_when_get_global_report_then_report_returned(
            self, get_global_data_mock, get_territorial_unit_report_mock):
        ccaa1 = "Melilla"
        ccaa2 = "Andalucia"
        data_header = "data_header"
        today_data = {ccaa1: MagicMock(), ccaa2: MagicMock()}
        yesterday_data = {ccaa1: MagicMock(), ccaa2: MagicMock()}
        accumulated_today = {ccaa1: MagicMock(), ccaa2: MagicMock()}

        global_today_data = MagicMock()
        global_yesterday_data = MagicMock()
        global_accumulated_data = MagicMock()
        get_global_data_mock.side_effect = [
            global_today_data, global_yesterday_data, global_accumulated_data
        ]

        result = get_global_report(data_header, today_data, yesterday_data,
                                   accumulated_today)

        self.assertEqual(get_territorial_unit_report_mock.return_value, result)

        get_territorial_unit_report_mock.assert_called_once_with(
            "🇪🇸 España", data_header, global_today_data, global_yesterday_data,
            global_accumulated_data)
        get_global_data_mock.assert_has_calls(
            [call(today_data),
             call(yesterday_data),
             call(accumulated_today)])
Esempio n. 2
0
def publish_report(today, yesterday):

    today_data = influx.get_all_stats_group_by_day(today)
    yesterday_data = influx.get_all_stats_group_by_day(yesterday)
    accumulated_today = influx.get_all_stats_accumulated_until_day(today)
    date_header = get_date_header(today, yesterday)

    spain_report = get_global_report(date_header, today_data, yesterday_data,
                                     accumulated_today)
    graph_url = get_graph_url(today - timedelta(31), today)
    last_id = twitter.publish_tweet_with_media(spain_report, graph_url)

    tweets = get_report_by_ccaa(date_header, today_data, yesterday_data,
                                accumulated_today)
    last_id = twitter.publish_tweets(tweets, last_id)
    twitter.publish_tweet(get_final_tweet(), last_id)

    logging.info("Tweets published correctly!")
Esempio n. 3
0
def main():
    date = datetime.now()

    today_data = delete_pcrs24h(influx.get_all_stats_group_by_week(date))
    last_week_data = delete_pcrs24h(
        influx.get_all_stats_group_by_week(date - timedelta(7)))
    accumulated_today = delete_pcrs24h(
        influx.get_all_stats_accumulated_until_day(date))
    date_header = get_date_header(date)

    spain_report = get_global_report(date_header, today_data, last_week_data,
                                     accumulated_today)
    graph_url = get_graph_url(additional_vars={"group_by": "1w,4d"})
    last_id = twitter.publish_tweet_with_media(spain_report, graph_url)

    tweets = get_report_by_ccaa(date_header, today_data, last_week_data,
                                accumulated_today)
    last_id = twitter.publish_tweets(tweets, last_id)
    twitter.publish_tweet(get_final_tweet(), last_id)