Total Complexity | 3 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Copyright 2022, Red Hat, Inc. |
||
2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
||
3 | |||
4 | import tempfile |
||
5 | from io import BytesIO |
||
6 | from pathlib import Path |
||
7 | from unittest import mock |
||
8 | |||
9 | import pytest |
||
10 | |||
11 | from openscap_report.cli import CommandLineAPI |
||
12 | from openscap_report.scap_results_parser import (ARF_SCHEMAS_PATH, |
||
13 | SCAPResultsParser) |
||
14 | |||
15 | from ..test_utils import get_fake_args |
||
16 | |||
17 | PATH_TO_RESULT_FILE = Path(tempfile.gettempdir()) / "oscap-report-tests_result.html" |
||
18 | |||
19 | |||
20 | @pytest.mark.unit_test |
||
21 | @mock.patch('argparse.ArgumentParser.parse_args', |
||
22 | return_value=get_fake_args()) |
||
23 | def test_load_file(mock_args): # pylint: disable=W0613 |
||
24 | api = CommandLineAPI() |
||
25 | xml_report = api.load_file() |
||
26 | parser = SCAPResultsParser(xml_report) |
||
27 | assert parser.validate(ARF_SCHEMAS_PATH) |
||
28 | api.close_files() |
||
29 | |||
30 | |||
31 | @pytest.mark.unit_test |
||
32 | @pytest.mark.usefixtures("remove_generated_file") |
||
33 | @mock.patch('argparse.ArgumentParser.parse_args', |
||
34 | return_value=get_fake_args()) |
||
35 | def test_store_file(mock_args): # pylint: disable=W0613 |
||
36 | api = CommandLineAPI() |
||
37 | data = BytesIO(b'<html><h1>TEST DATA</h1></html>') |
||
38 | api.store_file(data) |
||
39 | api.close_files() |
||
40 | with open(PATH_TO_RESULT_FILE, "r", encoding="utf-8") as result_file: |
||
41 | assert result_file.read() == data.getvalue().decode("utf-8") |
||
42 |