def test_get_gpg_sign_options__missing_cmd(self): repo = mock.MagicMock(id="myrepo") cmd = os.path.join(self.test_dir, "sign.sh") config = dict(gpg_cmd=cmd) with self.assertRaises(util.SignerError) as ctx: configuration.get_gpg_sign_options(repo, config) self.assertEqual("Command %s is not a file" % cmd, str(ctx.exception))
def test_get_gpg_sign_options__nonexec_cmd(self): repo = mock.MagicMock(id="myrepo") cmd = os.path.join(self.test_dir, "sign.sh") open(cmd, "w").write("#!/bin/bash") os.chmod(cmd, 0644) config = dict(gpg_cmd=cmd) with self.assertRaises(util.SignerError) as ctx: configuration.get_gpg_sign_options(repo, config) self.assertEqual("Command %s is not executable" % cmd, str(ctx.exception))
def test_get_gpg_sign_options__default_cmd(self, _os_access): "Make sure the test passes even if gpg is not installed" _os_access.return_value = 1 opts = configuration.get_gpg_sign_options() cmd = "/usr/bin/gpg --yes --detach-sign --armor" self.assertEqual(dict(GPG_CMD=cmd), opts.as_environment()) _os_access.assert_called_once_with("/usr/bin/gpg", 1)
def test_get_gpg_sign_options(self): repo = mock.MagicMock(id="myrepo") cmd = os.path.join(self.test_dir, "sign.sh") open(cmd, "w").write("#!/bin/bash") os.chmod(cmd, 0755) config = dict(gpg_cmd=cmd) opts = configuration.get_gpg_sign_options(repo, config) self.assertEqual(dict(GPG_CMD=cmd, GPG_REPOSITORY_NAME="myrepo"), opts.as_environment())