2020-01-31 17:27:22 +01:00
|
|
|
import json
|
|
|
|
import os.path
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2020-02-21 16:50:00 +01:00
|
|
|
from rpmautospec import release
|
2020-01-31 17:27:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
__here__ = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
test_data = [
|
|
|
|
{
|
|
|
|
"package": "gimp",
|
|
|
|
"expected_results": [
|
|
|
|
# 5 existing builds -> 6
|
2020-02-21 18:21:19 +01:00
|
|
|
{"dist": "fc32", "last": "gimp-2.10.14-4.fc32.1", "next": "gimp-2.10.14-6.fc32",},
|
|
|
|
{"dist": "fc31", "last": "gimp-2.10.14-3.fc31", "next": "gimp-2.10.14-4.fc31",},
|
2020-01-31 17:27:22 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def data_as_test_parameters(test_data):
|
|
|
|
parameters = []
|
|
|
|
|
|
|
|
for datum in test_data:
|
|
|
|
blueprint = datum.copy()
|
|
|
|
expected_results = blueprint.pop("expected_results")
|
|
|
|
for expected in expected_results:
|
|
|
|
parameters.append({**blueprint, **expected})
|
|
|
|
|
|
|
|
return parameters
|
|
|
|
|
|
|
|
|
|
|
|
class TestNextBuild:
|
|
|
|
@pytest.mark.parametrize("test_data", data_as_test_parameters(test_data))
|
|
|
|
def test_main(self, test_data, capsys):
|
|
|
|
with open(
|
2020-02-21 18:21:19 +01:00
|
|
|
os.path.join(__here__, "koji-output", "list-builds", test_data["package"] + ".json"),
|
2020-01-31 17:27:22 +01:00
|
|
|
"rb",
|
|
|
|
) as f:
|
|
|
|
koji_list_builds_output = json.load(f)
|
|
|
|
|
2020-02-24 11:41:57 +01:00
|
|
|
with mock.patch("rpmautospec.misc.koji") as mock_koji:
|
2020-01-31 17:27:22 +01:00
|
|
|
mock_client = mock.MagicMock()
|
|
|
|
mock_koji.ClientSession.return_value = mock_client
|
|
|
|
mock_client.getPackageID.return_value = 1234
|
|
|
|
mock_client.listBuilds.return_value = koji_list_builds_output
|
|
|
|
|
2020-02-21 16:50:00 +01:00
|
|
|
main_args = mock.Mock()
|
|
|
|
main_args.algorithm = "sequential_builds"
|
|
|
|
main_args.package = test_data["package"]
|
|
|
|
main_args.dist = test_data["dist"]
|
|
|
|
main_args.evr = None
|
|
|
|
|
|
|
|
release.main(main_args)
|
2020-01-31 17:27:22 +01:00
|
|
|
|
|
|
|
mock_client.getPackageID.assert_called_once()
|
|
|
|
mock_client.listBuilds.assert_called_once()
|
|
|
|
|
2020-02-21 18:21:19 +01:00
|
|
|
expected_output = f"Last build: {test_data['last']}\n" f"Next build: {test_data['next']}\n"
|
2020-01-31 17:27:22 +01:00
|
|
|
captured_output = capsys.readouterr()
|
|
|
|
|
|
|
|
assert captured_output.out == expected_output
|