more mocks related to context

This commit is contained in:
Tomas Kopecek 2024-07-10 16:05:53 +02:00
parent 117164ab3f
commit d7bbc037f5
11 changed files with 39 additions and 2 deletions

View file

@ -43,6 +43,8 @@ class CliTestCase(unittest.TestCase):
STDOUT = sys.stdout
STDERR = sys.stderr
def tearDown(self):
mock.patch.stopall()
#
# private methods
#
@ -129,7 +131,7 @@ class CliTestCase(unittest.TestCase):
# check callableObj callable
self.__assert_callable(callableObj)
# these arguments are reseverd and used in assert_system_exit
# these arguments are reserved and used in assert_system_exit
reserved = [
'activate_session', 'stdout', 'stderr',
'assert_func', 'exit_code'

View file

@ -9,6 +9,10 @@ class TestAddExternalRepoToTag(unittest.TestCase):
def setUp(self):
self.tag_name = 'test-tag'
self.context = mock.patch('kojihub.kojihub.context').start()
# It seems MagicMock will not automatically handle attributes that
# start with "assert"
self.context.session.assertPerm = mock.MagicMock()
self.get_tag = mock.patch('kojihub.kojihub.get_tag').start()
self.get_external_repo = mock.patch('kojihub.kojihub.get_external_repo').start()
self.get_tag_external_repos = mock.patch('kojihub.kojihub.get_tag_external_repos').start()

View file

@ -10,6 +10,10 @@ class TestAddGroupMember(unittest.TestCase):
def setUp(self):
self.exports = kojihub.RootExports()
self.context = mock.patch('kojihub.kojihub.context').start()
# It seems MagicMock will not automatically handle attributes that
# start with "assert"
self.context.session.assertPerm = mock.MagicMock()
self.get_user = mock.patch('kojihub.kojihub.get_user').start()
def tearDown(self):

View file

@ -8,6 +8,10 @@ import copy
class TestAddUserKrbPrincipal(unittest.TestCase):
def setUp(self):
self.context = mock.patch('kojihub.kojihub.context').start()
# It seems MagicMock will not automatically handle attributes that
# start with "assert"
self.context.session.assertPerm = mock.MagicMock()
self.get_user = mock.patch('kojihub.kojihub.get_user').start()
self.verify_name_user = mock.patch('kojihub.kojihub.verify_name_user').start()
self.get_user_by_krb_principal = mock.patch('kojihub.kojihub.get_user_by_krb_principal').start()

View file

@ -13,6 +13,10 @@ class TestCreateImageBuild(unittest.TestCase):
def setUp(self):
self.get_build = mock.patch('kojihub.kojihub.get_build').start()
self.exports = kojihub.RootExports()
self.context = mock.patch('kojihub.kojihub.context').start()
# It seems MagicMock will not automatically handle attributes that
# start with "assert"
self.context.session.assertPerm = mock.MagicMock()
self.InsertProcessor = mock.patch('kojihub.kojihub.InsertProcessor',
side_effect=self.getInsert).start()
self.inserts = []

View file

@ -20,6 +20,10 @@ class TestDeleteBuildTarget(unittest.TestCase):
def setUp(self):
self.lookup_build_target = mock.patch('kojihub.kojihub.lookup_build_target').start()
self.exports = kojihub.RootExports()
self.context = mock.patch('kojihub.kojihub.context').start()
# It seems MagicMock will not automatically handle attributes that
# start with "assert"
self.context.session.assertPerm = mock.MagicMock()
self.UpdateProcessor = mock.patch('kojihub.kojihub.UpdateProcessor',
side_effect=self.getUpdate).start()
self.updates = []

View file

@ -18,6 +18,10 @@ class TestDisableChannel(unittest.TestCase):
def setUp(self):
self.exports = kojihub.RootExports()
self.context = mock.patch('kojihub.kojihub.context').start()
# It seems MagicMock will not automatically handle attributes that
# start with "assert"
self.context.session.assertPerm = mock.MagicMock()
self.get_channel = mock.patch('kojihub.kojihub.get_channel').start()
self.UpdateProcessor = mock.patch('kojihub.kojihub.UpdateProcessor',
side_effect=self.getUpdate).start()

View file

@ -18,6 +18,11 @@ class TestEnableChannel(unittest.TestCase):
def setUp(self):
self.exports = kojihub.RootExports()
self.context = mock.patch('kojihub.kojihub.context').start()
# It seems MagicMock will not automatically handle attributes that
# start with "assert"
self.context.session.assertPerm = mock.MagicMock()
self.get_channel = mock.patch('kojihub.kojihub.get_channel').start()
self.UpdateProcessor = mock.patch('kojihub.kojihub.UpdateProcessor',
side_effect=self.getUpdate).start()

View file

@ -11,6 +11,10 @@ class TestGetGroupMembers(DBQueryTestCase):
super(TestGetGroupMembers, self).setUp()
self.get_user = mock.patch('kojihub.kojihub.get_user').start()
self.exports = kojihub.RootExports()
self.context = mock.patch('kojihub.kojihub.context').start()
# It seems MagicMock will not automatically handle attributes that
# start with "assert"
self.context.session.assertPerm = mock.MagicMock()
def tearDown(self):
mock.patch.stopall()

View file

@ -132,7 +132,8 @@ class TestHost(unittest.TestCase):
)
self.assertEqual(processor.call_args_list[2], update3)
def test_task_wait_check(self):
@mock.patch('kojihub.kojihub.context')
def test_task_wait_check(self, context):
self.query_execute.return_value = [{'id': 1, 'state': 1},
{'id': 2, 'state': 2},
{'id': 3, 'state': 3},

View file

@ -7,6 +7,7 @@ import kojihub
class TestWriteSignedRPM(unittest.TestCase):
def setUp(self):
self.context = mock.patch('kojihub.kojihub.context').start()
self.get_rpm = mock.patch('kojihub.kojihub.get_rpm').start()
def tearDown(self):