|
7 | 7 | # See https://aboutcode.org for more information about nexB OSS projects. |
8 | 8 | # |
9 | 9 | import json |
10 | | -import os |
| 10 | +from pathlib import Path |
11 | 11 | from unittest import TestCase |
12 | 12 |
|
13 | 13 | from vulnerabilities.importers.osv import parse_advisory_data |
14 | 14 | from vulnerabilities.tests.util_tests import VULNERABLECODE_REGEN_TEST_FIXTURES as REGEN |
15 | 15 | from vulnerabilities.tests.util_tests import check_results_against_json |
16 | 16 |
|
17 | | -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
18 | | -TEST_DATA = os.path.join(BASE_DIR, "test_data/pysec") |
| 17 | +TEST_DATA = Path(__file__).parent.parent / "test_data" / "pysec" |
19 | 18 |
|
20 | 19 |
|
21 | 20 | class TestPyPIImporter(TestCase): |
22 | 21 | def test_to_advisories_with_summary(self): |
23 | | - with open(os.path.join(TEST_DATA, "pysec-advisories_with_summary.json")) as f: |
| 22 | + with open(TEST_DATA / "pysec-advisories_with_summary.json") as f: |
24 | 23 | mock_response = json.load(f) |
25 | 24 | results = parse_advisory_data(mock_response, ["pypi"], "https://test.com").to_dict() |
26 | 25 |
|
27 | | - expected_file = os.path.join(TEST_DATA, "pysec-advisories_with_summary-expected.json") |
| 26 | + expected_file = TEST_DATA / "pysec-advisories_with_summary-expected.json" |
28 | 27 | check_results_against_json( |
29 | 28 | results=results, |
30 | 29 | expected_file=expected_file, |
31 | 30 | regen=REGEN, |
32 | 31 | ) |
33 | 32 |
|
34 | 33 | def test_to_advisories_without_summary(self): |
35 | | - with open(os.path.join(TEST_DATA, "pysec-advisories_without_summary.json")) as f: |
| 34 | + with open(TEST_DATA / "pysec-advisories_without_summary.json") as f: |
36 | 35 | mock_response = json.load(f) |
37 | 36 |
|
38 | 37 | results = parse_advisory_data(mock_response, ["pypi"], "https://test.com").to_dict() |
39 | 38 |
|
40 | | - expected_file = os.path.join(TEST_DATA, "pysec-advisories_without_summary-expected.json") |
| 39 | + expected_file = TEST_DATA / "pysec-advisories_without_summary-expected.json" |
41 | 40 | check_results_against_json( |
42 | 41 | results=results, |
43 | 42 | expected_file=expected_file, |
44 | 43 | regen=REGEN, |
45 | 44 | ) |
46 | 45 |
|
47 | 46 | def test_to_advisories_with_cwe(self): |
48 | | - with open(os.path.join(TEST_DATA, "pysec-advisory_with_cwe.json")) as f: |
| 47 | + with open(TEST_DATA / "pysec-advisory_with_cwe.json") as f: |
49 | 48 | mock_response = json.load(f) |
50 | 49 |
|
51 | 50 | results = parse_advisory_data( |
52 | 51 | raw_data=mock_response, supported_ecosystems=["pypi"], advisory_url="https://tes.com" |
53 | 52 | ).to_dict() |
54 | 53 |
|
55 | | - expected_file = os.path.join(TEST_DATA, "pysec-advisories_with_cwe-expected.json") |
| 54 | + expected_file = TEST_DATA / "pysec-advisories_with_cwe-expected.json" |
56 | 55 | check_results_against_json( |
57 | 56 | results=results, |
58 | 57 | expected_file=expected_file, |
|
0 commit comments