PR#4082: More mocking cleanup

Merges #4082
https://pagure.io/koji/pull-request/4082
This commit is contained in:
Tomas Kopecek 2024-06-04 12:55:04 +02:00
commit 2b45e9889e
20 changed files with 45 additions and 1 deletions

View file

@ -339,7 +339,7 @@ Default behavior without --all option downloads .rpm files only for build and bu
self.download_file.assert_not_called()
def test_handle_download_parent_not_finished(self):
args = [str(self.parent_task_id)]
args = [str(self.parent_task_id), '--nowait']
self.session.getTaskInfo.return_value = {
'id': self.parent_task_id,
'method': 'buildArch',

View file

@ -36,6 +36,7 @@ class TestGetOptions(unittest.TestCase):
koji.BASEDIR = self.orig_basedir
koji.pathinfo.topdir = self.orig_pathinfo_topdir
cli.load_plugins = self.orig_load_plugins
mock.patch.stopall()
def test_get_options(self):
self.read_config.return_value = self.config_dict

View file

@ -50,6 +50,7 @@ class TestHostinfo(utils.CliTestCase):
else:
os.environ['TZ'] = self.original_timezone
time.tzset()
mock.patch.stopall()
def test_hostinfo_without_option(self):
self.session.getChannel.return_value = None

View file

@ -42,6 +42,7 @@ class TestListExternalRepo(utils.CliTestCase):
else:
os.environ['TZ'] = self.original_timezone
time.tzset()
mock.patch.stopall()
def test_list_external_repos_with_args(self):
arguments = ['arg']

View file

@ -46,6 +46,7 @@ class TestListHosts(utils.CliTestCase):
else:
os.environ['TZ'] = self.original_timezone
time.tzset()
mock.patch.stopall()
def __vm(self, result):
m = koji.VirtualCall('mcall_method', [], {})

View file

@ -85,6 +85,7 @@ class TestCliListTagged(utils.CliTestCase):
else:
os.environ['TZ'] = self.original_timezone
time.tzset()
mock.patch.stopall()
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.util.eventFromOpts', return_value={'id': 1000,

View file

@ -12,6 +12,9 @@ class TestGetBuild(DBQueryTestCase):
self.find_build_id = mock.patch('kojihub.kojihub.find_build_id').start()
self.lookup_name = mock.patch('kojihub.kojihub.lookup_name').start()
def tearDown(self):
mock.patch.stopall()
def test_non_exist_build_string_with_strict(self):
build = 'build-1-23'
self.find_build_id.side_effect = koji.GenericError('No such build: %s' % build)

View file

@ -20,6 +20,9 @@ class TestGetBuildTargets(DBQueryTestCase):
self.build_tag_id = 1
self.dest_tag_id = 2
def tearDown(self):
mock.patch.stopall()
def test_get_build_targets_strings(self):
self.name_or_id_clause.return_value = '(build_target.name = %(build_target_name)s)', \
{'build_target_name': 'build-target-url'}

View file

@ -14,6 +14,9 @@ class TestGetBuildType(DBQueryTestCase):
self.get_win_build = mock.patch('kojihub.kojihub.get_win_build').start()
self.get_image_build = mock.patch('kojihub.kojihub.get_image_build').start()
def tearDown(self):
mock.patch.stopall()
def test_no_build(self):
self.get_build.return_value = None

View file

@ -12,6 +12,9 @@ class TestGetChannel(DBQueryTestCase):
self.context = mock.patch('kojihub.kojihub.context').start()
self.exports = kojihub.RootExports()
def tearDown(self):
mock.patch.stopall()
def test_wrong_type_channelInfo(self):
# dict
channel_info = {'channel': 'val'}

View file

@ -12,6 +12,9 @@ class TestGetGroupMembers(DBQueryTestCase):
self.get_user = mock.patch('kojihub.kojihub.get_user').start()
self.exports = kojihub.RootExports()
def tearDown(self):
mock.patch.stopall()
def test_non_exist_group(self):
group = 'test-group'
self.get_user.return_value = []

View file

@ -11,6 +11,9 @@ class TestGetImageBuild(DBQueryTestCase):
self.maxDiff = None
self.find_build_id = mock.patch('kojihub.kojihub.find_build_id').start()
def tearDown(self):
mock.patch.stopall()
def test_build_id_not_found(self):
self.find_build_id.return_value = None
result = kojihub.get_image_build('test-build.1-23.1')

View file

@ -11,6 +11,9 @@ class TestGetMavenBuild(DBQueryTestCase):
self.maxDiff = None
self.find_build_id = mock.patch('kojihub.kojihub.find_build_id').start()
def tearDown(self):
mock.patch.stopall()
def test_build_id_not_found(self):
self.find_build_id.return_value = None
result = kojihub.get_maven_build('test-build.1-23.1')

View file

@ -12,6 +12,9 @@ class TestGetNextRelease(DBQueryTestCase):
self.get_build = mock.patch('kojihub.kojihub.get_build').start()
self.binfo = {'name': 'name', 'version': 'version'}
def tearDown(self):
mock.patch.stopall()
def test_get_next_release_new(self):
# no previous build
self.qp_execute_one_return_value = None

View file

@ -14,6 +14,9 @@ class TestGetSessionInfo(DBQueryTestCase):
self.userinfo = {'id': 123, 'name': 'testuser'}
self.exports.getLoggedInUser = mock.MagicMock()
def tearDown(self):
mock.patch.stopall()
def test_get_session_info_not_logged(self):
self.context.session.logged_in = False
result = self.exports.getSessionInfo()

View file

@ -19,6 +19,9 @@ class TestGetTagExternalRepos(DBQueryTestCase):
self.build_tag_info = {'id': 111, 'name': self.build_tag}
self.repo_info = {'id': 123, 'name': self.repo}
def tearDown(self):
mock.patch.stopall()
def test_valid(self):
self.get_tag.return_value = self.build_tag_info
self.get_external_repo.return_value = self.repo_info

View file

@ -15,6 +15,9 @@ class TestGetUser(DBQueryTestCase):
self.list_user_krb_principals = mock.patch(
'kojihub.kojihub.list_user_krb_principals').start()
def tearDown(self):
mock.patch.stopall()
def test_wrong_format_user_info(self):
userinfo = ['test-user']
with self.assertRaises(koji.GenericError) as cm:

View file

@ -11,6 +11,9 @@ class TestGetWinBuild(DBQueryTestCase):
self.maxDiff = None
self.find_build_id = mock.patch('kojihub.kojihub.find_build_id').start()
def tearDown(self):
mock.patch.stopall()
def test_build_id_not_found(self):
self.find_build_id.return_value = None
result = kojihub.get_win_build('test-build.1-23.1')

View file

@ -33,6 +33,7 @@ class TestQueryProcessor(unittest.TestCase):
def tearDown(self):
kojihub.QueryProcessor.iterchunksize = self.original_chunksize
mock.patch.stopall()
def test_basic_instantiation(self):
kojihub.QueryProcessor() # No exception!

View file

@ -42,6 +42,8 @@ extra_limit = 2048
if hasattr(context, 'protonmsg_msgs'):
del context.protonmsg_msgs
del self.conf
mock.patch.stopall()
def assertMsg(self, topic, body=None, **kws):
self.assertTrue(hasattr(context, 'protonmsg_msgs'))