PR#4457: fix some mocking in unit tests
Merges #4457 https://pagure.io/koji/pull-request/4457 Fixes: #4458 https://pagure.io/koji/issue/4458 incorrect mocking in some unit tests
This commit is contained in:
commit
407b8ef1a9
3 changed files with 13 additions and 9 deletions
|
|
@ -149,7 +149,9 @@ class TestEnsureDraftBacklink(unittest.TestCase):
|
|||
|
||||
def find_files(dirpath):
|
||||
'''Find all files under dir, report relative paths'''
|
||||
for path, dirs, files in os.walk(dirpath):
|
||||
for path, dirs, files in os.walk(dirpath, topdown=True):
|
||||
# sort dirs in place for consistent traversal
|
||||
dirs.sort()
|
||||
for fn in sorted(dirs + files):
|
||||
yield os.path.relpath(os.path.join(path, fn), dirpath)
|
||||
|
||||
|
|
|
|||
|
|
@ -29,10 +29,13 @@ class TestKiwiBuildTask(unittest.TestCase):
|
|||
self.options.allowed_scms = 'allowed_scms'
|
||||
self.options.allowed_scms_use_config = False
|
||||
self.options.allowed_scms_use_policy = True
|
||||
kiwi.SCM = mock.MagicMock(side_effect=self.SCM)
|
||||
koji.ensuredir = mock.MagicMock()
|
||||
mock.patch.object(kiwi, 'SCM', side_effect=self.SCM).start()
|
||||
mock.patch('koji.ensuredir').start()
|
||||
self.task = kiwi.KiwiBuildTask(123, 'kiwiBuild', {}, self.session, self.options)
|
||||
|
||||
def tearDown(self):
|
||||
mock.patch.stopall()
|
||||
|
||||
def test_get_nrvp_invalid_xml(self):
|
||||
# missing file
|
||||
with self.assertRaises(koji.GenericError):
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ class TestCreateSideTagHub(unittest.TestCase):
|
|||
'id': 23,
|
||||
'name': 'username',
|
||||
}
|
||||
mock.patch('sidetag_hub.ALLOWED_SUFFIXES', new=['suffix', 'another']).start()
|
||||
mock.patch('sidetag_hub.NAME_TEMPLATE', new='{basetag}-sidetagTEST-{tag_id}').start()
|
||||
|
||||
def tearDown(self):
|
||||
mock.patch.stopall()
|
||||
|
|
@ -42,7 +44,7 @@ class TestCreateSideTagHub(unittest.TestCase):
|
|||
|
||||
def test_createsidetag_basic(self):
|
||||
self.query_executeOne.return_value = {'user_tags': 0}
|
||||
sidetag_name = 'base_tag-side-12346'
|
||||
sidetag_name = 'base_tag-sidetagTEST-12346'
|
||||
self.context.session.assertLogin = mock.MagicMock()
|
||||
self.context.session.user_id = 23
|
||||
self.get_user.return_value = self.user
|
||||
|
|
@ -72,17 +74,16 @@ class TestCreateSideTagHub(unittest.TestCase):
|
|||
|
||||
def test_createsidetag_template_valid_and_debuginfo(self):
|
||||
self.query_executeOne.return_value = {'user_tags': 0}
|
||||
sidetag_name = 'base_tag-sidetag-12346-suffix'
|
||||
sidetag_name = 'base_tag-sidetagTEST-12346-suffix'
|
||||
self.context.session.assertLogin = mock.MagicMock()
|
||||
self.context.session.user_id = 23
|
||||
self.get_user.return_value = self.user
|
||||
self.get_tag.return_value = self.basetag
|
||||
self.nextval.return_value = 12345
|
||||
self._create_tag.return_value = 12346
|
||||
sidetag_hub.ALLOWED_SUFFIXES = ['suffix', 'another']
|
||||
sidetag_hub.NAME_TEMPLATE = '{basetag}-sidetag-{tag_id}'
|
||||
|
||||
ret = sidetag_hub.createSideTag('base_tag', debuginfo=True, suffix='suffix')
|
||||
|
||||
self.assertEqual(ret, {'name': sidetag_name, 'id': 12346, 'task_id': None, 'request': None})
|
||||
|
||||
def test_createsidetag_template_forbidden_suffix(self):
|
||||
|
|
@ -104,8 +105,6 @@ class TestCreateSideTagHub(unittest.TestCase):
|
|||
self.context.session.user_id = 23
|
||||
self.get_user.return_value = self.user
|
||||
self.get_tag.return_value = self.basetag
|
||||
sidetag_hub.ALLOWED_SUFFIXES = ['suffix', 'another']
|
||||
sidetag_hub.NAME_TEMPLATE = '{basetag}-sidetag-{tag_id}'
|
||||
|
||||
with self.assertRaises(koji.GenericError) as ex:
|
||||
sidetag_hub.createSideTag('base_tag', suffix='suffix')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue