-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from Honny1/move-unit-tests-to-dir-unit-tests
Move unit tests to the unit tests directory
- Loading branch information
Showing
3 changed files
with
59 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2022, Red Hat, Inc. | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import tempfile | ||
from io import BytesIO | ||
from pathlib import Path | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from openscap_report.cli import CommandLineAPI | ||
from openscap_report.scap_results_parser import (ARF_SCHEMAS_PATH, | ||
SCAPResultsParser) | ||
|
||
from ..test_utils import get_fake_args | ||
|
||
PATH_TO_RESULT_FILE = Path(tempfile.gettempdir()) / "oscap-report-tests_result.html" | ||
|
||
|
||
@pytest.mark.unit_test | ||
@mock.patch('argparse.ArgumentParser.parse_args', | ||
return_value=get_fake_args()) | ||
def test_load_file(mock_args): # pylint: disable=W0613 | ||
api = CommandLineAPI() | ||
xml_report = api.load_file() | ||
parser = SCAPResultsParser(xml_report) | ||
assert parser.validate(ARF_SCHEMAS_PATH) | ||
api.close_files() | ||
|
||
|
||
@pytest.mark.unit_test | ||
@pytest.mark.usefixtures("remove_generated_file") | ||
@mock.patch('argparse.ArgumentParser.parse_args', | ||
return_value=get_fake_args()) | ||
def test_store_file(mock_args): # pylint: disable=W0613 | ||
api = CommandLineAPI() | ||
data = BytesIO(b'<html><h1>TEST DATA</h1></html>') | ||
api.store_file(data) | ||
api.close_files() | ||
with open(PATH_TO_RESULT_FILE, "r", encoding="utf-8") as result_file: | ||
assert result_file.read() == data.getvalue().decode("utf-8") |