Skip to content

Commit 85cb602

Browse files
pombredannesbs2001
andauthored
Ensure Debian test are passing (#538)
* Ensure Debian test are passing Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com> * Build docs with Python 3.7 Since we use Python 3.8 everywhere, let's use it there too. Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com> * Fix debian tests Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com> Co-authored-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
1 parent db33279 commit 85cb602

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
max-parallel: 4
1111
matrix:
12-
python-version: [3.7]
12+
python-version: [3.8]
1313

1414
steps:
1515
- name: Checkout code

vulnerabilities/importers/debian.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ 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)
136141
if self.config.last_run_date:
137142
return self.config.last_run_date < last_modified_date

vulnerabilities/tests/test_debian.py

Lines changed: 11 additions & 7 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

@@ -45,14 +47,16 @@ def setUpClass(cls) -> None:
4547
cls.importer = models.Importer.objects.create(
4648
name="debian_unittests",
4749
license="",
48-
last_run="2019-08-05 13:14:17.733232+05:30",
50+
last_run=dateparser.parse("2019-08-05 13:14:17.733232+05:30"),
4951
data_source="DebianDataSource",
5052
data_source_cfg={"debian_tracker_url": "https://security.example.com/json"},
5153
)
54+
return super().setUpClass()
5255

53-
@classmethod
54-
def tearDownClass(cls) -> None:
55-
pass
56+
def tearDown(self) -> None:
57+
self.importer.data_source_cfg = {"debian_tracker_url": "https://security.example.com/json"}
58+
self.importer.last_run = dateparser.parse("2019-08-05 13:14:17.733232+05:30")
59+
self.importer.save()
5660

5761
def test_import(self):
5862
runner = ImportRunner(self.importer, 5)
@@ -84,12 +88,12 @@ def test_response_is_new(self):
8488
mock_resp.headers = {"last-modified": "Wed, 05 Aug 2021 09:12:19 GMT"}
8589

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

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

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

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

0 commit comments

Comments
 (0)