def test_get_total_sent_notifications_yesterday_returns_expected_totals_dict(
        notify_db, notify_db_session, sample_template):
    notification_history = partial(create_notification_history,
                                   notify_db,
                                   notify_db_session,
                                   sample_template,
                                   status='delivered')

    notification_history(notification_type='email')
    notification_history(notification_type='sms')

    # Create some notifications for the day before
    yesterday = datetime(2016, 1, 10, 12, 30, 0, 0)  # 2016-01-10 11:30pm AEDT
    ereyesterday = datetime(2016, 1, 9, 12, 30, 0,
                            0)  # 2016-01-09 11:30pm AEDT
    with freeze_time(yesterday):
        notification_history(notification_type='letter')
        notification_history(notification_type='sms')
        notification_history(notification_type='sms')
        notification_history(notification_type='email')
        notification_history(notification_type='email')
        notification_history(notification_type='email')

    total_count_dict = get_total_sent_notifications_for_day(yesterday)

    assert total_count_dict == {
        "start_date": get_midnight_for_day_before(datetime.utcnow()),
        "email": {
            "count": 3
        },
        "sms": {
            "count": 2
        },
        "letter": {
            "count": 1
        }
    }

    another_day = get_total_sent_notifications_for_day(ereyesterday)

    assert another_day == {
        'email': {
            'count': 0
        },
        'letter': {
            'count': 0
        },
        'sms': {
            'count': 0
        },
        'start_date': datetime(2016, 1, 8, 13, 00),
    }
Exemplo n.º 2
0
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 test_get_total_sent_notifications_yesterday_returns_expected_totals_dict(sample_service):
    sms = create_template(sample_service, template_type='sms')
    email = create_template(sample_service, template_type='email')
    letter = create_template(sample_service, template_type='letter')

    today = date(2018, 6, 10)
    yesterday = date(2018, 6, 9)

    # todays is excluded
    create_ft_notification_status(bst_date=today, template=sms)
    create_ft_notification_status(bst_date=today, template=email)
    create_ft_notification_status(bst_date=today, template=letter)

    # yesterdays is included
    create_ft_notification_status(bst_date=yesterday, template=sms, count=2)
    create_ft_notification_status(bst_date=yesterday, template=email, count=3)
    create_ft_notification_status(bst_date=yesterday, template=letter, count=1)

    total_count_dict = get_total_sent_notifications_for_day(yesterday)

    assert total_count_dict == {
        "email": 3,
        "sms": 2,
        "letter": 1
    }
Exemplo n.º 4
0
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
    )
Exemplo n.º 5
0
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)