Skip to content

Commit 1a3f816

Browse files
committed
Ensure Debian test are passing
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent fd2c127 commit 1a3f816

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

vulnerabilities/importers/debian.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,15 @@ def _parse(self, pkg_name: str, records: Mapping[str, Any]) -> List[Advisory]:
131131
return advisories
132132

133133
def response_is_new(self):
134-
date_str = requests.head(self.config.debian_tracker_url).headers.get("last-modified")
134+
"""
135+
Return True if a request response is for new data likely changed or
136+
updated since we last checked.
137+
"""
138+
head = requests.head(self.config.debian_tracker_url)
139+
date_str = head.headers.get("last-modified")
135140
last_modified_date = dateparser.parse(date_str)
141+
print('last_modified_date:', type(last_modified_date), last_modified_date)
142+
print('self.config.last_run_date:', type(self.config.last_run_date), self.config.last_run_date)
136143
if self.config.last_run_date:
137144
return self.config.last_run_date < last_modified_date
138145

vulnerabilities/tests/test_debian.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
# for any legal advice.
2121
# VulnerableCode is a free software code scanning tool from nexB Inc. and others.
2222
# Visit https://github.com/nexB/vulnerablecode/ for support and download.
23+
2324
import json
2425
import os
26+
from dateutil import parser as dateparser
2527
from unittest.mock import patch
2628
from unittest.mock import MagicMock
2729

@@ -36,6 +38,7 @@
3638

3739

3840
class DebianImportTest(TestCase):
41+
3942
@classmethod
4043
def setUpClass(cls) -> None:
4144
fixture_path = os.path.join(TEST_DATA, "debian.json")
@@ -45,7 +48,7 @@ def setUpClass(cls) -> None:
4548
cls.importer = models.Importer.objects.create(
4649
name="debian_unittests",
4750
license="",
48-
last_run="2019-08-05 13:14:17.733232+05:30",
51+
last_run=dateparser.parse("2019-08-05 13:14:17.733232+05:30"),
4952
data_source="DebianDataSource",
5053
data_source_cfg={"debian_tracker_url": "https://security.example.com/json"},
5154
)
@@ -84,12 +87,12 @@ def test_response_is_new(self):
8487
mock_resp.headers = {"last-modified": "Wed, 05 Aug 2021 09:12:19 GMT"}
8588

8689
with patch("vulnerabilities.importers.debian.requests.head", return_value=mock_resp):
87-
assert test_data_source.response_is_new() is True
90+
assert test_data_source.response_is_new()
8891

89-
mock_resp.headers = {"last-modified": "Wed, 05 Aug 2019 09:12:19 GMT"}
92+
mock_resp.headers = {"last-modified": "Wed, 04 Aug 2019 09:12:19 GMT"}
9093

9194
with patch("vulnerabilities.importers.debian.requests.head", return_value=mock_resp):
92-
assert test_data_source.response_is_new() is False
95+
assert not test_data_source.response_is_new()
9396

9497
def assert_for_package(self, name, version, release, cve_ids=None):
9598
qs = models.Package.objects.filter(

0 commit comments

Comments
 (0)