Exemplo n.º 1
0
def test_throws_value_error_given_end_datetime_but_no_start_datetime():
    end_datetime = datetime(year=2019, month=12, day=31, hour=0, minute=0, second=0, tzinfo=UTC)
    conversation_cutoff = timedelta(days=3)

    with pytest.raises(ValueError) as e:
        ReportingWindow(
            start_datetime=None, end_datetime=end_datetime, conversation_cutoff=conversation_cutoff
        )
    assert str(e.value) == "Start datetime must be provided if end datetime is provided"
Exemplo n.º 2
0
def test_returns_dates_list_when_today_time_is_bst():
    reporting_window = ReportingWindow(
        start_datetime=None, end_datetime=None, conversation_cutoff=timedelta(days=0)
    )

    actual_dates = reporting_window.get_dates()
    expected_dates = [datetime(year=2021, month=4, day=30, hour=0, minute=0, second=0, tzinfo=UTC)]

    assert actual_dates == expected_dates
Exemplo n.º 3
0
def test_returns_list_of_overflow_dates_depending_on_cutoff_when_start_and_end_datetime_are_none(
    cutoff_days, expected_overflow_dates
):
    reporting_window = ReportingWindow(
        start_datetime=None, end_datetime=None, conversation_cutoff=timedelta(days=cutoff_days)
    )

    actual_dates = reporting_window.get_overflow_dates()

    assert actual_dates == expected_overflow_dates
Exemplo n.º 4
0
def test_returns_dates_list_from_yesterday_midnight_minus_cutoff_when_datetimes_are_none(
    cutoff_days, expected_dates
):
    reporting_window = ReportingWindow(
        start_datetime=None, end_datetime=None, conversation_cutoff=timedelta(days=cutoff_days)
    )

    actual_dates = reporting_window.get_dates()

    assert actual_dates == expected_dates
Exemplo n.º 5
0
def test_throws_value_error_given_start_datetime_is_after_end_datetime():
    start_datetime = datetime(year=2019, month=12, day=2, hour=0, minute=0, second=0, tzinfo=UTC)
    end_datetime = datetime(year=2019, month=12, day=1, hour=0, minute=0, second=0, tzinfo=UTC)
    conversation_cutoff = timedelta(days=3)

    with pytest.raises(ValueError) as e:
        ReportingWindow(
            start_datetime=start_datetime,
            end_datetime=end_datetime,
            conversation_cutoff=conversation_cutoff,
        )
    assert str(e.value) == "Start datetime must be before end datetime"
Exemplo n.º 6
0
def test_returns_empty_list_given_cutoff_of_0():
    start_datetime = datetime(year=2022, month=1, day=12, hour=0, minute=0, second=0, tzinfo=UTC)
    end_datetime = datetime(year=2022, month=1, day=13, hour=0, minute=0, second=0, tzinfo=UTC)

    reporting_window = ReportingWindow(
        start_datetime, end_datetime, conversation_cutoff=timedelta(days=0)
    )

    expected_overflow_dates: List = []

    actual = reporting_window.get_overflow_dates()

    assert actual == expected_overflow_dates
Exemplo n.º 7
0
def test_get_overflow_dates_returns_list_of_datetimes_within_cutoff_period():
    start_datetime = datetime(year=2019, month=12, day=30, hour=0, minute=0, second=0, tzinfo=UTC)
    end_datetime = datetime(year=2019, month=12, day=31, hour=0, minute=0, second=0, tzinfo=UTC)
    conversation_cutoff = timedelta(days=3)

    reporting_window = ReportingWindow(start_datetime, end_datetime, conversation_cutoff)

    expected_overflow_dates = [
        datetime(year=2019, month=12, day=31, tzinfo=UTC),
        datetime(year=2020, month=1, day=1, tzinfo=UTC),
        datetime(year=2020, month=1, day=2, tzinfo=UTC),
    ]

    actual = reporting_window.get_overflow_dates()

    assert actual == expected_overflow_dates
Exemplo n.º 8
0
def test_throws_value_error_given_datetimes_that_are_not_midnight(start_hour, end_hour):
    start_datetime = datetime(
        year=2019, month=12, day=1, hour=start_hour, minute=0, second=0, tzinfo=UTC
    )
    end_datetime = datetime(
        year=2019, month=12, day=2, hour=end_hour, minute=0, second=0, tzinfo=UTC
    )
    conversation_cutoff = timedelta(days=3)

    with pytest.raises(ValueError) as e:
        ReportingWindow(
            start_datetime=start_datetime,
            end_datetime=end_datetime,
            conversation_cutoff=conversation_cutoff,
        )
    assert str(e.value) == "Datetime must be at midnight"
    def __init__(self, config: TransferClassifierConfig):
        s3 = boto3.resource("s3", endpoint_url=config.s3_endpoint_url)
        s3_manager = S3DataManager(s3)

        self._reporting_window = ReportingWindow(config.start_datetime,
                                                 config.end_datetime,
                                                 config.conversation_cutoff)

        self._config = config

        self._uris = TransferClassifierS3UriResolver(
            gp2gp_spine_bucket=config.input_spine_data_bucket,
            transfers_bucket=config.output_transfer_data_bucket,
            ods_metadata_bucket=config.input_ods_metadata_bucket,
        )

        self._io = TransferClassifierIO(s3_manager)
Exemplo n.º 10
0
def test_get_dates_returns_list_of_datetimes_within_reporting_window():
    start_datetime = datetime(year=2021, month=12, day=30, tzinfo=UTC)
    end_datetime = datetime(year=2022, month=1, day=3, tzinfo=UTC)
    conversation_cutoff = timedelta(days=14)

    reporting_window = ReportingWindow(start_datetime, end_datetime, conversation_cutoff)

    expected = [
        datetime(year=2021, month=12, day=30, tzinfo=UTC),
        datetime(year=2021, month=12, day=31, tzinfo=UTC),
        datetime(year=2022, month=1, day=1, tzinfo=UTC),
        datetime(year=2022, month=1, day=2, tzinfo=UTC),
    ]

    actual = reporting_window.get_dates()

    assert actual == expected