Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tp2000 1640 new ref doc data importer #1370

Merged
merged 13 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions common/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import json
import os
from unittest import mock
Expand All @@ -11,6 +12,7 @@
from common.tests import models
from common.tests.util import Dates
from common.tests.util import wrap_numbers_over_max_digits
from common.util import TaricDateRange
from common.validators import UpdateType
from geo_areas.models import GeographicalArea
from geo_areas.models import GeographicalAreaDescription
Expand Down Expand Up @@ -582,3 +584,47 @@ def test_make_real_edit_create_delete():
# since the FK to geo area on description has on_delete=models.CASCADE this will delete the description as well
assert deleted_geo_area == None
assert workbasket.tracked_models.count() == 0


@pytest.mark.parametrize(
"date_range,compared_date_range,expected",
(
(
TaricDateRange(datetime.date(2020, 1, 1), datetime.date(2020, 1, 2)),
TaricDateRange(datetime.date(2020, 1, 1), datetime.date(2020, 1, 2)),
True,
),
(
TaricDateRange(datetime.date(2020, 1, 1), datetime.date(2020, 1, 2)),
TaricDateRange(datetime.date(2020, 1, 1), datetime.date(2020, 1, 1)),
True,
),
(
TaricDateRange(datetime.date(2020, 1, 1), datetime.date(2020, 1, 1)),
TaricDateRange(datetime.date(2020, 1, 1), datetime.date(2020, 1, 2)),
False,
),
(
TaricDateRange(datetime.date(2020, 1, 1)),
TaricDateRange(datetime.date(2020, 1, 1), datetime.date(2020, 1, 2)),
True,
),
(
TaricDateRange(datetime.date(2020, 1, 1), datetime.date(2020, 1, 1)),
TaricDateRange(datetime.date(2020, 1, 1)),
False,
),
(
TaricDateRange(datetime.date(2020, 1, 1)),
TaricDateRange(datetime.date(2020, 1, 1)),
True,
),
(
TaricDateRange(datetime.date(2020, 1, 2)),
TaricDateRange(datetime.date(2020, 1, 1)),
False,
),
),
)
def test_contains(date_range, compared_date_range, expected):
assert date_range.contains(compared_date_range) == expected
8 changes: 7 additions & 1 deletion common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ def contains(self, compared_date_range: TaricDateRange):
bool: True if the date range is fully contained within a provided date range, else False.
"""
lower_contained = self.lower <= compared_date_range.lower
upper_contained = self.upper_inf or self.upper >= compared_date_range.upper
if compared_date_range.upper_inf:
if self.upper_inf:
upper_contained = True
else:
upper_contained = False
else:
upper_contained = self.upper_inf or self.upper >= compared_date_range.upper

return lower_contained and upper_contained

Expand Down
Loading
Loading