diff --git a/common/tests/test_models.py b/common/tests/test_models.py index 74a333b99..61d43f3ac 100644 --- a/common/tests/test_models.py +++ b/common/tests/test_models.py @@ -81,6 +81,25 @@ def test_as_at_today(model1_with_history): } +def test_as_at_today_and_beyond(date_ranges, validity_factory): + """Ensure only records active at the current date and future records are + fetched.""" + outdated_record = {validity_factory.create(valid_between=date_ranges.earlier).pk} + + active_and_future_records = { + validity_factory.create(valid_between=date_ranges.normal).pk, + validity_factory.create(valid_between=date_ranges.later).pk, + } + + test_model = validity_factory._meta.get_model_class() + queryset = set( + test_model.objects.as_at_today_and_beyond().values_list("pk", flat=True), + ) + + assert queryset != outdated_record + assert queryset == active_and_future_records + + def test_get_version_raises_error(): """Ensure that trying to get a specific version raises an error if no identifiers given.""" diff --git a/geo_areas/forms.py b/geo_areas/forms.py index c629c0442..f59241703 100644 --- a/geo_areas/forms.py +++ b/geo_areas/forms.py @@ -85,7 +85,7 @@ def __init__(self, *args, **kwargs): GeographicalArea.objects.filter(area_code=AreaCode.COUNTRY) .current() .with_latest_description() - .as_at_today() + .as_at_today_and_beyond() .order_by("description") ) self.fields[ @@ -107,7 +107,7 @@ def __init__(self, *args, **kwargs): GeographicalArea.objects.filter(area_code=AreaCode.REGION) .current() .with_latest_description() - .as_at_today() + .as_at_today_and_beyond() .order_by("description") ) self.fields[ @@ -196,7 +196,7 @@ def __init__(self, *args, **kwargs): GeographicalArea.objects.filter(area_code=AreaCode.GROUP) .current() .with_latest_description() - .as_at_today() + .as_at_today_and_beyond() .order_by("description") ) self.fields[ @@ -542,7 +542,7 @@ def __init__(self, *args, **kwargs): .exclude(pk__in=current_memberships) .current() .with_latest_description() - .as_at_today() + .as_at_today_and_beyond() .order_by("description") ) self.fields[ @@ -631,7 +631,7 @@ def __init__(self, *args, **kwargs): ) .current() .with_latest_description() - .as_at_today() + .as_at_today_and_beyond() .order_by("description") ) self.fields[ @@ -768,7 +768,7 @@ def __init__(self, *args, **kwargs): self.fields["erga_omnes_exclusion"].queryset = ( GeographicalArea.objects.current() .with_latest_description() - .as_at_today() + .as_at_today_and_beyond() .order_by("description") ) self.fields[ @@ -803,7 +803,7 @@ def __init__(self, *args, **kwargs): GeographicalArea.objects.current() .with_latest_description() .filter(area_code=AreaCode.GROUP) - .as_at_today() + .as_at_today_and_beyond() .order_by("description") ) # descriptions__description" should make this implicitly distinct() @@ -830,7 +830,7 @@ def __init__(self, *args, **kwargs): self.fields["geo_group_exclusion"].queryset = ( GeographicalArea.objects.current() .with_latest_description() - .as_at_today() + .as_at_today_and_beyond() .order_by("description") ) self.fields[ @@ -879,7 +879,7 @@ def __init__(self, *args, **kwargs): GeographicalArea.objects.current() .with_latest_description() .exclude(area_code=AreaCode.GROUP) - .as_at_today() + .as_at_today_and_beyond() .order_by("description") ) diff --git a/quotas/forms.py b/quotas/forms.py index 7f491ad26..3c5d3dbfb 100644 --- a/quotas/forms.py +++ b/quotas/forms.py @@ -90,7 +90,7 @@ def __init__(self, *args, **kwargs): self.fields["exclusion"].queryset = ( GeographicalArea.objects.current() .with_latest_description() - .as_at_today() + .as_at_today_and_beyond() .order_by("description") ) self.fields[ @@ -258,7 +258,7 @@ def init_fields(self): self.fields["geographical_area"].queryset = ( GeographicalArea.objects.current() .with_latest_description() - .as_at_today() + .as_at_today_and_beyond() .order_by("description") ) self.fields[