test/cli: add unit test skeleton

Add the skeleton to run the cli plugin unit tests. As first check
ensure that exceptions are thrown for the build target checks.
This commit is contained in:
Christian Kellner 2020-09-14 13:24:37 +02:00 committed by Tom Gundersen
parent 9e98f10afc
commit b92e19aa1d

65
test/unit/test_cli.py Normal file
View file

@ -0,0 +1,65 @@
#
# koji command line interface plugin unit tests
#
import contextlib
import io
import koji
from flexmock import flexmock
from plugintest import PluginTest
@PluginTest.load_plugin("cli")
class TestCliPlugin(PluginTest):
def test_basic_invocation(self):
# check we get the right amount of arguments
# i.e. we are missing the architecture here
argv = ["name", "version", "distro", "target"]
f = io.StringIO()
with self.assertRaises(SystemExit) as cm, \
contextlib.redirect_stderr(f):
self.plugin.handle_osbuild_image(None, None, argv)
self.assertEqual(cm.exception.code, 2)
self.assertIn("osbuild-image", f.getvalue())
f.close()
def test_target_check(self):
# unknown build target
session = flexmock()
session.should_receive("getBuildTarget") \
.with_args("target") \
.and_return(None) \
.once()
argv = ["name", "version", "distro", "target", "arch1"]
with self.assertRaises(koji.GenericError):
self.plugin.handle_osbuild_image(None, session, argv)
# unknown destination tag
build_target = {
"build_tag": 23,
"build_tag_name": "target-build",
"dest_tag": 42,
"dest_tag_name": "target-dest" # missing!
}
session = flexmock()
session.should_receive("getBuildTarget") \
.with_args("target") \
.and_return(build_target) \
.once()
session.should_receive("getTag") \
.with_args(build_target["dest_tag"]) \
.and_return(None) \
.once()
argv = ["name", "version", "distro", "target", "arch1"]
with self.assertRaises(koji.GenericError):
self.plugin.handle_osbuild_image(None, session, argv)