updated tests
This commit is contained in:
parent
d1ab4ed287
commit
7eb264eb4c
3 changed files with 67 additions and 36 deletions
|
|
@ -27,34 +27,37 @@ class TestSaveFailedTree(unittest.TestCase):
|
|||
|
||||
@mock.patch('os.unlink')
|
||||
@mock.patch('tarfile.open')
|
||||
def testNonExistentTask(self, tarfile, os_unlink):
|
||||
# empty tarball
|
||||
def testNonExistentBuildroot(self, tarfile, os_unlink):
|
||||
tfile = mock.MagicMock(name='tfile')
|
||||
tarfile.return_value = tfile
|
||||
self.session.getBuildroot.return_value = None
|
||||
|
||||
self.t.handler(1)
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.t.handler(1)
|
||||
self.assertTrue('Nonexistent buildroot' in str(cm.exception))
|
||||
|
||||
tarfile.assert_called_once_with(
|
||||
'/tmp/nonexistentdirectory/tasks/123/123/broots-task-1.tar.gz',
|
||||
'w:gz'
|
||||
)
|
||||
tarfile.assert_not_called()
|
||||
tfile.add.assert_not_called()
|
||||
tfile.close.assert_called_once_with()
|
||||
os_unlink.assert_called_once_with('/tmp/nonexistentdirectory/tasks/123/123/broots-task-1.tar.gz')
|
||||
tfile.close.assert_not_called()
|
||||
os_unlink.assert_not_called()
|
||||
|
||||
@mock.patch('os.path.exists')
|
||||
@mock.patch('os.unlink')
|
||||
@mock.patch('tarfile.open')
|
||||
def testCorrect(self, tarfile, os_unlink):
|
||||
def testCorrect(self, tarfile, os_unlink, os_exists):
|
||||
def getBuildroot(bid):
|
||||
tmp = {
|
||||
'tag_name': 'tag_name',
|
||||
'repo_id': 'repo_id',
|
||||
'host_id': 1,
|
||||
}
|
||||
if bid == 1:
|
||||
tmp['id'] = 1
|
||||
tmp['task_id'] = 1000
|
||||
tmp['arch'] = 'x86_64'
|
||||
tmp['tag_id'] = 5000
|
||||
elif bid == 2:
|
||||
tmp['id'] = 2
|
||||
tmp['task_id'] = 1001
|
||||
tmp['arch'] = 'i386'
|
||||
tmp['tag_id'] = 5001
|
||||
|
|
@ -64,20 +67,19 @@ class TestSaveFailedTree(unittest.TestCase):
|
|||
tfile = mock.MagicMock(name='tfile')
|
||||
tfile.add = mock.MagicMock()
|
||||
tarfile.return_value = tfile
|
||||
# simplified return values, only id should be used
|
||||
self.session.listBuildroots.return_value = [{'id': 1, 'host_id': 1}, {'id': 2, 'host_id': 1}]
|
||||
os_exists.return_value = True
|
||||
|
||||
self.t.handler(1)
|
||||
|
||||
tarfile.assert_called_once_with(
|
||||
'/tmp/nonexistentdirectory/tasks/123/123/broots-task-1.tar.gz',
|
||||
'/tmp/nonexistentdirectory/tasks/123/123/broot-1.tar.gz',
|
||||
'w:gz'
|
||||
)
|
||||
|
||||
tfile.add.assert_called_once()
|
||||
self.assertEqual(tfile.add.call_args_list[0][0][0], '/tmp/mockdir/tag_name-1-repo_id/root/builddir')
|
||||
self.assertEqual(tfile.add.call_args_list[1][0][0], '/tmp/mockdir/tag_name-2-repo_id/root/builddir')
|
||||
self.assertEqual(len(tfile.add.call_args_list), 2)
|
||||
tfile.close.assert_called_once_with()
|
||||
os_unlink.assert_called_once_with('/tmp/nonexistentdirectory/tasks/123/123/broots-task-1.tar.gz')
|
||||
os_unlink.assert_called_once_with('/tmp/nonexistentdirectory/tasks/123/123/broot-1.tar.gz')
|
||||
|
||||
@mock.patch('os.unlink')
|
||||
@mock.patch('tarfile.open')
|
||||
|
|
@ -86,12 +88,15 @@ class TestSaveFailedTree(unittest.TestCase):
|
|||
tmp = {
|
||||
'tag_name': 'tag_name',
|
||||
'repo_id': 'repo_id',
|
||||
'host_id': 2000,
|
||||
}
|
||||
if bid == 1:
|
||||
tmp['id'] = 1
|
||||
tmp['task_id'] = 1000
|
||||
tmp['arch'] = 'x86_64'
|
||||
tmp['tag_id'] = 5000
|
||||
elif bid == 2:
|
||||
tmp['id'] = 2
|
||||
tmp['task_id'] = 1001
|
||||
tmp['arch'] = 'i386'
|
||||
tmp['tag_id'] = 5001
|
||||
|
|
@ -100,8 +105,6 @@ class TestSaveFailedTree(unittest.TestCase):
|
|||
self.session.getBuildroot.side_effect = getBuildroot
|
||||
tfile = mock.MagicMock(name='tfile')
|
||||
tarfile.return_value = tfile
|
||||
# simplified return values, only id should be used
|
||||
self.session.listBuildroots.return_value = [{'id': 1, 'host_id': 2}, {'id': 2, 'host_id': 2}]
|
||||
|
||||
with self.assertRaises(koji.GenericError):
|
||||
self.t.handler(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue