From 55e555259bfe50627a15c1688c4f25c197de3002 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Fri, 13 Dec 2024 14:39:26 +0100 Subject: [PATCH] Fix: Make cpe_last_modified of CPE matches optional --- pontos/nvd/models/cpe_match_string.py | 4 ++-- tests/nvd/models/test_cpe_match.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pontos/nvd/models/cpe_match_string.py b/pontos/nvd/models/cpe_match_string.py index b0b1b935f..4aa33dddc 100644 --- a/pontos/nvd/models/cpe_match_string.py +++ b/pontos/nvd/models/cpe_match_string.py @@ -38,7 +38,7 @@ class CPEMatchString(Model): version_end_including: Optional end of the matching version range, including the given version version_end_excluding: Optional end of the matching version range, excluding the given version status: Status of the CPE match - cpe_last_modified: The date the CPEs list of the match was last modified + cpe_last_modified: Optional date the CPEs list of the match was last modified created: Creation date of the CPE last_modified: Last modification date of the CPE matches: List of CPEs matching the criteria string and the optional range limits @@ -47,9 +47,9 @@ class CPEMatchString(Model): match_criteria_id: UUID criteria: str status: str - cpe_last_modified: datetime created: datetime last_modified: datetime + cpe_last_modified: Optional[datetime] = None matches: List[CPEMatch] = field(default_factory=list) version_start_including: Optional[str] = None version_start_excluding: Optional[str] = None diff --git a/tests/nvd/models/test_cpe_match.py b/tests/nvd/models/test_cpe_match.py index c583a524a..6a1812c8f 100644 --- a/tests/nvd/models/test_cpe_match.py +++ b/tests/nvd/models/test_cpe_match.py @@ -22,6 +22,7 @@ def test_required_only(self): data = get_cpe_match_data() data.__delitem__("matches") data.__delitem__("version_end_including") + data.__delitem__("cpe_last_modified") cpe_match_string = CPEMatchString.from_dict(data) @@ -37,10 +38,6 @@ def test_required_only(self): "Active", cpe_match_string.status, ) - self.assertEqual( - datetime(2019, 7, 22, 16, 37, 38, 133000, tzinfo=timezone.utc), - cpe_match_string.cpe_last_modified, - ) self.assertEqual( datetime(2019, 6, 17, 9, 16, 33, 960000, tzinfo=timezone.utc), cpe_match_string.created, @@ -52,11 +49,21 @@ def test_required_only(self): self.assertEqual([], cpe_match_string.matches) + self.assertIsNone(cpe_match_string.cpe_last_modified) self.assertIsNone(cpe_match_string.version_start_excluding) self.assertIsNone(cpe_match_string.version_end_excluding) self.assertIsNone(cpe_match_string.version_start_including) self.assertIsNone(cpe_match_string.version_end_including) + def test_cpe_last_modified(self): + data = get_cpe_match_data() + cpe_match_string = CPEMatchString.from_dict(data) + + self.assertEqual( + datetime(2019, 7, 22, 16, 37, 38, 133000, tzinfo=timezone.utc), + cpe_match_string.cpe_last_modified, + ) + def test_matches(self): """ Test the matches list of a CPEMatchString