Skip to content

Commit

Permalink
chore(RHTAPWATCH-691): verify-rpms test to fail on unsigned RPMs
Browse files Browse the repository at this point in the history
The e2e test for the verify-rpms script checked
only scenarios where it should not fail on unsigned RPMs.

Added a test to check a scenario where the script should
fail on unsigned RPMs - and those exist.

Signed-off-by: Omer <[email protected]>
  • Loading branch information
Omeramsc committed Dec 26, 2023
1 parent 41c6df1 commit 76bd495
Showing 1 changed file with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions tests/test_rpm_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from subprocess import CalledProcessError
from textwrap import dedent
from typing import Callable
from unittest.mock import MagicMock, call, create_autospec, sentinel

import pytest
Expand Down Expand Up @@ -355,24 +356,34 @@ def mock_image_processor(self, monkeypatch: MonkeyPatch) -> MagicMock:
return mock

@pytest.fixture()
def mock_generate_output(self, monkeypatch: MonkeyPatch) -> MagicMock:
"""Monkey-patched generate_output"""
mock = create_autospec(generate_output, return_value=(False, ""))
monkeypatch.setattr(rpm_verifier, generate_output.__name__, mock)
return mock
def create_generate_output_mock(
self, monkeypatch: MonkeyPatch
) -> Callable[[bool], MagicMock]:
"""Create a generate_output mock with different results according to
the `fail_unsigned` flag"""

def _mock_generate_output(fail_unsigned: bool = False) -> MagicMock:
"""Monkey-patched generate_output"""
mock = create_autospec(generate_output, return_value=(fail_unsigned, ""))
monkeypatch.setattr(rpm_verifier, generate_output.__name__, mock)
return mock

return _mock_generate_output

def test_main(
self,
mock_generate_output: MagicMock,
create_generate_output_mock: MagicMock,
mock_image_processor: MagicMock,
) -> None:
"""Test call to rpm_verifier.py main function"""
fail_on_unsigned_rpms: bool = False
generate_output_mock = create_generate_output_mock(fail_on_unsigned_rpms)
rpm_verifier.main( # pylint: disable=no-value-for-parameter
args=[
"--input",
"img1",
"--fail-unsigned",
"true",
fail_on_unsigned_rpms,
"--workdir",
"some/path",
],
Expand All @@ -381,5 +392,32 @@ def test_main(
)

assert mock_image_processor.return_value.call_count == 1
generate_output_mock.assert_called_once_with(
[sentinel.output], fail_on_unsigned_rpms
)
mock_image_processor.return_value.assert_has_calls([call("img1")])
mock_generate_output.assert_called_once_with([sentinel.output], True)

def test_main_fail_on_unsigned_rpm(
self,
create_generate_output_mock: MagicMock,
mock_image_processor: MagicMock,
) -> None:
"""Test call to rpm_verifier.py main function fails
when whe 'fail-unsigned' flag is used and there are unsigned RPMs
"""
unsigned_rpm_exist: bool = True
create_generate_output_mock(unsigned_rpm_exist)
with pytest.raises(SystemExit):
rpm_verifier.main( # pylint: disable=no-value-for-parameter
args=[
"--input",
"img1",
"--fail-unsigned",
"true",
"--workdir",
"some/path",
],
obj={},
standalone_mode=False,
)
assert mock_image_processor.return_value.call_count == 1

0 comments on commit 76bd495

Please sign in to comment.