#3382 www: archivelist and rpmlist raise error when imageID is unknown
Merged 13 days ago by tkopecek. Opened 2 months ago by jcupova.
jcupova/koji issue-3381  into  master

@@ -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')

@@ -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')

file modified
+9 -3
@@ -1915,7 +1915,10 @@ 

  

      elif imageID is not None:

          imageID = int(imageID)

-         values['image'] = server.getArchive(imageID)

+         image = server.getArchive(imageID)

+         values['image'] = image

+         if image is None:

+             raise koji.GenericError('unknown image ID: %i' % imageID)

          # If/When future image types are supported, add elifs here if needed.

          if type == 'image':

              kojiweb.util.paginateMethod(server, values, 'listRPMs',
@@ -1961,14 +1964,17 @@ 

              raise koji.GenericError('unrecognized type of archivelist')

      elif imageID is not None:

          imageID = int(imageID)

-         values['image'] = server.getArchive(imageID)

+         image = server.getArchive(imageID)

+         values['image'] = image

+         if image is None:

+             raise koji.GenericError('unknown image ID: %i' % imageID)

          # If/When future image types are supported, add elifs here if needed.

          if type == 'image':

              kojiweb.util.paginateMethod(server, values, 'listArchives', kw={'imageID': imageID},

                                          start=start, dataName='archives', prefix='archive',

                                          order=order)

          else:

-             raise koji.GenericError('unrecognized type of archivelist')

+             raise koji.GenericError('unrecognized type of image archivelist')

      else:

          # It is an error if neither buildrootID and imageID are defined.

          raise koji.GenericError('Both buildrootID and imageID are None')

rebased onto b6e2c0e6179c66f431344c88843545a494598838

2 months ago

rebased onto 3ee52c2

2 months ago

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

2 months ago

1 new commit added

  • koji download-task retry download file
2 months ago

1 new commit added

  • www: archivelist and rpmlist raise error when imageID is unknown
2 months ago

Metadata Update from @jobrauer:
- Pull-request tagged with: testing-done

17 days ago

Commit 9698772 fixes this pull-request

Pull-Request has been merged by tkopecek

13 days ago