88#
99
1010import json
11- import os
11+ from pathlib import Path
1212
13- from vulnerabilities .importers import nvd
13+ from vulnerabilities .pipelines import nvd_importer
1414from vulnerabilities .tests .util_tests import VULNERABLECODE_REGEN_TEST_FIXTURES as REGEN
1515
16- BASE_DIR = os .path .dirname (os .path .abspath (__file__ ))
17- TEST_DATA = os .path .join (BASE_DIR , "test_data/nvd/nvd_test.json" )
18- REJECTED_CVE = os .path .join (BASE_DIR , "test_data/nvd/rejected_nvd.json" )
16+ TEST_DATA = Path (__file__ ).parent .parent / "test_data" / "nvd"
1917
2018
2119def load_test_data (file ):
@@ -37,10 +35,11 @@ def sorted_advisory_data(advisory_data):
3735
3836
3937def test_to_advisories_skips_hardware (regen = REGEN ):
40- expected_file = os . path . join ( BASE_DIR , "test_data/ nvd/nvd -expected.json")
38+ expected_file = TEST_DATA / " nvd-expected.json"
4139
42- test_data = load_test_data (file = TEST_DATA )
43- result = [data .to_dict () for data in nvd .to_advisories (test_data )]
40+ test_file = TEST_DATA / "nvd_test.json"
41+ test_data = load_test_data (file = test_file )
42+ result = [data .to_dict () for data in nvd_importer .to_advisories (test_data )]
4443 result = sorted_advisory_data (result )
4544
4645 if regen :
@@ -56,10 +55,11 @@ def test_to_advisories_skips_hardware(regen=REGEN):
5655
5756
5857def test_to_advisories_marks_rejected_cve (regen = REGEN ):
59- expected_file = os . path . join ( BASE_DIR , "test_data/ nvd/nvd -rejected-expected.json")
58+ expected_file = TEST_DATA / " nvd-rejected-expected.json"
6059
61- test_data = load_test_data (file = REJECTED_CVE )
62- result = [data .to_dict () for data in nvd .to_advisories (test_data )]
60+ test_file = TEST_DATA / "rejected_nvd.json"
61+ test_data = load_test_data (file = test_file )
62+ result = [data .to_dict () for data in nvd_importer .to_advisories (test_data )]
6363 result = sorted_advisory_data (result )
6464
6565 if regen :
@@ -168,14 +168,16 @@ def test_CveItem_cpes():
168168 "cpe:2.3:a:csilvers:gperftools:*:*:*:*:*:*:*:*" ,
169169 ]
170170
171- found_cpes = nvd .CveItem (cve_item = get_test_cve_item ()).cpes
171+ found_cpes = nvd_importer .CveItem (cve_item = get_test_cve_item ()).cpes
172172 assert found_cpes == expected_cpes
173173
174174
175175def test_is_related_to_hardware ():
176- assert nvd .is_related_to_hardware ("cpe:2.3:h:csilvers:gperftools:0.2:*:*:*:*:*:*:*" )
177- assert not nvd .is_related_to_hardware ("cpe:2.3:a:csilvers:gperftools:0.1:*:*:*:*:*:*:*" )
178- assert not nvd .is_related_to_hardware ("cpe:2.3:a:csilvers:gperftools:*:*:*:*:*:*:*:*" )
176+ assert nvd_importer .is_related_to_hardware ("cpe:2.3:h:csilvers:gperftools:0.2:*:*:*:*:*:*:*" )
177+ assert not nvd_importer .is_related_to_hardware (
178+ "cpe:2.3:a:csilvers:gperftools:0.1:*:*:*:*:*:*:*"
179+ )
180+ assert not nvd_importer .is_related_to_hardware ("cpe:2.3:a:csilvers:gperftools:*:*:*:*:*:*:*:*" )
179181
180182
181183def test_CveItem_summary_with_single_summary ():
@@ -186,7 +188,7 @@ def test_CveItem_summary_with_single_summary():
186188 "be allocated than expected."
187189 )
188190
189- assert nvd .CveItem (cve_item = get_test_cve_item ()).summary == expected_summary
191+ assert nvd_importer .CveItem (cve_item = get_test_cve_item ()).summary == expected_summary
190192
191193
192194def test_CveItem_reference_urls ():
@@ -195,4 +197,4 @@ def test_CveItem_reference_urls():
195197 "http://kqueue.org/blog/2012/03/05/memory-allocator-security-revisited/" ,
196198 ]
197199
198- assert nvd .CveItem (cve_item = get_test_cve_item ()).reference_urls == expected_urls
200+ assert nvd_importer .CveItem (cve_item = get_test_cve_item ()).reference_urls == expected_urls
0 commit comments