Unify error messages
Unify error messages for CLI Unify error messages for hub Fixes: https://pagure.io/koji/issue/2720
This commit is contained in:
parent
bbe5b4c703
commit
e784373000
77 changed files with 2170 additions and 348 deletions
13
tests/test_hub/test_add_external_repo_to_tag.py
Normal file
13
tests/test_hub/test_add_external_repo_to_tag.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import unittest
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestAddExternalRepoToTag(unittest.TestCase):
|
||||
|
||||
def test_with_wrong_merge_mode(self):
|
||||
merge_mode = 'test-mode'
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.add_external_repo_to_tag('tag', 'repo', 1, merge_mode=merge_mode)
|
||||
self.assertEqual('No such merge mode: %s' % merge_mode, str(cm.exception))
|
||||
43
tests/test_hub/test_add_group_member.py
Normal file
43
tests/test_hub/test_add_group_member.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestAddGroupMember(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exports = kojihub.RootExports()
|
||||
self.get_user = mock.patch('kojihub.get_user').start()
|
||||
|
||||
def test_non_exist_user(self):
|
||||
data = [{'id': 3,
|
||||
'name': 'test-group',
|
||||
'status': 0,
|
||||
'usertype': 2,
|
||||
'krb_principals': []},
|
||||
None,
|
||||
]
|
||||
group = 'test-group'
|
||||
username = 'test-user'
|
||||
self.get_user.side_effect = data
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.addGroupMember(group, username)
|
||||
self.assertEqual("Not an user: %s" % username, str(cm.exception))
|
||||
|
||||
def test_non_exist_group(self):
|
||||
data = [None,
|
||||
{'id': 1,
|
||||
'krb_principals': [],
|
||||
'name': 'test-user',
|
||||
'status': 0,
|
||||
'usertype': 0}
|
||||
]
|
||||
group = 'test-group'
|
||||
username = 'test-user'
|
||||
self.get_user.side_effect = data
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.addGroupMember(group, username)
|
||||
self.assertEqual("Not a group: %s" % group, str(cm.exception))
|
||||
|
|
@ -33,13 +33,16 @@ class TestCGImporter(unittest.TestCase):
|
|||
|
||||
def test_get_metadata_is_not_instance(self):
|
||||
x = kojihub.CG_Importer()
|
||||
with self.assertRaises(GenericError):
|
||||
x.get_metadata(42, '')
|
||||
metadata = 42
|
||||
with self.assertRaises(GenericError) as ex:
|
||||
x.get_metadata(metadata, '')
|
||||
self.assertEqual('Invalid type for metadata value: %s' % type(metadata), str(ex.exception))
|
||||
|
||||
def test_get_metadata_is_none(self):
|
||||
x = kojihub.CG_Importer()
|
||||
with self.assertRaises(GenericError):
|
||||
with self.assertRaises(GenericError) as ex:
|
||||
x.get_metadata(None, '')
|
||||
self.assertEqual('No such file: metadata.json', str(ex.exception))
|
||||
|
||||
@mock.patch("koji.pathinfo.work")
|
||||
def test_get_metadata_missing_json_file(self, work):
|
||||
|
|
@ -170,6 +173,30 @@ class TestCGImporter(unittest.TestCase):
|
|||
x.get_metadata('default.json', 'cg_importer_json')
|
||||
x.import_metadata()
|
||||
|
||||
@mock.patch("kojihub.CG_Importer.get_metadata")
|
||||
def test_do_import_no_such_metadata(self, get_metadata):
|
||||
x = kojihub.CG_Importer()
|
||||
metadata = {'metadata_version': 99,
|
||||
'build': {
|
||||
'name': 'f32-build-n2j8',
|
||||
'version': '1.1',
|
||||
'release': '1',
|
||||
'epoch': 0,
|
||||
'owner': 'kojiadmin'}
|
||||
}
|
||||
get_metadata.return_value = metadata
|
||||
with self.assertRaises(koji.GenericError) as ex:
|
||||
x.do_import(metadata, '/test/dir')
|
||||
self.assertEqual('No such metadata version: %s' % metadata['metadata_version'],
|
||||
str(ex.exception))
|
||||
|
||||
def test_match_componemt_wrong_component(self):
|
||||
x = kojihub.CG_Importer()
|
||||
components = [{'type': 'type'}]
|
||||
with self.assertRaises(koji.GenericError) as ex:
|
||||
x.match_components(components)
|
||||
self.assertEqual('No such component type: %s' % components[0]['type'], str(ex.exception))
|
||||
|
||||
|
||||
class TestMatchKojiFile(unittest.TestCase):
|
||||
|
||||
|
|
|
|||
60
tests/test_hub/test_create_notification.py
Normal file
60
tests/test_hub/test_create_notification.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import unittest
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestCreateNotification(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exports = kojihub.RootExports()
|
||||
self.exports.getLoggedInUser = mock.MagicMock()
|
||||
self.context = mock.patch('kojihub.context').start()
|
||||
self.cursor = mock.MagicMock()
|
||||
|
||||
def test_non_exist_user(self):
|
||||
user_id = 999
|
||||
package_id = 555
|
||||
tag_id = 111
|
||||
success_only = False
|
||||
logged_user = {'authtype': 2,
|
||||
'id': 1,
|
||||
'krb_principal': None,
|
||||
'krb_principals': [],
|
||||
'name': 'kojiadmin',
|
||||
'status': 0,
|
||||
'usertype': 0}
|
||||
self.cursor.fetchone.return_value = None
|
||||
self.context.cnx.cursor.return_value = self.cursor
|
||||
self.exports.getLoggedInUser.return_value = logged_user
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.createNotification(user_id, package_id, tag_id, success_only)
|
||||
self.assertEqual('No such user ID: %s' % user_id, str(cm.exception))
|
||||
|
||||
|
||||
class TestCreateNotificationBlock(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exports = kojihub.RootExports()
|
||||
self.exports.getLoggedInUser = mock.MagicMock()
|
||||
self.context = mock.patch('kojihub.context').start()
|
||||
self.cursor = mock.MagicMock()
|
||||
|
||||
def test_non_exist_user(self):
|
||||
user_id = 999
|
||||
package_id = 555
|
||||
tag_id = 111
|
||||
logged_user = {'authtype': 2,
|
||||
'id': 1,
|
||||
'krb_principal': None,
|
||||
'krb_principals': [],
|
||||
'name': 'kojiadmin',
|
||||
'status': 0,
|
||||
'usertype': 0}
|
||||
self.cursor.fetchone.return_value = None
|
||||
self.context.cnx.cursor.return_value = self.cursor
|
||||
self.exports.getLoggedInUser.return_value = logged_user
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.createNotificationBlock(user_id, package_id, tag_id)
|
||||
self.assertEqual('No such user ID: %s' % user_id, str(cm.exception))
|
||||
20
tests/test_hub/test_delete_build_target.py
Normal file
20
tests/test_hub/test_delete_build_target.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestDeleteBuildTarget(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.lookup_name = mock.patch('kojihub.lookup_name').start()
|
||||
self.exports = kojihub.RootExports()
|
||||
|
||||
def test_non_exist_target(self):
|
||||
build_target = 'build-target'
|
||||
self.lookup_name.return_value = None
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.deleteBuildTarget(build_target)
|
||||
self.assertEqual("No such build target: %s" % build_target, str(cm.exception))
|
||||
20
tests/test_hub/test_disable_user.py
Normal file
20
tests/test_hub/test_disable_user.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestDisableUser(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exports = kojihub.RootExports()
|
||||
self.get_user = mock.patch('kojihub.get_user').start()
|
||||
|
||||
def test_non_exist_user(self):
|
||||
username = 'test-user'
|
||||
self.get_user.return_value = None
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.disableUser(username)
|
||||
self.assertEqual("No such user: %s" % username, str(cm.exception))
|
||||
27
tests/test_hub/test_edit_build_target.py
Normal file
27
tests/test_hub/test_edit_build_target.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestEditBuildTarget(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.lookup_build_target = mock.patch('kojihub.lookup_build_target').start()
|
||||
self.exports = kojihub.RootExports()
|
||||
|
||||
def test_non_exist_build_target(self):
|
||||
session = kojihub.context.session = mock.MagicMock()
|
||||
session.assertPerm = mock.MagicMock()
|
||||
target_name = 'build-target'
|
||||
name = 'build-target-rename'
|
||||
build_tag = 'tag'
|
||||
dest_tag = 'dest-tag'
|
||||
self.lookup_build_target.return_value = None
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.editBuildTarget(target_name, name, build_tag, dest_tag)
|
||||
self.assertEqual("No such build target: %s" % target_name,
|
||||
str(cm.exception))
|
||||
session.assertPerm.called_once_with('target')
|
||||
20
tests/test_hub/test_enable_user.py
Normal file
20
tests/test_hub/test_enable_user.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestEnableUser(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exports = kojihub.RootExports()
|
||||
self.get_user = mock.patch('kojihub.get_user').start()
|
||||
|
||||
def test_non_exist_user(self):
|
||||
username = 'test-user'
|
||||
self.get_user.return_value = None
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.enableUser(username)
|
||||
self.assertEqual("No such user: %s" % username, str(cm.exception))
|
||||
47
tests/test_hub/test_find_build_id.py
Normal file
47
tests/test_hub/test_find_build_id.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestFindBuildId(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.context = mock.patch('kojihub.context').start()
|
||||
self.cursor = mock.MagicMock()
|
||||
|
||||
def test_non_exist_build_dict(self):
|
||||
build = {
|
||||
'name': 'test_name',
|
||||
'version': 'test_version',
|
||||
'release': 'test_release',
|
||||
}
|
||||
self.cursor.fetchone.return_value = None
|
||||
self.context.cnx.cursor.return_value = self.cursor
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.find_build_id(build, strict=True)
|
||||
self.assertEqual("No such build: %s" % build, str(cm.exception))
|
||||
|
||||
def test_invalid_argument(self):
|
||||
build = ['test-build']
|
||||
self.cursor.fetchone.return_value = None
|
||||
self.context.cnx.cursor.return_value = self.cursor
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.find_build_id(build)
|
||||
self.assertEqual("Invalid type for argument: %s" % type(build), str(cm.exception))
|
||||
|
||||
def test_build_dict_without_release(self):
|
||||
build = {
|
||||
'name': 'test_name',
|
||||
'version': 'test_version',
|
||||
'epoch': 'test_epoch',
|
||||
'owner': 'test_owner',
|
||||
'extra': {'extra_key': 'extra_value'},
|
||||
}
|
||||
self.cursor.fetchone.return_value = None
|
||||
self.context.cnx.cursor.return_value = self.cursor
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.find_build_id(build, strict=True)
|
||||
self.assertEqual("did not provide name, version, and release", str(cm.exception))
|
||||
|
|
@ -31,7 +31,7 @@ class TestGetPackageID(DBQueryTestCase):
|
|||
'strict': True,
|
||||
'self': mock.ANY})
|
||||
self.assertEqual(cm.exception.args[0],
|
||||
'Invalid package name: invalidpkg')
|
||||
'No such package name: invalidpkg')
|
||||
|
||||
def test_getPackageID_None(self):
|
||||
rv = kojihub.RootExports().getPackageID('invalidpkg')
|
||||
|
|
|
|||
38
tests/test_hub/test_getRPM.py
Normal file
38
tests/test_hub/test_getRPM.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import unittest
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestGetRPM(unittest.TestCase):
|
||||
|
||||
def test_wrong_type_rpminfo(self):
|
||||
rpminfo = ['test-user']
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.get_rpm(rpminfo)
|
||||
self.assertEqual("Invalid type for rpminfo: %s" % type(rpminfo), str(cm.exception))
|
||||
|
||||
|
||||
class TestGetRPMHeaders(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exports = kojihub.RootExports()
|
||||
self.exports.getLoggedInUser = mock.MagicMock()
|
||||
self.context = mock.patch('kojihub.context').start()
|
||||
self.cursor = mock.MagicMock()
|
||||
|
||||
def test_taskid_invalid_path(self):
|
||||
self.cursor.fetchone.return_value = None
|
||||
self.context.cnx.cursor.return_value = self.cursor
|
||||
filepath = '../test/path'
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getRPMHeaders(taskID=99, filepath=filepath)
|
||||
self.assertEqual("Invalid filepath: %s" % filepath, str(cm.exception))
|
||||
|
||||
def test_taskid_without_filepath(self):
|
||||
self.cursor.fetchone.return_value = None
|
||||
self.context.cnx.cursor.return_value = self.cursor
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getRPMHeaders(taskID=99)
|
||||
self.assertEqual("filepath must be specified with taskID", str(cm.exception))
|
||||
37
tests/test_hub/test_get_build.py
Normal file
37
tests/test_hub/test_get_build.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
from .utils import DBQueryTestCase
|
||||
|
||||
|
||||
class TestGetBuild(DBQueryTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestGetBuild, self).setUp()
|
||||
self.find_build_id = mock.patch('kojihub.find_build_id').start()
|
||||
|
||||
def test_non_exist_build_string(self):
|
||||
build = 'build-1-23'
|
||||
self.find_build_id.side_effect = koji.GenericError('No such build: %s' % build)
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.get_build(build, strict=True)
|
||||
self.assertEqual('No such build: %s' % build, str(cm.exception))
|
||||
|
||||
def test_non_exist_build_int(self):
|
||||
build = 11
|
||||
self.find_build_id.return_value = build
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.get_build(build, strict=True)
|
||||
self.assertEqual('No such build: %s' % build, str(cm.exception))
|
||||
|
||||
def test_non_exist_build_dict(self):
|
||||
build = {
|
||||
'name': 'test_name',
|
||||
'version': 'test_version',
|
||||
'release': 'test_release',
|
||||
}
|
||||
self.find_build_id.side_effect = koji.GenericError('No such build: %s' % build['name'])
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.get_build(build, strict=True)
|
||||
self.assertEqual('No such build: %s' % build['name'], str(cm.exception))
|
||||
28
tests/test_hub/test_get_build_target.py
Normal file
28
tests/test_hub/test_get_build_target.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestGetBuildTarget(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.get_build_targets = mock.patch('kojihub.get_build_targets').start()
|
||||
self.exports = kojihub.RootExports()
|
||||
|
||||
def test_non_exist_build_target(self):
|
||||
build_target = 'build-target'
|
||||
self.get_build_targets.return_value = []
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getBuildTarget(build_target, strict=True)
|
||||
self.assertEqual("No such build target: %s" % build_target, str(cm.exception))
|
||||
|
||||
def test_wrong_type_build_target(self):
|
||||
build_target = {'info_key': 'info_value'}
|
||||
expected = "Invalid type for lookup: %s" % type(build_target)
|
||||
self.get_build_targets.side_effect = koji.GenericError(expected)
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getBuildTarget(build_target, strict=True)
|
||||
self.assertEqual(expected, str(cm.exception))
|
||||
65
tests/test_hub/test_get_changelog_entries.py
Normal file
65
tests/test_hub/test_get_changelog_entries.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
from koji.util import joinpath
|
||||
|
||||
|
||||
class TestGetChangelogEntries(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exports = kojihub.RootExports()
|
||||
self.get_build = mock.patch('kojihub.get_build').start()
|
||||
self.context = mock.patch('kojihub.context').start()
|
||||
self.cursor = mock.MagicMock()
|
||||
self.os_path_exists = mock.patch('os.path.exists').start()
|
||||
|
||||
def test_non_exist_build(self):
|
||||
build_id = 1
|
||||
self.cursor.fetchone.return_value = None
|
||||
self.context.cnx.cursor.return_value = self.cursor
|
||||
self.get_build.return_value = None
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getChangelogEntries(buildID=build_id, strict=True)
|
||||
self.assertEqual("No such build: %s" % build_id, str(cm.exception))
|
||||
|
||||
def test_taskid_invalid_path(self):
|
||||
filepath = '../test/path'
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getChangelogEntries(taskID=99, filepath=filepath)
|
||||
self.assertEqual("Invalid filepath: %s" % filepath, str(cm.exception))
|
||||
|
||||
def test_taskid_without_filepath(self):
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getChangelogEntries(taskID=99)
|
||||
self.assertEqual("filepath must be specified with taskID", str(cm.exception))
|
||||
|
||||
def test_before_invalid_type(self):
|
||||
before = {'before': '1133456'}
|
||||
filepath = 'test/path'
|
||||
self.os_path_exists.return_value = True
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getChangelogEntries(taskID=99, before=before, filepath=filepath)
|
||||
self.assertEqual("Invalid type for before: %s" % type(before), str(cm.exception))
|
||||
|
||||
def test_after_invalid_type(self):
|
||||
after = {'after': '1133456'}
|
||||
filepath = 'test/path'
|
||||
self.os_path_exists.return_value = True
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getChangelogEntries(taskID=99, after=after, filepath=filepath)
|
||||
self.assertEqual("Invalid type for after: %s" % type(after), str(cm.exception))
|
||||
|
||||
def test_srpm_path_not_exist(self):
|
||||
filepath = 'test/path'
|
||||
task_id = 99
|
||||
srpm_path = joinpath(koji.pathinfo.work(),
|
||||
koji.pathinfo.taskrelpath(task_id),
|
||||
filepath)
|
||||
self.os_path_exists.return_value = False
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getChangelogEntries(taskID=task_id, filepath=filepath, strict=True)
|
||||
self.assertEqual("SRPM %s doesn't exist" % srpm_path, str(cm.exception))
|
||||
22
tests/test_hub/test_get_channel.py
Normal file
22
tests/test_hub/test_get_channel.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import unittest
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestGetChannel(unittest.TestCase):
|
||||
|
||||
def test_wrong_type_channelInfo(self):
|
||||
# dict
|
||||
channel_info = {'channel': 'val'}
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.get_channel(channel_info)
|
||||
self.assertEqual('Invalid type for channelInfo: %s' % type(channel_info),
|
||||
str(cm.exception))
|
||||
|
||||
#list
|
||||
channel_info = ['channel']
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.get_channel(channel_info)
|
||||
self.assertEqual('Invalid type for channelInfo: %s' % type(channel_info),
|
||||
str(cm.exception))
|
||||
20
tests/test_hub/test_get_external_repo.py
Normal file
20
tests/test_hub/test_get_external_repo.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestGetExternalRepo(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.get_external_repos = mock.patch('kojihub.get_external_repos').start()
|
||||
self.exports = kojihub.RootExports()
|
||||
|
||||
def test_non_exist_repo(self):
|
||||
repo = 'test-repo'
|
||||
self.get_external_repos.return_value = []
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getExternalRepo(repo, strict=True)
|
||||
self.assertEqual("No such repo: %s" % repo, str(cm.exception))
|
||||
|
|
@ -144,3 +144,9 @@ class TestGetExternalRepos(DBQueryTestCase):
|
|||
self.assertEqual(rv, [{'id': 1,
|
||||
'name': 'ext_repo_1',
|
||||
'url': 'http://example.com/repo/'}])
|
||||
|
||||
def test_get_external_repos_wrong_type(self):
|
||||
info = {'info_key': 'info_value'}
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.get_external_repos(info=info)
|
||||
self.assertEqual("Invalid type for lookup: %s" % type(info), str(cm.exception))
|
||||
|
|
|
|||
20
tests/test_hub/test_get_group_members.py
Normal file
20
tests/test_hub/test_get_group_members.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestGetGroupMembers(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.get_user = mock.patch('kojihub.get_user').start()
|
||||
self.exports = kojihub.RootExports()
|
||||
|
||||
def test_non_exist_group(self):
|
||||
group = 'test-group'
|
||||
self.get_user.return_value = []
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getGroupMembers(group)
|
||||
self.assertEqual("No such group: %s" % group, str(cm.exception))
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import mock
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
|
@ -17,7 +18,7 @@ class TestSetHostEnabled(unittest.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.QueryProcessor = mock.patch('kojihub.QueryProcessor',
|
||||
side_effect=self.getQuery).start()
|
||||
side_effect=self.getQuery).start()
|
||||
self.queries = []
|
||||
self.context = mock.patch('kojihub.context').start()
|
||||
# It seems MagicMock will not automatically handle attributes that
|
||||
|
|
@ -33,12 +34,12 @@ class TestSetHostEnabled(unittest.TestCase):
|
|||
self.assertEqual(len(self.queries), 1)
|
||||
query = self.queries[0]
|
||||
columns = ['host.id', 'host.user_id', 'host.name', 'host.ready',
|
||||
'host.task_load', 'host_config.arches',
|
||||
'host_config.capacity', 'host_config.description',
|
||||
'host_config.comment', 'host_config.enabled']
|
||||
'host.task_load', 'host_config.arches',
|
||||
'host_config.capacity', 'host_config.description',
|
||||
'host_config.comment', 'host_config.enabled']
|
||||
joins = ['host ON host.id = host_config.host_id']
|
||||
aliases = ['id', 'user_id', 'name', 'ready', 'task_load',
|
||||
'arches', 'capacity', 'description', 'comment', 'enabled']
|
||||
'arches', 'capacity', 'description', 'comment', 'enabled']
|
||||
clauses = ['(host_config.active = TRUE)', 'host.name = %(hostInfo)s']
|
||||
values = {'hostInfo': 'hostname'}
|
||||
self.assertEqual(query.tables, ['host_config'])
|
||||
|
|
@ -54,14 +55,15 @@ class TestSetHostEnabled(unittest.TestCase):
|
|||
self.assertEqual(len(self.queries), 1)
|
||||
query = self.queries[0]
|
||||
columns = ['host.id', 'host.user_id', 'host.name', 'host.ready',
|
||||
'host.task_load', 'host_config.arches',
|
||||
'host_config.capacity', 'host_config.description',
|
||||
'host_config.comment', 'host_config.enabled']
|
||||
'host.task_load', 'host_config.arches',
|
||||
'host_config.capacity', 'host_config.description',
|
||||
'host_config.comment', 'host_config.enabled']
|
||||
joins = ['host ON host.id = host_config.host_id']
|
||||
aliases = ['id', 'user_id', 'name', 'ready', 'task_load',
|
||||
'arches', 'capacity', 'description', 'comment', 'enabled']
|
||||
clauses = ['(host_config.create_event <= 345 AND ( host_config.revoke_event IS NULL OR 345 < host_config.revoke_event ))',
|
||||
'host.id = %(hostInfo)i']
|
||||
'arches', 'capacity', 'description', 'comment', 'enabled']
|
||||
clauses = ['(host_config.create_event <= 345 AND ( host_config.revoke_event IS NULL '
|
||||
'OR 345 < host_config.revoke_event ))',
|
||||
'host.id = %(hostInfo)i']
|
||||
values = {'hostInfo': 123}
|
||||
self.assertEqual(query.tables, ['host_config'])
|
||||
self.assertEqual(query.joins, joins)
|
||||
|
|
@ -77,19 +79,21 @@ class TestSetHostEnabled(unittest.TestCase):
|
|||
|
||||
def test_get_host_missing(self):
|
||||
self.QueryProcessor.side_effect = self.getQueryMissing
|
||||
|
||||
r = self.exports.getHost(123)
|
||||
host_id = 123
|
||||
r = self.exports.getHost(host_id)
|
||||
self.assertEqual(r, None)
|
||||
|
||||
with self.assertRaises(koji.GenericError):
|
||||
self.exports.getHost(123, strict=True)
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getHost(host_id, strict=True)
|
||||
self.assertEqual("Invalid hostInfo: %s" % host_id, str(cm.exception))
|
||||
|
||||
self.assertEqual(len(self.queries), 2)
|
||||
|
||||
self.QueryProcessor.side_effect = self.getQuery
|
||||
|
||||
def test_get_host_invalid_hostinfo(self):
|
||||
with self.assertRaises(koji.GenericError):
|
||||
self.exports.getHost({'host_id': 567})
|
||||
|
||||
host_info = {'host_id': 567}
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getHost(host_info)
|
||||
self.assertEqual("Invalid type for hostInfo: %s" % type(host_info), str(cm.exception))
|
||||
self.assertEqual(len(self.queries), 0)
|
||||
|
|
|
|||
16
tests/test_hub/test_get_last_event.py
Normal file
16
tests/test_hub/test_get_last_event.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import unittest
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestGetLastEvent(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exports = kojihub.RootExports()
|
||||
|
||||
def test_wrong_type_before(self):
|
||||
before = '12345'
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getLastEvent(before)
|
||||
self.assertEqual("Invalid type for before: %s" % type(before), str(cm.exception))
|
||||
51
tests/test_hub/test_get_user.py
Normal file
51
tests/test_hub/test_get_user.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import unittest
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestGetUser(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exports = kojihub.RootExports()
|
||||
|
||||
def test_wrong_format_user_info(self):
|
||||
userinfo = ['test-user']
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getUser(userinfo)
|
||||
self.assertEqual("Invalid type for userInfo: %s" % type(userinfo), str(cm.exception))
|
||||
|
||||
def test_wrong_format_userid(self):
|
||||
userinfo = {'id': '123456'}
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getUser(userinfo)
|
||||
self.assertEqual("Invalid type for userid: %s" % type(userinfo['id']), str(cm.exception))
|
||||
|
||||
def test_wrong_format_username(self):
|
||||
userinfo = {'name': 57896}
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getUser(userinfo)
|
||||
self.assertEqual("Invalid type for username: %s" % type(userinfo['name']),
|
||||
str(cm.exception))
|
||||
|
||||
def test_wrong_format_krb_principal(self):
|
||||
userinfo = {'krb_principal': 57896}
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.getUser(userinfo)
|
||||
self.assertEqual("Invalid type for krb_principal: %s" % type(userinfo['krb_principal']),
|
||||
str(cm.exception))
|
||||
|
||||
|
||||
class TestGetUserByKrbPrincipal(unittest.TestCase):
|
||||
def test_wrong_type_krb_principal(self):
|
||||
krb_principal = ['test-user']
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.get_user_by_krb_principal(krb_principal)
|
||||
self.assertEqual("Invalid type for krb_principal: %s" % type(krb_principal),
|
||||
str(cm.exception))
|
||||
|
||||
def test_krb_principal_none(self):
|
||||
krb_principal = None
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.get_user_by_krb_principal(krb_principal)
|
||||
self.assertEqual("No kerberos principal provided", str(cm.exception))
|
||||
|
|
@ -19,9 +19,12 @@ class TestImportRPM(unittest.TestCase):
|
|||
# Touch a file
|
||||
with open(self.src_filename, 'w'):
|
||||
pass
|
||||
self.context = mock.patch('kojihub.context').start()
|
||||
self.cursor = mock.MagicMock()
|
||||
|
||||
self.rpm_header_retval = {
|
||||
'filename': 'name-version-release.arch.rpm',
|
||||
'sourcepackage': 2,
|
||||
1000: 'name',
|
||||
1001: 'version',
|
||||
1002: 'release',
|
||||
|
|
@ -164,6 +167,36 @@ class TestImportRPM(unittest.TestCase):
|
|||
}
|
||||
_dml.assert_called_once_with(statement, values)
|
||||
|
||||
@mock.patch('os.path.exists')
|
||||
def test_non_exist_file(self, os_path_exist):
|
||||
exports = kojihub.RootExports()
|
||||
basename = 'rpm-1-34'
|
||||
uploadpath = koji.pathinfo.work()
|
||||
filepath = '%s/%s/%s' % (uploadpath, self.filename, basename)
|
||||
os_path_exist.return_value = False
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
exports.importRPM(self.filename, basename)
|
||||
self.assertEqual("No such file: %s" % filepath, str(cm.exception))
|
||||
|
||||
@mock.patch('koji.get_rpm_header')
|
||||
@mock.patch('os.path.exists')
|
||||
@mock.patch('os.path.basename')
|
||||
def test_non_exist_file(self, os_path_basename, os_path_exist, get_rpm_header):
|
||||
self.cursor.fetchone.return_value = None
|
||||
self.context.cnx.cursor.return_value = self.cursor
|
||||
retval = copy.copy(self.rpm_header_retval)
|
||||
retval.update({
|
||||
'filename': 'name-version-release.arch.rpm',
|
||||
'sourcepackage': 2
|
||||
})
|
||||
get_rpm_header.return_value = retval
|
||||
os_path_exist.return_value = True
|
||||
os_path_basename.return_value = 'name-version-release.arch.rpm'
|
||||
kojihub.get_build.return_value = None
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.import_rpm(self.src_filename)
|
||||
self.assertEqual("No such build", str(cm.exception))
|
||||
|
||||
|
||||
class TestImportBuild(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
|
@ -283,3 +316,12 @@ class TestImportBuild(unittest.TestCase):
|
|||
'id': mock.ANY,
|
||||
}
|
||||
_dml.assert_called_once_with(statement, values)
|
||||
|
||||
@mock.patch('os.path.exists')
|
||||
def test_import_build_non_exist_file(self, os_path_exists):
|
||||
uploadpath = koji.pathinfo.work()
|
||||
os_path_exists.return_value = False
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.import_build(self.src_filename, [self.filename])
|
||||
self.assertEqual("No such file: %s/%s" % (uploadpath, self.src_filename),
|
||||
str(cm.exception))
|
||||
|
|
|
|||
14
tests/test_hub/test_list_rpms.py
Normal file
14
tests/test_hub/test_list_rpms.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import unittest
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestListRpms(unittest.TestCase):
|
||||
|
||||
def test_wrong_type_arches(self):
|
||||
arches = {'test-arch': 'val'}
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.list_rpms(arches=arches)
|
||||
self.assertEqual('Invalid type for "arches" parameter: %s' % type(arches),
|
||||
str(cm.exception))
|
||||
45
tests/test_hub/test_list_tags.py
Normal file
45
tests/test_hub/test_list_tags.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestListTags(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.get_build = mock.patch('kojihub.get_build').start()
|
||||
self.exports = kojihub.RootExports()
|
||||
self.context = mock.patch('kojihub.context').start()
|
||||
self.cursor = mock.MagicMock()
|
||||
|
||||
def test_non_exist_build(self):
|
||||
build_id = 999
|
||||
self.get_build.return_value = None
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.listTags(build=build_id)
|
||||
self.assertEqual("No such build: %s" % build_id, str(cm.exception))
|
||||
|
||||
build_name = 'test-build-1-23'
|
||||
self.get_build.return_value = None
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.listTags(build=build_name)
|
||||
self.assertEqual("No such build: %s" % build_name, str(cm.exception))
|
||||
|
||||
def test_non_exist_package(self):
|
||||
package_id = 999
|
||||
self.cursor.fetchone.return_value = None
|
||||
self.context.cnx.cursor.return_value = self.cursor
|
||||
kojihub.lookup_package.return_value = koji.GenericError
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.listTags(package=package_id)
|
||||
self.assertEqual("No such package: %s" % package_id, str(cm.exception))
|
||||
|
||||
package_name = 'test-pkg'
|
||||
self.cursor.fetchone.return_value = None
|
||||
self.context.cnx.cursor.return_value = self.cursor
|
||||
kojihub.lookup_package.return_value = koji.GenericError
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.listTags(package=package_name)
|
||||
self.assertEqual("No such package: %s" % package_name, str(cm.exception))
|
||||
18
tests/test_hub/test_list_user_krb_principals.py
Normal file
18
tests/test_hub/test_list_user_krb_principals.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestListUserKrbPrincipals(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exports = kojihub.RootExports()
|
||||
|
||||
def test_wrong_format_user_info(self):
|
||||
userinfo = ['test-user']
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.list_user_krb_principals(userinfo)
|
||||
self.assertEqual("Invalid type for user_info: %s" % type(userinfo), str(cm.exception))
|
||||
|
|
@ -151,7 +151,8 @@ class TestNewBuild(unittest.TestCase):
|
|||
'extra': {'extra_key': CantDoJSON()},
|
||||
}
|
||||
|
||||
with self.assertRaises(koji.GenericError):
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.new_build(data)
|
||||
|
||||
self.assertEqual(len(self.inserts), 0)
|
||||
self.assertEqual("No such build extra data: %(extra)r" % data, str(cm.exception))
|
||||
|
|
|
|||
|
|
@ -257,14 +257,26 @@ class TestPkglistBlock(unittest.TestCase):
|
|||
readPackageList.return_value = {}
|
||||
|
||||
# package needs to be name, not dict
|
||||
with self.assertRaises(koji.GenericError):
|
||||
with self.assertRaises(koji.GenericError) as ex:
|
||||
kojihub._direct_pkglist_add(tag['name'], pkg,
|
||||
user['name'], block=block, extra_arches=extra_arches,
|
||||
force=force, update=update, policy=policy)
|
||||
self.assertEqual("No such package: %s" % pkg, str(ex.exception))
|
||||
|
||||
lookup_package.assert_called_once_with(pkg, strict=False)
|
||||
self.assertEqual(self.run_callbacks.call_count, 0)
|
||||
_pkglist_add.assert_not_called()
|
||||
@mock.patch('kojihub.get_tag')
|
||||
@mock.patch('kojihub.lookup_package')
|
||||
def test_direct_pkglist_add_pkginfo_dict(self, lookup_package, get_tag):
|
||||
pkg = {'id': 2, 'name': 'pkg', 'owner_id': 3}
|
||||
user = 'user'
|
||||
tag = {'id': 1, 'name': 'tag'}
|
||||
expected = "Invalid type for id lookup: %s" % pkg
|
||||
|
||||
get_tag.return_value = tag
|
||||
lookup_package.side_effect = koji.GenericError(expected)
|
||||
with self.assertRaises(koji.GenericError) as ex:
|
||||
kojihub._direct_pkglist_add(tag['name'], pkg, user, block=False, extra_arches='arch',
|
||||
force=False, update=True)
|
||||
self.assertEqual(expected, str(ex.exception))
|
||||
|
||||
@mock.patch('kojihub._pkglist_add')
|
||||
@mock.patch('kojihub.readPackageList')
|
||||
|
|
|
|||
21
tests/test_hub/test_search.py
Normal file
21
tests/test_hub/test_search.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import unittest
|
||||
|
||||
import koji
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestSearch(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exports = kojihub.RootExports()
|
||||
|
||||
def test_empty_terms(self):
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.search('', 'type', 'glob')
|
||||
self.assertEqual("empty search terms", str(cm.exception))
|
||||
|
||||
def test_wrong_type(self):
|
||||
type = 'test-type'
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.search('item', type, 'glob')
|
||||
self.assertEqual("No such search type: %s" % type, str(cm.exception))
|
||||
|
|
@ -146,3 +146,33 @@ class TestTagBuild(unittest.TestCase):
|
|||
self.assertEqual(update.data, data)
|
||||
self.assertEqual(update.values, values)
|
||||
update = self.updates[0]
|
||||
|
||||
|
||||
class TestGetTag(unittest.TestCase):
|
||||
|
||||
def getQuery(self, *args, **kwargs):
|
||||
query = QP(*args, **kwargs)
|
||||
query.execute = mock.MagicMock()
|
||||
query.executeOne = self.query_executeOne
|
||||
query.iterate = mock.MagicMock()
|
||||
self.queries.append(query)
|
||||
return query
|
||||
|
||||
def setUp(self):
|
||||
self.query_executeOne = mock.MagicMock()
|
||||
self.QueryProcessor = mock.patch('kojihub.QueryProcessor',
|
||||
side_effect=self.getQuery).start()
|
||||
self.queries = []
|
||||
|
||||
def test_get_tag_invalid_taginfo(self):
|
||||
taginfo = {'test-tag': 'value'}
|
||||
with self.assertRaises(koji.GenericError) as ex:
|
||||
kojihub.get_tag(taginfo, strict=True)
|
||||
self.assertEqual("Invalid type for tagInfo: %s" % type(taginfo), str(ex.exception))
|
||||
|
||||
def test_get_tag_non_exist_tag(self):
|
||||
taginfo = 'test-tag'
|
||||
self.query_executeOne.return_value = None
|
||||
with self.assertRaises(koji.GenericError) as ex:
|
||||
kojihub.get_tag(taginfo, strict=True)
|
||||
self.assertEqual("No such tagInfo: '%s'" % taginfo, str(ex.exception))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue