More repos in the get_external_repo returns and error
Fixes: https://pagure.io/koji/issue/3033
This commit is contained in:
parent
390a633afd
commit
7096bddc4f
2 changed files with 38 additions and 2 deletions
|
|
@ -3759,8 +3759,12 @@ def get_external_repo(info, strict=False, event=None):
|
||||||
:returns: a map containing the id, name, and url of the repository.
|
:returns: a map containing the id, name, and url of the repository.
|
||||||
"""
|
"""
|
||||||
repos = get_external_repos(info, event=event)
|
repos = get_external_repos(info, event=event)
|
||||||
if repos:
|
if len(repos) == 1:
|
||||||
return repos[0]
|
return repos[0]
|
||||||
|
elif len(repos) > 1:
|
||||||
|
# a very defective situation which should never occur
|
||||||
|
# (name/id should be exact identification)
|
||||||
|
raise koji.GenericError('More than one repo in the result.')
|
||||||
else:
|
else:
|
||||||
if strict:
|
if strict:
|
||||||
raise koji.GenericError('No such repo: %s' % info)
|
raise koji.GenericError('No such repo: %s' % info)
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,41 @@ class TestGetExternalRepo(unittest.TestCase):
|
||||||
self.get_external_repos = mock.patch('kojihub.get_external_repos').start()
|
self.get_external_repos = mock.patch('kojihub.get_external_repos').start()
|
||||||
self.exports = kojihub.RootExports()
|
self.exports = kojihub.RootExports()
|
||||||
|
|
||||||
def test_non_exist_repo(self):
|
def test_non_exist_repo_with_strict(self):
|
||||||
repo = 'test-repo'
|
repo = 'test-repo'
|
||||||
self.get_external_repos.return_value = []
|
self.get_external_repos.return_value = []
|
||||||
with self.assertRaises(koji.GenericError) as cm:
|
with self.assertRaises(koji.GenericError) as cm:
|
||||||
self.exports.getExternalRepo(repo, strict=True)
|
self.exports.getExternalRepo(repo, strict=True)
|
||||||
self.assertEqual("No such repo: %s" % repo, str(cm.exception))
|
self.assertEqual("No such repo: %s" % repo, str(cm.exception))
|
||||||
|
|
||||||
|
def test_non_exist_repo_without_strict(self):
|
||||||
|
repo = 'test-repo'
|
||||||
|
self.get_external_repos.return_value = []
|
||||||
|
rv = self.exports.getExternalRepo(repo, strict=False)
|
||||||
|
self.assertEqual(None, rv)
|
||||||
|
|
||||||
|
def test_valid(self):
|
||||||
|
repo = 'test-repo'
|
||||||
|
repo_info = [
|
||||||
|
{'id': 1,
|
||||||
|
'name': 'build-external-repo-1',
|
||||||
|
'url': 'https://path/to/ext/repo1'},
|
||||||
|
]
|
||||||
|
self.get_external_repos.return_value = repo_info
|
||||||
|
rv = self.exports.getExternalRepo(repo, strict=True)
|
||||||
|
self.assertEqual(repo_info[0], rv)
|
||||||
|
|
||||||
|
def test_more_repos(self):
|
||||||
|
repo = 'test-repo'
|
||||||
|
repo_info = [
|
||||||
|
{'id': 1,
|
||||||
|
'name': 'build-external-repo-1',
|
||||||
|
'url': 'https://path/to/ext/repo1'},
|
||||||
|
{'id': 2,
|
||||||
|
'name': 'build-external-repo-1',
|
||||||
|
'url': 'https://path/to/ext/repo2'}
|
||||||
|
]
|
||||||
|
self.get_external_repos.return_value = repo_info
|
||||||
|
with self.assertRaises(koji.GenericError) as cm:
|
||||||
|
self.exports.getExternalRepo(repo, strict=False)
|
||||||
|
self.assertEqual("More than one repo in the result.", str(cm.exception))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue