debian-koji-osbuild/test/unit/test_hub.py
Christian Kellner d7bfaee189 plugins: ability to skip the tagging
Add a new command line option `--skip-tag` that will skip tagging
after a successful build. The help text is copied from the same
option of other sub-commands in the koji client. The hub plugin's
jsonschema was updated accordingly, and the builder plugin will
skip the tag if the option was requested.
Tests were added or augmented for all three plugins to test the
new option.
2020-11-16 17:00:40 +01:00

75 lines
2 KiB
Python

#
# koji hub plugin unit tests
#
import jsonschema
import koji
from flexmock import flexmock
from plugintest import PluginTest
@PluginTest.load_plugin("hub")
class TestHubPlugin(PluginTest):
@staticmethod
def mock_koji_context(*, admin=False):
session = flexmock()
session.should_receive("hasPerm") \
.with_args("admin") \
.and_return(admin)
session.should_receive("assertPerm") \
.with_args("image") \
.once()
context = flexmock(session=session)
return context
@staticmethod
def mock_kojihub(args, task):
kojihub = flexmock()
kojihub.should_receive("make_task") \
.with_args("osbuildImage", args, **task)
return kojihub
def test_plugin_jsonschema(self):
# Make sure the schema used to validate the input is
# itself correct jsonschema
schema = self.plugin.OSBUILD_IMAGE_SCHEMA
jsonschema.Draft4Validator.check_schema(schema)
def test_basic(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"],
opts]
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_input_validation(self):
context = self.mock_koji_context()
setattr(self.plugin, "context", context)
opts = {}
args = ["name", "version", "distro",
"image_type", # image type not an array
"target",
["arches"],
opts]
with self.assertRaises(koji.ParameterError):
self.plugin.osbuildImage(*args, opts)