www: archivelist and rpmlist raise error when imageID is unknown
Fixes: https://pagure.io/koji/issue/3381
This commit is contained in:
parent
22882bff32
commit
c1e669111f
3 changed files with 145 additions and 3 deletions
68
tests/test_www/test_archivelist.py
Normal file
68
tests/test_www/test_archivelist.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import unittest
|
||||
import koji
|
||||
|
||||
import mock
|
||||
from .loadwebindex import webidx
|
||||
|
||||
|
||||
class TestArchiveList(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.get_server = mock.patch.object(webidx, "_getServer").start()
|
||||
self.assert_login = mock.patch.object(webidx, "_assertLogin").start()
|
||||
self.server = mock.MagicMock()
|
||||
self.environ = {
|
||||
'koji.options': {
|
||||
'SiteName': 'test',
|
||||
'KojiFilesURL': 'https://server.local/files',
|
||||
},
|
||||
'koji.currentUser': None
|
||||
}
|
||||
self.buildroot_id = '1'
|
||||
self.image_id = '2'
|
||||
|
||||
def tearDown(self):
|
||||
mock.patch.stopall()
|
||||
|
||||
def test_archivelist_exception_unknown_buildroot_id(self):
|
||||
"""Test archivelist function raises exception when buildroot_id is unknown."""
|
||||
self.get_server.return_value = self.server
|
||||
self.server.getBuildroot.return_value = None
|
||||
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
webidx.archivelist(self.environ, type='component', buildrootID=self.buildroot_id)
|
||||
self.assertEqual(str(cm.exception), f'unknown buildroot ID: {self.buildroot_id}')
|
||||
|
||||
def test_archivelist_exception_unknown_archivetype(self):
|
||||
"""Test archivelist function raises exception when buildroot type is wrong type."""
|
||||
self.get_server.return_value = self.server
|
||||
self.server.getBuildroot.return_value = {'id': int(self.buildroot_id)}
|
||||
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
webidx.archivelist(self.environ, type='non-exist', buildrootID=self.buildroot_id)
|
||||
self.assertEqual(str(cm.exception), 'unrecognized type of archivelist')
|
||||
|
||||
def test_archivelist_exception_unknown_image_id(self):
|
||||
"""Test archivelist function raises exception when image_id is unknown."""
|
||||
self.get_server.return_value = self.server
|
||||
self.server.getArchive.return_value = None
|
||||
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
webidx.archivelist(self.environ, type='image', imageID=self.image_id)
|
||||
self.assertEqual(str(cm.exception), f'unknown image ID: {self.image_id}')
|
||||
|
||||
def test_archivelist_exception_unknown_image_type(self):
|
||||
"""Test archivelist function raises exception when image type is unknown."""
|
||||
self.get_server.return_value = self.server
|
||||
self.server.getArchive.return_value = {'id': int(self.image_id)}
|
||||
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
webidx.archivelist(self.environ, type='non-exist', imageID=self.image_id)
|
||||
self.assertEqual(str(cm.exception), 'unrecognized type of image archivelist')
|
||||
|
||||
def test_archivelist_exception_buildroot_and_image_none(self):
|
||||
"""Test archivelist function raises exception when buildroot and image is None."""
|
||||
self.get_server.return_value = self.server
|
||||
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
webidx.archivelist(self.environ, type='non-exist')
|
||||
self.assertEqual(str(cm.exception), 'Both buildrootID and imageID are None')
|
||||
68
tests/test_www/test_rpmlist.py
Normal file
68
tests/test_www/test_rpmlist.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import unittest
|
||||
import koji
|
||||
|
||||
import mock
|
||||
from .loadwebindex import webidx
|
||||
|
||||
|
||||
class TestRpmList(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.get_server = mock.patch.object(webidx, "_getServer").start()
|
||||
self.assert_login = mock.patch.object(webidx, "_assertLogin").start()
|
||||
self.server = mock.MagicMock()
|
||||
self.environ = {
|
||||
'koji.options': {
|
||||
'SiteName': 'test',
|
||||
'KojiFilesURL': 'https://server.local/files',
|
||||
},
|
||||
'koji.currentUser': None
|
||||
}
|
||||
self.buildroot_id = '1'
|
||||
self.image_id = '2'
|
||||
|
||||
def tearDown(self):
|
||||
mock.patch.stopall()
|
||||
|
||||
def test_rpmlist_exception_unknown_buildroot_id(self):
|
||||
"""Test rpmlist function raises exception when buildroot_id is unknown."""
|
||||
self.get_server.return_value = self.server
|
||||
self.server.getBuildroot.return_value = None
|
||||
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
webidx.rpmlist(self.environ, type='component', buildrootID=self.buildroot_id)
|
||||
self.assertEqual(str(cm.exception), f'unknown buildroot ID: {self.buildroot_id}')
|
||||
|
||||
def test_rpmlist_exception_wrong_type(self):
|
||||
"""Test rpmlist function raises exception when buildroot type is wrong type."""
|
||||
self.get_server.return_value = self.server
|
||||
self.server.getBuildroot.return_value = {'id': int(self.buildroot_id)}
|
||||
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
webidx.rpmlist(self.environ, type='non-exist', buildrootID=self.buildroot_id)
|
||||
self.assertEqual(str(cm.exception), 'unrecognized type of rpmlist')
|
||||
|
||||
def test_rpmlist_exception_unknown_image_id(self):
|
||||
"""Test rpmlist function raises exception when image_id is unknown."""
|
||||
self.get_server.return_value = self.server
|
||||
self.server.getArchive.return_value = None
|
||||
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
webidx.rpmlist(self.environ, type='image', imageID=self.image_id)
|
||||
self.assertEqual(str(cm.exception), f'unknown image ID: {self.image_id}')
|
||||
|
||||
def test_rpmlist_exception_unknown_image_type(self):
|
||||
"""Test rpmlist function raises exception when image type is unknown."""
|
||||
self.get_server.return_value = self.server
|
||||
self.server.getArchive.return_value = {'id': int(self.image_id)}
|
||||
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
webidx.rpmlist(self.environ, type='non-exist', imageID=self.image_id)
|
||||
self.assertEqual(str(cm.exception), 'unrecognized type of image rpmlist')
|
||||
|
||||
def test_rpmlist_exception_buildroot_and_image_none(self):
|
||||
"""Test rpmlist function raises exception when buildroot and image is None."""
|
||||
self.get_server.return_value = self.server
|
||||
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
webidx.rpmlist(self.environ, type='non-exist')
|
||||
self.assertEqual(str(cm.exception), 'Both buildrootID and imageID are None')
|
||||
Loading…
Add table
Add a link
Reference in a new issue