createWinBuild returns an error when win info is empty, is not a dict or doesn't contain platform key createWinBuild returns an error when build info is string and build is not existing Fixes: https://pagure.io/koji/issue/1103 Fixes: https://pagure.io/koji/issue/1102
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
import unittest
|
|
|
|
import mock
|
|
|
|
import koji
|
|
import kojihub
|
|
|
|
IP = kojihub.InsertProcessor
|
|
|
|
|
|
class TestNewWinBuild(unittest.TestCase):
|
|
def setUp(self):
|
|
self.InsertProcessor = mock.patch('kojihub.InsertProcessor',
|
|
side_effect=self.getInsert).start()
|
|
self.inserts = []
|
|
self.insert_execute = mock.MagicMock()
|
|
|
|
self.build_info = {
|
|
'id': 100,
|
|
'name': 'test_name',
|
|
'version': 'test_version',
|
|
'release': 'test_release',
|
|
'epoch': 'test_epoch',
|
|
'owner': 'test_owner',
|
|
'extra': {'extra_key': 'extra_value'},
|
|
}
|
|
|
|
def getInsert(self, *args, **kwargs):
|
|
insert = IP(*args, **kwargs)
|
|
insert.execute = self.insert_execute
|
|
self.inserts.append(insert)
|
|
return insert
|
|
|
|
def test_empty_win_info(self):
|
|
win_info = {}
|
|
with self.assertRaises(koji.GenericError) as cm:
|
|
kojihub.new_win_build(self.build_info, win_info)
|
|
self.assertEqual("Windows info is empty", str(cm.exception))
|
|
self.assertEqual(len(self.inserts), 0)
|
|
|
|
def test_win_info_without_platform(self):
|
|
win_info = {
|
|
'test-key': 'test-value'
|
|
}
|
|
with self.assertRaises(koji.GenericError) as cm:
|
|
kojihub.new_win_build(self.build_info, win_info)
|
|
self.assertEqual("Windows info doesn't have mandatory platform key", str(cm.exception))
|
|
self.assertEqual(len(self.inserts), 0)
|
|
|
|
def test_wrong_format_win_info(self):
|
|
win_info = 'test-win-info'
|
|
with self.assertRaises(koji.GenericError) as cm:
|
|
kojihub.new_win_build(self.build_info, win_info)
|
|
self.assertEqual('Invalid type for win_info: %s' % type(win_info), str(cm.exception))
|
|
self.assertEqual(len(self.inserts), 0)
|