debian-koji/tests/test_hub/test_get_build_notification_blocks.py
Yuming Zhu ca05418fb5 unittest: use unittest.mock instead of mock
because the absence of unittest.mock on python2.7, we still fallback to
mock
2024-10-23 16:35:30 +00:00

29 lines
1.1 KiB
Python

from unittest import mock
import unittest
import koji
import kojihub
class TestGetBuildNotificationBlocks(unittest.TestCase):
def setUp(self):
self.exports = kojihub.RootExports()
self.get_user = mock.patch('kojihub.kojihub.get_user').start()
self.get_build_notification_blocks = mock.patch(
'kojihub.kojihub.get_build_notification_blocks').start()
def tearDown(self):
mock.patch.stopall()
def test_loggedin_user(self):
self.get_user.return_value = {'id': 1}
self.exports.getBuildNotificationBlocks(None)
self.get_user.assert_called_once_with(None, strict=True)
self.get_build_notification_blocks.assert_called_once_with(1)
def test_user_not_found(self):
self.get_user.side_effect = koji.GenericError('error msg')
with self.assertRaises(koji.GenericError) as cm:
self.exports.getBuildNotificationBlocks(1)
self.get_user.assert_called_once_with(1, strict=True)
self.get_build_notification_blocks.assert_not_called()
self.assertEqual(cm.exception.args[0], 'error msg')