-
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.
chore(RHTAPWATCH-634): request ODCS compose
Implement ODCSRequestor, allowing requesting ODCS for multiple compose files, per number of sources. Signed-off-by: Omer <[email protected]>
- Loading branch information
Showing
6 changed files
with
131 additions
and
12 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
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,83 @@ | ||
"""test_odcs_requester.py - test odcs_requester""" | ||
from typing import Callable | ||
|
||
# pylint: disable=redefined-outer-name | ||
from unittest.mock import MagicMock, create_autospec | ||
|
||
import pytest | ||
from odcs.client.odcs import ODCS, ComposeSourceTag # type: ignore | ||
|
||
from generate_compose.odcs_configurations_generator import ( | ||
ODCSComposeConfig, | ||
ODCSComposesConfigs, | ||
) | ||
from generate_compose.odcs_requester import ODCSRequester, ODCSRequestReferences | ||
|
||
|
||
@pytest.fixture() | ||
def compose_url() -> str: | ||
"""Example compose-url, as close to the one expected""" | ||
return "http://download.eng.bos.redhat.com/odcs/prod/odcs-222222" | ||
|
||
|
||
@pytest.fixture() | ||
def create_odcs_mock(compose_url: str) -> Callable[[int], MagicMock]: | ||
"""Create an ODCS mock with specific results for the compose method""" | ||
|
||
def _mock_odcs_compose(num_of_composes: int) -> MagicMock: | ||
"""Monkey-patched ODCS compose""" | ||
mock: MagicMock = create_autospec(ODCS) | ||
mock.request_compose.side_effect = [ | ||
{"result_repofile": f"{compose_url}", "id": i} | ||
for i in range(1, num_of_composes + 1) | ||
] | ||
return mock | ||
|
||
return _mock_odcs_compose | ||
|
||
|
||
@pytest.fixture() | ||
def compose_source_tag() -> ComposeSourceTag: | ||
"""Example ComposeSource of type 'tag'""" | ||
return ComposeSourceTag(tag="tag") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("composes_configs, num_of_composes"), | ||
[ | ||
pytest.param( | ||
ODCSComposesConfigs([ODCSComposeConfig(spec=ComposeSourceTag(tag="tag"))]), | ||
1, | ||
id="single compose, tag source, no additional arguments", | ||
), | ||
pytest.param( | ||
ODCSComposesConfigs( | ||
[ | ||
ODCSComposeConfig(spec=ComposeSourceTag(tag="tag")), | ||
ODCSComposeConfig(spec=ComposeSourceTag(tag="tag")), | ||
] | ||
), | ||
2, | ||
id="multiple composes, , tag source, no additional arguments", | ||
), | ||
], | ||
) | ||
def test_odcs_requester( | ||
create_odcs_mock: Callable, | ||
compose_url: str, | ||
compose_source_tag: ComposeSourceTag, | ||
composes_configs: ODCSComposesConfigs, | ||
num_of_composes: int, | ||
) -> None: | ||
"""test ODCSRequester.__call__""" | ||
expected_req_ref = ODCSRequestReferences( | ||
compose_urls=[compose_url] * num_of_composes | ||
) | ||
mock_odcs = create_odcs_mock(num_of_composes) | ||
odcs_requester = ODCSRequester(odcs=mock_odcs) | ||
req_ref = odcs_requester(compose_configs=composes_configs) | ||
|
||
assert mock_odcs.request_compose.call_count == num_of_composes | ||
assert mock_odcs.request_compose.call_args[0][0].source == compose_source_tag.source | ||
assert mock_odcs.wait_for_compose.call_count == num_of_composes | ||
assert req_ref == expected_req_ref |