Skip to content

Commit 47f732d

Browse files
committed
Test v2 ubuntu importer pipeline
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 2b0d198 commit 47f732d

24 files changed

+50277
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
10+
11+
from pathlib import Path
12+
from unittest.mock import patch
13+
14+
from django.test import TestCase
15+
16+
from vulnerabilities.models import AdvisoryV2
17+
from vulnerabilities.pipelines.v2_importers.ubuntu_osv_importer import UbuntuOSVImporterPipeline
18+
from vulnerabilities.tests import util_tests
19+
from vulnerabilities.tests.pipelines import TestLogger
20+
21+
TEST_DATA = Path(__file__).parent.parent.parent / "test_data" / "ubuntu"
22+
23+
24+
class TestUbuntuOSVImporterPipeline(TestCase):
25+
def setUp(self):
26+
self.logger = TestLogger()
27+
28+
@patch(
29+
"vulnerabilities.pipelines.v2_importers.ubuntu_osv_importer.UbuntuOSVImporterPipeline.clone"
30+
)
31+
def test_redhat_advisories_v2(self, mock_clone):
32+
mock_clone.__name__ = "clone"
33+
pipeline = UbuntuOSVImporterPipeline()
34+
pipeline.advisories_path = TEST_DATA / "ubuntu_security_notices"
35+
pipeline.vcs_response = None
36+
pipeline.log = self.logger.write
37+
pipeline.execute()
38+
39+
self.assertEqual(AdvisoryV2.objects.count(), 22)
40+
41+
expected_file = TEST_DATA / "ubuntu_osv_advisoryv2-expected.json"
42+
result = [adv.to_advisory_data().to_dict() for adv in AdvisoryV2.objects.all()]
43+
util_tests.check_results_against_json(result, expected_file, regen=True)

0 commit comments

Comments
 (0)