diff --git a/dev_requirements/requirements-tests.in b/dev_requirements/requirements-tests.in index cf01731..166f858 100644 --- a/dev_requirements/requirements-tests.in +++ b/dev_requirements/requirements-tests.in @@ -4,3 +4,4 @@ pytest-datafiles pytest-mock pytest-asyncio==0.22.0 #pinned for bugs/breaking changes in 0.23.x aioresponses +freezegun diff --git a/dev_requirements/requirements-tests.txt b/dev_requirements/requirements-tests.txt index 9bb2ab5..1929ca2 100644 --- a/dev_requirements/requirements-tests.txt +++ b/dev_requirements/requirements-tests.txt @@ -12,6 +12,10 @@ aiosignal==1.3.1 # via aiohttp attrs==23.2.0 # via aiohttp +colorama==0.4.6 + # via pytest +freezegun==1.5.1 + # via -r dev_requirements/requirements-tests.in frozenlist==1.4.1 # via # aiohttp @@ -40,5 +44,9 @@ pytest-datafiles==3.0.0 # via -r dev_requirements/requirements-tests.in pytest-mock==3.14.0 # via -r dev_requirements/requirements-tests.in +python-dateutil==2.9.0.post0 + # via freezegun +six==1.16.0 + # via python-dateutil yarl==1.9.4 # via aiohttp diff --git a/requirements.txt b/requirements.txt index 2fbe314..4e84e87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,8 +4,6 @@ # # pip-compile pyproject.toml # -aiodns==3.2.0 - # via aiohttp aiohttp[speedups]==3.9.5 # via # aiohttp-requests @@ -22,8 +20,6 @@ beautifulsoup4==4.12.3 # via edi_energy_scraper (pyproject.toml) brotli==1.1.0 # via aiohttp -cffi==1.16.0 - # via pycares coworker==2.0.1 # via aiohttp-requests frozenlist==1.4.1 @@ -44,10 +40,6 @@ multidict==6.0.5 # yarl packaging==24.0 # via marshmallow -pycares==4.4.0 - # via aiodns -pycparser==2.22 - # via cffi pypdf==4.2.0 # via edi_energy_scraper (pyproject.toml) pytz==2024.1 diff --git a/src/edi_energy_scraper/__init__.py b/src/edi_energy_scraper/__init__.py index 4f6e07b..541321c 100644 --- a/src/edi_energy_scraper/__init__.py +++ b/src/edi_energy_scraper/__init__.py @@ -459,7 +459,12 @@ def get_edifact_format_version_range_from_filename(path: Path) -> List[EdifactFo is_format_version_end_greater_than_next_format_version = format_version_end > next_format_version if is_format_version_end_greater_than_next_format_version: - format_version_end = next_format_version + # files which have been published earlier and not been replaced yet are used until the next format version + if format_version_start < next_format_version: + format_version_end = next_format_version + # new documents which are not valdi yet are used for the future format version + else: + format_version_end = format_version_start format_versions = [efv.value for efv in EdifactFormatVersion] diff --git a/unittests/test_edienergyscraper.py b/unittests/test_edienergyscraper.py index a97ba05..187f6c1 100644 --- a/unittests/test_edienergyscraper.py +++ b/unittests/test_edienergyscraper.py @@ -4,6 +4,7 @@ import pytest from aioresponses import aioresponses from bs4 import BeautifulSoup +from freezegun import freeze_time from maus.edifact import EdifactFormatVersion from edi_energy_scraper import ( @@ -505,6 +506,7 @@ def test_get_edifact_version_and_formats(self, input_filename: str, expected_res assert actual == expected_result + @freeze_time("2024-06-25") @pytest.mark.parametrize( "input_filename, expected_result", [ @@ -527,6 +529,16 @@ def test_get_edifact_version_and_formats(self, input_filename: str, expected_res [EdifactFormatVersion.FV2310, EdifactFormatVersion.FV2404], id="valid for two format versions", ), + pytest.param( + "IFTSTAMIG2.0e_20280930_20231001.pdf", + [EdifactFormatVersion.FV2310, EdifactFormatVersion.FV2404, EdifactFormatVersion.FV2410], + id="valid in future, starting in past", + ), + pytest.param( + "IFTSTAMIG2.0e_20280930_20250404.pdf", + [EdifactFormatVersion.FV2504], + id="starting in future", + ), ], ) def test_get_edifact_format_version_range(self, input_filename: str, expected_result: List[EdifactFormatVersion]):