Skip to content

Commit

Permalink
Merge branch 'master' into TP2000-1577--packaging-queue-race-condition
Browse files Browse the repository at this point in the history
  • Loading branch information
dalecannon committed Jan 15, 2025
2 parents f1185e0 + bafa306 commit 5849bc4
Show file tree
Hide file tree
Showing 37 changed files with 2,510 additions and 198 deletions.
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

0 comments on commit 5849bc4

Please sign in to comment.