# Path: notifications_utils/letter_timings.py
# def get_letter_timings(upload_time, postage):
# 
#     LetterTimings = namedtuple(
#         'LetterTimings',
#         'printed_by, is_printed, earliest_delivery, latest_delivery'
#     )
# 
#     # shift anything after 5:30pm to the next day
#     processing_day = utc_string_to_aware_gmt_datetime(upload_time) + timedelta(hours=6, minutes=30)
#     print_day = get_next_dvla_working_day(processing_day)
# 
#     earliest_delivery, latest_delivery = get_earliest_and_latest_delivery(print_day, postage)
# 
#     # print deadline is 3pm BST
#     printed_by = set_gmt_hour(print_day, hour=15)
#     now = datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(pytz.timezone('Europe/London'))
# 
#     return LetterTimings(
#         printed_by=printed_by,
#         is_printed=(now > printed_by),
#         earliest_delivery=set_gmt_hour(earliest_delivery, hour=16),
#         latest_delivery=set_gmt_hour(latest_delivery, hour=16),
#     )
# 
# def letter_can_be_cancelled(notification_status, notification_created_at):
#     '''
#     If letter does not have status of created or pending-virus-check
#         => can't be cancelled (it has already been processed)
# 
#     If it's after 5.30pm local time and the notification was created today before 5.30pm local time
#         => can't be cancelled (it will already be zipped up to be sent)
#     '''
#     if notification_status not in ('created', 'pending-virus-check'):
#         return False
# 
#     if too_late_to_cancel_letter(notification_created_at):
#         return False
#     return True


from datetime import datetime
from freezegun import freeze_time
from notifications_utils.letter_timings import (
    get_letter_timings,
    letter_can_be_cancelled,
)
import pytest
import pytz
            'Tuesday 2020-04-14 15:00',
            False,
            'Wednesday 2020-04-15 16:00',
            'Thursday 2020-04-16 16:00',
            'Friday 2020-04-17 16:00',
            'Saturday 2020-04-18 16:00',
            'Tuesday 2020-04-21 16:00',
            'Tuesday 2020-04-21 16:00',
            'Thursday 2020-04-23 16:00',
        ),
    ]
)
def test_get_estimated_delivery_date_for_letter(
    upload_time,
    expected_print_time,
    is_printed,
    first_class,
    expected_earliest_second_class,
    expected_latest_second_class,
    expected_earliest_europe,
    expected_latest_europe,
    expected_earliest_rest_of_world,
    expected_latest_rest_of_world,
):
    # remove the day string from the upload_time, which is purely informational

    format_dt = lambda x: x.astimezone(pytz.timezone('Europe/London')).strftime('%A %Y-%m-%d %H:%M')  # noqa

    upload_time = upload_time.split(' ', 1)[1]


# Path: notifications_utils/letter_timings.py
# def get_letter_timings(upload_time, postage):
# 
#     LetterTimings = namedtuple(
#         'LetterTimings',
#         'printed_by, is_printed, earliest_delivery, latest_delivery'
#     )
# 
#     # shift anything after 5:30pm to the next day
#     processing_day = utc_string_to_aware_gmt_datetime(upload_time) + timedelta(hours=6, minutes=30)
#     print_day = get_next_dvla_working_day(processing_day)
# 
#     earliest_delivery, latest_delivery = get_earliest_and_latest_delivery(print_day, postage)
# 
#     # print deadline is 3pm BST
#     printed_by = set_gmt_hour(print_day, hour=15)
#     now = datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(pytz.timezone('Europe/London'))
# 
#     return LetterTimings(
#         printed_by=printed_by,
#         is_printed=(now > printed_by),
#         earliest_delivery=set_gmt_hour(earliest_delivery, hour=16),
#         latest_delivery=set_gmt_hour(latest_delivery, hour=16),
#     )
# 
# def letter_can_be_cancelled(notification_status, notification_created_at):
#     '''
#     If letter does not have status of created or pending-virus-check
#         => can't be cancelled (it has already been processed)
# 
#     If it's after 5.30pm local time and the notification was created today before 5.30pm local time
#         => can't be cancelled (it will already be zipped up to be sent)
#     '''
#     if notification_status not in ('created', 'pending-virus-check'):
#         return False
# 
#     if too_late_to_cancel_letter(notification_created_at):
#         return False
#     return True


# Path: tests/test_letter_timings.py
from datetime import datetime
from freezegun import freeze_time
from notifications_utils.letter_timings import (
    get_letter_timings,
    letter_can_be_cancelled,
)
import pytest
import pytz

            'Tuesday 2020-04-14 15:00',
            False,
            'Wednesday 2020-04-15 16:00',
            'Thursday 2020-04-16 16:00',
            'Friday 2020-04-17 16:00',
            'Saturday 2020-04-18 16:00',
            'Tuesday 2020-04-21 16:00',
            'Tuesday 2020-04-21 16:00',
            'Thursday 2020-04-23 16:00',
        ),
    ]
)
def test_get_estimated_delivery_date_for_letter(
    upload_time,
    expected_print_time,
    is_printed,
    first_class,
    expected_earliest_second_class,
    expected_latest_second_class,
    expected_earliest_europe,
    expected_latest_europe,
    expected_earliest_rest_of_world,
    expected_latest_rest_of_world,
):
    # remove the day string from the upload_time, which is purely informational

    format_dt = lambda x: x.astimezone(pytz.timezone('Europe/London')).strftime('%A %Y-%m-%d %H:%M')  # noqa

    upload_time = upload_time.split(' ', 1)[1]


    timings = get_letter_timings(upload_time, postage='second')