Skip to content

Commit 933ce53

Browse files
committed
Add test for RedHat importer pipeline
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 4b89cdb commit 933ce53

File tree

8 files changed

+9993
-0
lines changed

8 files changed

+9993
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
import json
11+
import os
12+
from pathlib import Path
13+
from unittest.mock import Mock
14+
from unittest.mock import patch
15+
16+
from django.test import TestCase
17+
18+
from vulnerabilities.models import AdvisoryV2
19+
from vulnerabilities.models import PackageV2
20+
from vulnerabilities.pipelines.v2_importers.redhat_importer import RedHatImporterPipeline
21+
from vulnerabilities.tests import util_tests
22+
23+
TEST_DATA = Path(__file__).parent.parent.parent / "test_data" / "redhat" / "csaf_2_0"
24+
25+
26+
class TestArchLinuxImporterPipeline(TestCase):
27+
@patch("vulnerabilities.pipelines.v2_importers.redhat_importer.RedHatImporterPipeline.fetch")
28+
def test_redhat_advisories_v2(self, mock_fetch):
29+
mock_fetch.__name__ = "fetch"
30+
pipeline = RedHatImporterPipeline()
31+
pipeline.location = TEST_DATA
32+
pipeline.execute()
33+
self.assertEqual(6, AdvisoryV2.objects.count())
34+
self.assertEqual(93, PackageV2.objects.count())
35+
expected_file = TEST_DATA.parent / "redhat_advisoryv2-expected.json"
36+
result = [adv.to_advisory_data().to_dict() for adv in AdvisoryV2.objects.all()]
37+
util_tests.check_results_against_json(result, expected_file)

0 commit comments

Comments
 (0)