def test_send_total_sent_notifications_to_performance_platform_calls_with_correct_totals( notify_db_session, sample_template, sample_email_template, mocker): perf_mock = mocker.patch( 'app.celery.nightly_tasks.total_sent_notifications.send_total_notifications_sent_for_day_stats' ) # noqa today = date(2016, 6, 11) create_ft_notification_status(utc_date=today, template=sample_template) create_ft_notification_status(utc_date=today, template=sample_email_template) # Create some notifications for the day before yesterday = date(2016, 6, 10) create_ft_notification_status(utc_date=yesterday, template=sample_template, count=2) create_ft_notification_status(utc_date=yesterday, template=sample_email_template, count=3) with patch.object(PerformancePlatformClient, 'active', new_callable=PropertyMock) as mock_active: mock_active.return_value = True send_total_sent_notifications_to_performance_platform(yesterday) perf_mock.assert_has_calls([ call("2016-06-10", 'sms', 2), call("2016-06-10", 'email', 3), call("2016-06-10", 'letter', 0) ])
def backfill_performance_platform_totals(start_date, end_date): """ Send historical total messages sent to Performance Platform. WARNING: This does not overwrite existing data. You need to delete the existing data or Performance Platform will double-count. """ delta = end_date - start_date print('Sending total messages sent for all days between {} and {}'.format( start_date, end_date)) for i in range(delta.days + 1): process_date = start_date + timedelta(days=i) print('Sending total messages sent for {}'.format( process_date.isoformat())) send_total_sent_notifications_to_performance_platform(process_date)