debian-koji/tests/test_hub/test_download_task_output.py
Yuming Zhu ca05418fb5 unittest: use unittest.mock instead of mock
because the absence of unittest.mock on python2.7, we still fallback to
mock
2024-10-23 16:35:30 +00:00

37 lines
1.4 KiB
Python

from unittest import mock
import unittest
import koji
import kojihub
class TestDownloadTaskOutput(unittest.TestCase):
def setUp(self):
self.exports = kojihub.RootExports()
self.exports.getVolume = mock.MagicMock()
self.task_id = 1
self.filename = 'test-file'
self.volumename = 'test-volume'
def tearDown(self):
mock.patch.stopall()
def test_size_wrong_type(self):
size = 'test-size'
with self.assertRaises(koji.ParameterError) as cm:
self.exports.downloadTaskOutput(self.task_id, self.filename, size=size)
self.assertEqual(f"Invalid type for value '{size}': {type(size)}, "
f"expected type <class 'int'>", str(cm.exception))
def test_volume_non_exist_wrong_type(self):
self.exports.getVolume.side_effect = koji.GenericError
with self.assertRaises(koji.GenericError):
self.exports.downloadTaskOutput(self.task_id, self.filename, volume=self.volumename)
def test_filename_wrong_format(self):
filename = '../test-file'
volumeinfo = {'id': 1, 'name': self.volumename}
self.exports.getVolume.return_value = volumeinfo
with self.assertRaises(koji.GenericError) as cm:
self.exports.downloadTaskOutput(self.task_id, filename, volume=self.volumename)
self.assertEqual(f"Invalid file name: {filename}", str(cm.exception))