fix missing tearDown methods for numerous tests

This commit is contained in:
Mike McLean 2024-03-29 19:41:03 -04:00 committed by Tomas Kopecek
parent a807137c3c
commit f49ee80a7b
38 changed files with 109 additions and 2 deletions

View file

@ -12,6 +12,9 @@ class TestAddGroupMember(unittest.TestCase):
self.exports = kojihub.RootExports()
self.get_user = mock.patch('kojihub.kojihub.get_user').start()
def tearDown(self):
mock.patch.stopall()
def test_non_exist_user(self):
data = [{'id': 3,
'name': 'test-group',

View file

@ -19,6 +19,9 @@ class TestAddVolume(unittest.TestCase):
self.context.session.assertPerm = mock.MagicMock()
self.context.session.assertLogin = mock.MagicMock()
def tearDown(self):
mock.patch.stopall()
def test_add_volume_wrong_format(self):
volume_name = 'volume-name+'

View file

@ -18,6 +18,9 @@ class TestCreateImageBuild(unittest.TestCase):
self.inserts = []
self.insert_execute = mock.MagicMock()
def tearDown(self):
mock.patch.stopall()
def getInsert(self, *args, **kwargs):
insert = IP(*args, **kwargs)
insert.execute = self.insert_execute

View file

@ -32,6 +32,9 @@ class TestCreateMavenBuild(unittest.TestCase):
}
self.build_info = 'test-build-11-12'
def tearDown(self):
mock.patch.stopall()
def getInsert(self, *args, **kwargs):
insert = IP(*args, **kwargs)
insert.execute = self.insert_execute

View file

@ -24,6 +24,9 @@ class TestCreateUser(unittest.TestCase):
self.user_info_krb = {'id': 1, 'krb_principals': ['test_user@fedora.org'],
'name': self.user_name, 'status': 0, 'usertype': 0}
def tearDown(self):
mock.patch.stopall()
def test_create_user_wrong_format(self):
user_name = 'test-user+'

View file

@ -32,6 +32,9 @@ class TestCreateWinBuild(unittest.TestCase):
}
self.build_info = 'test-build-11-12'
def tearDown(self):
mock.patch.stopall()
def getInsert(self, *args, **kwargs):
insert = IP(*args, **kwargs)
insert.execute = self.insert_execute

View file

@ -28,6 +28,9 @@ class TestDeleteBuildTarget(unittest.TestCase):
# start with "assert"
self.context_db.session.assertLogin = mock.MagicMock()
def tearDown(self):
mock.patch.stopall()
def test_non_exist_target(self):
build_target = 'build-target'
self.lookup_build_target.return_value = None

View file

@ -24,6 +24,9 @@ class TestDisableChannel(unittest.TestCase):
self.updates = []
self.channelname = 'test-channel'
def tearDown(self):
mock.patch.stopall()
def test_non_exist_channel(self):
self.get_channel.return_value = None
with self.assertRaises(koji.GenericError) as cm:

View file

@ -12,6 +12,9 @@ class TestDisableUser(unittest.TestCase):
self.exports = kojihub.RootExports()
self.get_user = mock.patch('kojihub.kojihub.get_user').start()
def tearDown(self):
mock.patch.stopall()
def test_non_exist_user(self):
username = 'test-user'
self.get_user.return_value = None

View file

@ -24,6 +24,9 @@ class TestEditPermission(unittest.TestCase):
self.perm_info = {'id': 1, 'name': self.perm_name}
self.description = 'test-description'
def tearDown(self):
mock.patch.stopall()
def test_edit_permission_non_exist_permission(self):
self.lookup_perm.side_effect = koji.GenericError
with self.assertRaises(koji.GenericError):

View file

@ -24,6 +24,9 @@ class TestEnableChannel(unittest.TestCase):
self.updates = []
self.channelname = 'test-channel'
def tearDown(self):
mock.patch.stopall()
def test_non_exist_channel(self):
self.get_channel.return_value = None

View file

@ -12,6 +12,9 @@ class TestEnableUser(unittest.TestCase):
self.exports = kojihub.RootExports()
self.get_user = mock.patch('kojihub.kojihub.get_user').start()
def tearDown(self):
mock.patch.stopall()
def test_non_exist_user(self):
username = 'test-user'
self.get_user.return_value = None

View file

@ -24,6 +24,9 @@ class TestFindBuildId(unittest.TestCase):
self.queries = []
self.query_singleValue = mock.MagicMock()
def tearDown(self):
mock.patch.stopall()
def test_non_exist_build_dict(self):
build = {
'name': 'test_name',

View file

@ -11,6 +11,9 @@ class TestGetRPMDeps(unittest.TestCase):
self.get_rpm = mock.patch('kojihub.kojihub.get_rpm').start()
self.get_build = mock.patch('kojihub.kojihub.get_build').start()
def tearDown(self):
mock.patch.stopall()
def test_getRPMDeps_no_rpminfo(self):
def mock_get_rpm(rpmID, strict=False):
if strict:

View file

@ -10,6 +10,9 @@ class TestGetBuildNotifications(unittest.TestCase):
self.get_user = mock.patch('kojihub.kojihub.get_user').start()
self.get_build_notifications = mock.patch('kojihub.kojihub.get_build_notifications').start()
def tearDown(self):
mock.patch.stopall()
def test_loggedin_user(self):
self.get_user.return_value = {'id': 1}
kojihub.RootExports().getBuildNotifications(None)

View file

@ -10,6 +10,9 @@ class TestGetBuildroot(unittest.TestCase):
self.query_buildroots = mock.patch('kojihub.kojihub.query_buildroots').start()
self.buildroot_id = 1
def tearDown(self):
mock.patch.stopall()
def test_empty_buildroots_without_strict(self):
self.query_buildroots.return_value = []
rv = kojihub.get_buildroot(self.buildroot_id, strict=False)

View file

@ -17,6 +17,9 @@ class TestGetChangelogEntries(unittest.TestCase):
self.cursor = mock.MagicMock()
self.os_path_exists = mock.patch('os.path.exists').start()
def tearDown(self):
mock.patch.stopall()
def test_non_exist_build(self):
build_id = 1
self.cursor.fetchone.return_value = None

View file

@ -12,6 +12,9 @@ class TestGetExternalRepo(unittest.TestCase):
self.get_external_repos = mock.patch('kojihub.kojihub.get_external_repos').start()
self.exports = kojihub.RootExports()
def tearDown(self):
mock.patch.stopall()
def test_non_exist_repo_with_strict(self):
repo = 'test-repo'
self.get_external_repos.return_value = []

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

@ -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 TestGetVolume(unittest.TestCase):
self.exports = kojihub.RootExports()
self.lookup_name = mock.patch('kojihub.kojihub.lookup_name').start()
def tearDown(self):
mock.patch.stopall()
def test_non_exist_volume_with_strict(self):
volume = ['test-volume']
self.lookup_name.return_value = None

View file

@ -32,6 +32,9 @@ class TestGrantPermission(unittest.TestCase):
'status': 0, 'usertype': 0}
self.perm_info = {'id': 1, 'name': self.perms_name}
def tearDown(self):
mock.patch.stopall()
def test_grant_permission_wrong_format(self):
perms_name = 'test-perms+'

View file

@ -61,6 +61,9 @@ class TestGroupPkglist(unittest.TestCase):
self.context_db.event_id = 42
self.context_db.session.user_id = 24
def tearDown(self):
mock.patch.stopall()
def test_grp_pkg_add_previous_changed(self):
self.lookup_tag.return_value = self.taginfo
self.lookup_group.return_value = self.groupinfo

View file

@ -61,6 +61,9 @@ class TestGroupReqlist(unittest.TestCase):
self.context_db.event_id = 42
self.context_db.session.user_id = 24
def tearDown(self):
mock.patch.stopall()
def test_grp_req_add_not_previous(self):
self.lookup_tag.return_value = self.taginfo
self.lookup_group.side_effect = [self.groupinfo, self.reqinfo]

View file

@ -22,6 +22,7 @@ class TestImportImageInternal(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.tempdir)
mock.patch.stopall()
def test_basic(self):
task = mock.MagicMock()

View file

@ -86,6 +86,9 @@ class TestListBuilds(unittest.TestCase):
'volume_name': 'DEFAULT',
'draft': False},]
def tearDown(self):
mock.patch.stopall()
def test_wrong_package(self):
package = 'test-package'
self.get_package_id.return_value = None

View file

@ -27,6 +27,9 @@ class TestListTagged(unittest.TestCase):
'release': '1.fc35', 'state': 1, 'tag_id': 1, 'tag_name': 'test-tag',
'task_id': None, 'version': '2.52', 'volume_id': 0, 'volume_name': 'DEFAULT'}]
def tearDown(self):
mock.patch.stopall()
def getQuery(self, *args, **kwargs):
query = QP(*args, **kwargs)
query.execute = mock.MagicMock()

View file

@ -48,6 +48,9 @@ class TestListTaggedArchives(unittest.TestCase):
'volume_name': 'DEFAULT'}]
]
def tearDown(self):
mock.patch.stopall()
def getQuery(self, *args, **kwargs):
query = QP(*args, **kwargs)
query.execute = mock.MagicMock()

View file

@ -47,6 +47,9 @@ class TestListTaggedRPMS(unittest.TestCase):
'volume_name': 'DEFAULT'}]
]
def tearDown(self):
mock.patch.stopall()
def getQuery(self, *args, **kwargs):
query = QP(*args, **kwargs)
query.execute = mock.MagicMock()

View file

@ -15,6 +15,9 @@ class DummyExports(object):
class TestMulticall(unittest.TestCase):
def tearDown(self):
mock.patch.stopall()
def test_multicall(self):
self.context_db = mock.patch('kojihub.db.context').start()
kojixmlrpc.kojihub = mock.MagicMock()

View file

@ -26,6 +26,9 @@ class TestNewMavenBuild(unittest.TestCase):
'build_id': 2,
}
def tearDown(self):
mock.patch.stopall()
def getInsert(self, *args, **kwargs):
insert = IP(*args, **kwargs)
insert.execute = self.insert_execute

View file

@ -31,6 +31,9 @@ class TestNewWinBuild(unittest.TestCase):
'extra': {'extra_key': 'extra_value'},
}
def tearDown(self):
mock.patch.stopall()
def getInsert(self, *args, **kwargs):
insert = IP(*args, **kwargs)
insert.execute = self.insert_execute

View file

@ -20,6 +20,9 @@ class TestQueryBuildroots(unittest.TestCase):
self.queries = []
self.query_execute = mock.MagicMock()
def tearDown(self):
mock.patch.stopall()
def test_query_buildroots(self):
self.query_execute.side_effect = [[7], [7], [7], []]
self.repo_references.return_value = [{'id': 7, 'host_id': 1, 'create_event': 333,

View file

@ -35,6 +35,9 @@ class TestQueryRPMSigs(unittest.TestCase):
'size': 25644,
'version': '3.3'}
def tearDown(self):
mock.patch.stopall()
def test_rpm_dict(self):
rinfo_dict = {
'arch': 'x86_64',

View file

@ -14,6 +14,9 @@ class TestRestartHosts(unittest.TestCase):
self.context.session.assertPerm = mock.MagicMock()
self.make_task = mock.patch('kojihub.kojihub.make_task').start()
def tearDown(self):
mock.patch.stopall()
def test_options_is_none(self):
self.make_task.return_value = 13
rv = self.exports.restartHosts()

View file

@ -23,6 +23,9 @@ class TestSetUserStatus(unittest.TestCase):
self.context.session.assertPerm = mock.MagicMock()
self.update_execute = mock.MagicMock()
def tearDown(self):
mock.patch.stopall()
def test_wrong_status(self):
status = 111
with self.assertRaises(koji.GenericError) as cm:

View file

@ -15,6 +15,9 @@ class TestVerifyNameInternal(unittest.TestCase):
self.context.opts = {'MaxNameLengthInternal': 15,
'RegexNameInternal.compiled': re.compile('^[A-Za-z0-9/_.+-]+$')}
def tearDown(self):
mock.patch.stopall()
def test_verify_name_internal_integer_type(self):
expected_error = "Name should be string"
with self.assertRaises(koji.GenericError) as cm:

View file

@ -28,7 +28,6 @@ def get_qp_init(testcase):
class DBQueryTestCase(unittest.TestCase):
def setUp(self):
mock.patch.stopall()
self.qp_execute_return_value = []
self.qp_execute_side_effect = None
self.qp_execute_one_return_value = []
@ -44,7 +43,6 @@ class DBQueryTestCase(unittest.TestCase):
def tearDown(self):
mock.patch.stopall()
self.reset_query()
def reset_query(self):
del self.queries[:]