raise Error when user not found in getBuildNotifications

This commit is contained in:
Yuming Zhu 2018-07-31 17:50:07 +08:00
parent e50cd283b8
commit 5a229a092e
2 changed files with 32 additions and 9 deletions

View 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')