def test_send_total_notifications_sent_for_day_stats_stats_creates_correct_call(mocker, client): send_stats = mocker.patch('app.performance_platform.total_sent_notifications.performance_platform_client.send_stats_to_performance_platform') # noqa send_total_notifications_sent_for_day_stats( start_time=datetime(2016, 10, 15, 23, 0, 0), notification_type='sms', count=142 ) assert send_stats.call_count == 1 request_args = send_stats.call_args[0][0] assert request_args['dataType'] == 'notifications' assert request_args['service'] == 'govuk-notify' assert request_args['period'] == 'day' assert request_args['channel'] == 'sms' assert request_args['_timestamp'] == '2016-10-16T00:00:00' assert request_args['count'] == 142 expected_base64_id = 'MjAxNi0xMC0xNlQwMDowMDowMGdvdnVrLW5vdGlmeXNtc25vdGlmaWNhdGlvbnNkYXk=' assert request_args['_id'] == expected_base64_id
def send_total_sent_notifications_to_performance_platform(day): """ :day a UTC datetime """ count_dict = total_sent_notifications.get_total_sent_notifications_for_day(day) email_sent_count = count_dict.get('email').get('count') sms_sent_count = count_dict.get('sms').get('count') letter_sent_count = count_dict.get('letter').get('count') start_date = count_dict.get('start_date') current_app.logger.info( "Attempting to update Performance Platform for {} with {} emails, {} text messages and {} letters" .format(start_date, email_sent_count, sms_sent_count, letter_sent_count) ) total_sent_notifications.send_total_notifications_sent_for_day_stats( start_date, 'sms', sms_sent_count ) total_sent_notifications.send_total_notifications_sent_for_day_stats( start_date, 'email', email_sent_count ) total_sent_notifications.send_total_notifications_sent_for_day_stats( start_date, 'letter', letter_sent_count )
def send_total_sent_notifications_to_performance_platform(bst_date): count_dict = total_sent_notifications.get_total_sent_notifications_for_day(bst_date) start_time = get_london_midnight_in_utc(bst_date) email_sent_count = count_dict['email'] sms_sent_count = count_dict['sms'] letter_sent_count = count_dict['letter'] current_app.logger.info( "Attempting to update Performance Platform for {} with {} emails, {} text messages and {} letters" .format(bst_date, email_sent_count, sms_sent_count, letter_sent_count) ) total_sent_notifications.send_total_notifications_sent_for_day_stats( start_time, 'sms', sms_sent_count ) total_sent_notifications.send_total_notifications_sent_for_day_stats( start_time, 'email', email_sent_count ) total_sent_notifications.send_total_notifications_sent_for_day_stats( start_time, 'letter', letter_sent_count )
def test_send_total_notifications_sent_for_day_stats_stats_creates_correct_call( mocker, client): send_stats = mocker.patch( "app.performance_platform.total_sent_notifications.performance_platform_client.send_stats_to_performance_platform" ) # noqa send_total_notifications_sent_for_day_stats(start_time=datetime( 2016, 10, 16, 4, 0, 0), notification_type="sms", count=142) assert send_stats.call_count == 1 request_args = send_stats.call_args[0][0] assert request_args["dataType"] == "notifications" assert request_args["service"] == "govuk-notify" assert request_args["period"] == "day" assert request_args["channel"] == "sms" assert request_args["_timestamp"] == "2016-10-16T00:00:00" assert request_args["count"] == 142 expected_base64_id = "MjAxNi0xMC0xNlQwMDowMDowMGdvdnVrLW5vdGlmeXNtc25vdGlmaWNhdGlvbnNkYXk=" assert request_args["_id"] == expected_base64_id
def send_total_sent_notifications_to_performance_platform(bst_date): count_dict = total_sent_notifications.get_total_sent_notifications_for_day( bst_date) start_time = get_local_timezone_midnight_in_utc(bst_date).strftime( "%Y-%m-%d") email_sent_count = count_dict["email"] sms_sent_count = count_dict["sms"] letter_sent_count = count_dict["letter"] current_app.logger.info( "Attempting to update Performance Platform for {} with {} emails, {} text messages and {} letters" .format(bst_date, email_sent_count, sms_sent_count, letter_sent_count)) total_sent_notifications.send_total_notifications_sent_for_day_stats( start_time, "sms", sms_sent_count) total_sent_notifications.send_total_notifications_sent_for_day_stats( start_time, "email", email_sent_count) total_sent_notifications.send_total_notifications_sent_for_day_stats( start_time, "letter", letter_sent_count)