PR#1016: raise Error when user not found in getBuildNotifications
Merges #1016 https://pagure.io/koji/pull-request/1016 Fixes: #1013 https://pagure.io/koji/issue/1013 getBuildNotifications API call should raise GenericError exception for non existing user ID
This commit is contained in:
commit
4a214437ee
2 changed files with 32 additions and 9 deletions
|
|
@ -11004,15 +11004,11 @@ class RootExports(object):
|
||||||
|
|
||||||
|
|
||||||
def getBuildNotifications(self, userID=None):
|
def getBuildNotifications(self, userID=None):
|
||||||
"""Get build notifications for the user with the given ID. If no ID
|
"""Get build notifications for the user with the given ID, name or
|
||||||
is specified, get the notifications for the currently logged-in user. If
|
Kerberos principal. If no user is specified, get the notifications for
|
||||||
there is no currently logged-in user, raise a GenericError."""
|
the currently logged-in user. If there is no currently logged-in user,
|
||||||
if userID is None:
|
raise a GenericError."""
|
||||||
user = self.getLoggedInUser()
|
userID = get_user(userID, strict=True)['id']
|
||||||
if user is None:
|
|
||||||
raise koji.GenericError('not logged-in')
|
|
||||||
else:
|
|
||||||
userID = user['id']
|
|
||||||
return get_build_notifications(userID)
|
return get_build_notifications(userID)
|
||||||
|
|
||||||
def getBuildNotification(self, id):
|
def getBuildNotification(self, id):
|
||||||
|
|
|
||||||
27
tests/test_hub/test_get_build_notifications.py
Normal file
27
tests/test_hub/test_get_build_notifications.py
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
import mock
|
||||||
|
try:
|
||||||
|
import unittest2 as unittest
|
||||||
|
except ImportError:
|
||||||
|
import unittest
|
||||||
|
import koji
|
||||||
|
import kojihub
|
||||||
|
|
||||||
|
|
||||||
|
class TestGetBuildNotifications(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch('kojihub.get_user', return_value={'id': 1})
|
||||||
|
@mock.patch('kojihub.get_build_notifications')
|
||||||
|
def test_loggedin_user(self, get_build_notifications, get_user):
|
||||||
|
kojihub.RootExports().getBuildNotifications(None)
|
||||||
|
get_user.assert_called_once_with(None, strict=True)
|
||||||
|
get_build_notifications.assert_called_once_with(1)
|
||||||
|
|
||||||
|
@mock.patch('kojihub.get_user', side_effect=koji.GenericError('error msg'))
|
||||||
|
@mock.patch('kojihub.get_build_notifications')
|
||||||
|
def test_user_not_found(self, get_build_notifications, get_user):
|
||||||
|
with self.assertRaises(koji.GenericError) as cm:
|
||||||
|
kojihub.RootExports().getBuildNotifications(1)
|
||||||
|
get_user.assert_called_once_with(1, strict=True)
|
||||||
|
get_build_notifications.assert_not_called()
|
||||||
|
self.assertEqual(cm.exception.args[0], 'error msg')
|
||||||
Loading…
Add table
Add a link
Reference in a new issue