test/hub: tidy up the unit test code
Reformat the code to be easier to read. An empty dict was sometimes passed to `osbuildImage()` as the `priority` argument, because `opts` were already part of `args`. Fix it. Restructure `test_input_validation()` test to allow multiple test cases. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
32d9826e1e
commit
05b395c7db
1 changed files with 67 additions and 47 deletions
|
|
@ -13,7 +13,7 @@ from plugintest import PluginTest
|
||||||
class TestHubPlugin(PluginTest):
|
class TestHubPlugin(PluginTest):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mock_koji_context(*, admin=False):
|
def mock_koji_context(*, times=1, admin=False):
|
||||||
session = flexmock()
|
session = flexmock()
|
||||||
session.should_receive("hasPerm") \
|
session.should_receive("hasPerm") \
|
||||||
.with_args("admin") \
|
.with_args("admin") \
|
||||||
|
|
@ -21,7 +21,7 @@ class TestHubPlugin(PluginTest):
|
||||||
|
|
||||||
session.should_receive("assertPerm") \
|
session.should_receive("assertPerm") \
|
||||||
.with_args("image") \
|
.with_args("image") \
|
||||||
.once()
|
.times(times)
|
||||||
|
|
||||||
context = flexmock(session=session)
|
context = flexmock(session=session)
|
||||||
return context
|
return context
|
||||||
|
|
@ -42,43 +42,20 @@ class TestHubPlugin(PluginTest):
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
context = self.mock_koji_context()
|
context = self.mock_koji_context()
|
||||||
|
|
||||||
opts = {"repo": ["repo1", "repo2"],
|
opts = {
|
||||||
"release": "1.2.3",
|
"repo": ["repo1", "repo2"],
|
||||||
"skip_tag": True}
|
"release": "1.2.3",
|
||||||
args = ["name", "version", "distro",
|
"skip_tag": True
|
||||||
"image_type",
|
}
|
||||||
"target",
|
args = [
|
||||||
["arches"],
|
"name",
|
||||||
opts]
|
"version",
|
||||||
|
"distro",
|
||||||
task = {"channel": "image"}
|
|
||||||
|
|
||||||
kojihub = self.mock_kojihub(args, task)
|
|
||||||
|
|
||||||
setattr(self.plugin, "context", context)
|
|
||||||
setattr(self.plugin, "kojihub", kojihub)
|
|
||||||
|
|
||||||
self.plugin.osbuildImage(*args, {})
|
|
||||||
|
|
||||||
def test_image_types_array(self):
|
|
||||||
context = self.mock_koji_context()
|
|
||||||
|
|
||||||
opts = {"repo": ["repo1", "repo2"],
|
|
||||||
"release": "1.2.3",
|
|
||||||
"skip_tag": True}
|
|
||||||
make_task_args = [
|
|
||||||
"name", "version", "distro",
|
|
||||||
"image_type",
|
"image_type",
|
||||||
"target",
|
"target",
|
||||||
["arches"],
|
["arches"]
|
||||||
opts
|
|
||||||
]
|
]
|
||||||
args = ["name", "version", "distro",
|
make_task_args = args + [opts]
|
||||||
["image_type"],
|
|
||||||
"target",
|
|
||||||
["arches"],
|
|
||||||
opts]
|
|
||||||
|
|
||||||
task = {"channel": "image"}
|
task = {"channel": "image"}
|
||||||
|
|
||||||
kojihub = self.mock_kojihub(make_task_args, task)
|
kojihub = self.mock_kojihub(make_task_args, task)
|
||||||
|
|
@ -86,18 +63,61 @@ class TestHubPlugin(PluginTest):
|
||||||
setattr(self.plugin, "context", context)
|
setattr(self.plugin, "context", context)
|
||||||
setattr(self.plugin, "kojihub", kojihub)
|
setattr(self.plugin, "kojihub", kojihub)
|
||||||
|
|
||||||
self.plugin.osbuildImage(*args, {})
|
self.plugin.osbuildImage(*args, opts)
|
||||||
|
|
||||||
|
def test_image_types_array(self):
|
||||||
|
context = self.mock_koji_context()
|
||||||
|
|
||||||
|
opts = {
|
||||||
|
"repo": ["repo1", "repo2"],
|
||||||
|
"release": "1.2.3",
|
||||||
|
"skip_tag": True
|
||||||
|
}
|
||||||
|
args = [
|
||||||
|
"name",
|
||||||
|
"version",
|
||||||
|
"distro",
|
||||||
|
["image_type"],
|
||||||
|
"target",
|
||||||
|
["arches"]
|
||||||
|
]
|
||||||
|
make_task_args = [
|
||||||
|
"name",
|
||||||
|
"version",
|
||||||
|
"distro",
|
||||||
|
"image_type",
|
||||||
|
"target",
|
||||||
|
["arches"]
|
||||||
|
] + [opts]
|
||||||
|
task = {"channel": "image"}
|
||||||
|
|
||||||
|
kojihub = self.mock_kojihub(make_task_args, task)
|
||||||
|
|
||||||
|
setattr(self.plugin, "context", context)
|
||||||
|
setattr(self.plugin, "kojihub", kojihub)
|
||||||
|
|
||||||
|
self.plugin.osbuildImage(*args, opts)
|
||||||
|
|
||||||
def test_input_validation(self):
|
def test_input_validation(self):
|
||||||
context = self.mock_koji_context()
|
test_cases = [
|
||||||
|
# only a single image type is allowed
|
||||||
|
{
|
||||||
|
"args": [
|
||||||
|
"name",
|
||||||
|
"version",
|
||||||
|
"distro",
|
||||||
|
["image_type", "image_type2"],
|
||||||
|
"target",
|
||||||
|
["arches"]
|
||||||
|
],
|
||||||
|
"opts": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
context = self.mock_koji_context(times=len(test_cases))
|
||||||
setattr(self.plugin, "context", context)
|
setattr(self.plugin, "context", context)
|
||||||
|
|
||||||
opts = {}
|
for idx, test_case in enumerate(test_cases):
|
||||||
args = ["name", "version", "distro",
|
with self.subTest(idx=idx):
|
||||||
["image_type", "image_type2"], # only a single image type is allowed
|
with self.assertRaises(koji.ParameterError):
|
||||||
"target",
|
self.plugin.osbuildImage(*test_case["args"], test_case["opts"])
|
||||||
["arches"],
|
|
||||||
opts]
|
|
||||||
|
|
||||||
with self.assertRaises(koji.ParameterError):
|
|
||||||
self.plugin.osbuildImage(*args, opts)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue