# 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

    assert format_dt(first_class_timings.printed_by) == expected_print_time
    assert first_class_timings.is_printed == is_printed
    assert format_dt(first_class_timings.earliest_delivery) == first_class
    assert format_dt(first_class_timings.latest_delivery) == first_class

    europe_timings = get_letter_timings(upload_time, postage='europe')

    assert format_dt(europe_timings.printed_by) == expected_print_time
    assert europe_timings.is_printed == is_printed
    assert format_dt(europe_timings.earliest_delivery) == expected_earliest_europe
    assert format_dt(europe_timings.latest_delivery) == expected_latest_europe

    rest_of_world_timings = get_letter_timings(upload_time, postage='rest-of-world')

    assert format_dt(rest_of_world_timings.printed_by) == expected_print_time
    assert rest_of_world_timings.is_printed == is_printed
    assert format_dt(rest_of_world_timings.earliest_delivery) == expected_earliest_rest_of_world
    assert format_dt(rest_of_world_timings.latest_delivery) == expected_latest_rest_of_world


def test_letter_timings_only_accept_real_postage_values():
    with pytest.raises(KeyError):
        get_letter_timings(datetime.utcnow().isoformat(), postage='foo')


@pytest.mark.parametrize('status', ['sending', 'pending'])
def test_letter_cannot_be_cancelled_if_letter_status_is_not_created_or_pending_virus_check(status):
    notification_created_at = datetime.utcnow()


# 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


    assert format_dt(first_class_timings.printed_by) == expected_print_time
    assert first_class_timings.is_printed == is_printed
    assert format_dt(first_class_timings.earliest_delivery) == first_class
    assert format_dt(first_class_timings.latest_delivery) == first_class

    europe_timings = get_letter_timings(upload_time, postage='europe')

    assert format_dt(europe_timings.printed_by) == expected_print_time
    assert europe_timings.is_printed == is_printed
    assert format_dt(europe_timings.earliest_delivery) == expected_earliest_europe
    assert format_dt(europe_timings.latest_delivery) == expected_latest_europe

    rest_of_world_timings = get_letter_timings(upload_time, postage='rest-of-world')

    assert format_dt(rest_of_world_timings.printed_by) == expected_print_time
    assert rest_of_world_timings.is_printed == is_printed
    assert format_dt(rest_of_world_timings.earliest_delivery) == expected_earliest_rest_of_world
    assert format_dt(rest_of_world_timings.latest_delivery) == expected_latest_rest_of_world


def test_letter_timings_only_accept_real_postage_values():
    with pytest.raises(KeyError):
        get_letter_timings(datetime.utcnow().isoformat(), postage='foo')


@pytest.mark.parametrize('status', ['sending', 'pending'])
def test_letter_cannot_be_cancelled_if_letter_status_is_not_created_or_pending_virus_check(status):
    notification_created_at = datetime.utcnow()


    assert not letter_can_be_cancelled(status, notification_created_at)