#2732 api: createImageBuild non-existing build wrong buildinfo
Merged a year ago by tkopecek. Opened a year ago by jcupova.
jcupova/koji issue1106  into  master

file modified
+17 -3
@@ -10754,13 +10754,27 @@ 

  

      def createImageBuild(self, build_info):

          """

-         Associate image metadata with an existing build. The build must not

-         already have associated image metadata.

+         Associate image metadata with an existing build. When build isn`t existing, creates a

+         build. The build must not already have associated image metadata.

+ 

+         :param build_info: a str (build name) if build is existing

+                            or a dict:

+                                - name: build name

+                                - version: build version

+                                - release: build release

+                                - epoch: build epoch

+         :raises: GenericError if type for build_info is not dict, when build isn`t existing.

+         :raises: GenericError if build info doesn't have mandatory keys.

          """

          context.session.assertPerm('image-import')

          build = get_build(build_info)

          if not build:

-             build_id = new_build(dslice(build_info, ('name', 'version', 'release', 'epoch')))

+             if not isinstance(build_info, dict):

+                 raise koji.GenericError('Invalid type for build_info: %s' % type(build_info))

+             try:

+                 build_id = new_build(dslice(build_info, ('name', 'version', 'release', 'epoch')))

+             except KeyError as cm:

+                 raise koji.GenericError("Build info doesn't have mandatory %s key" % cm)

              build = get_build(build_id, strict=True)

          new_image_build(build)

  

@@ -0,0 +1,86 @@ 

+ import unittest

+ 

+ import mock

+ 

+ import koji

+ import kojihub

+ 

+ IP = kojihub.InsertProcessor

+ 

+ 

+ class TestCreateImageBuild(unittest.TestCase):

+ 

+     def setUp(self):

+         self.get_build = mock.patch('kojihub.get_build').start()

+         self.exports = kojihub.RootExports()

+         self.InsertProcessor = mock.patch('kojihub.InsertProcessor',

+                                           side_effect=self.getInsert).start()

+         self.inserts = []

+         self.insert_execute = mock.MagicMock()

+ 

+     def getInsert(self, *args, **kwargs):

+         insert = IP(*args, **kwargs)

+         insert.execute = self.insert_execute

+         self.inserts.append(insert)

+         return insert

+ 

+     def test_empty_wrong_format_non_exist_build_info(self):

+         build_info = 'test-build-11-12'

+         self.get_build.return_value = None

+         with self.assertRaises(koji.GenericError) as cm:

+             self.exports.createImageBuild(build_info)

+         self.assertEqual('Invalid type for build_info: %s' % type(build_info), str(cm.exception))

+         self.assertEqual(len(self.inserts), 0)

+ 

+     def test_build_info_without_some_mandatory_key(self):

+         # build_info without name

+         get_build_info = {

+             'id': 100,

+             'version': 'test_version',

+             'release': 'test_release',

+             'epoch': 'test_epoch',

+         }

+         self.get_build.return_value = None

+         with self.assertRaises(koji.GenericError) as cm:

+             self.exports.createImageBuild(get_build_info)

+         self.assertEqual("Build info doesn't have mandatory 'name' key", str(cm.exception))

+         self.assertEqual(len(self.inserts), 0)

+ 

+         # build_info without version

+         get_build_info = {

+             'id': 100,

+             'name': 'test_name',

+             'release': 'test_release',

+             'epoch': 'test_epoch',

+         }

+         self.get_build.return_value = None

+         with self.assertRaises(koji.GenericError) as cm:

+             self.exports.createImageBuild(get_build_info)

+         self.assertEqual("Build info doesn't have mandatory 'version' key", str(cm.exception))

+         self.assertEqual(len(self.inserts), 0)

+ 

+         # build_info without release

+         get_build_info = {

+             'id': 100,

+             'name': 'test_name',

+             'version': 'test_version',

+             'epoch': 'test_epoch',

+         }

+         self.get_build.return_value = None

+         with self.assertRaises(koji.GenericError) as cm:

+             self.exports.createImageBuild(get_build_info)

+         self.assertEqual("Build info doesn't have mandatory 'release' key", str(cm.exception))

+         self.assertEqual(len(self.inserts), 0)

+ 

+         # build_info without epoch

+         get_build_info = {

+             'id': 100,

+             'name': 'test_name',

+             'version': 'test_version',

+             'release': 'test_release',

+         }

+         self.get_build.return_value = None

+         with self.assertRaises(koji.GenericError) as cm:

+             self.exports.createImageBuild(get_build_info)

+         self.assertEqual("Build info doesn't have mandatory 'epoch' key", str(cm.exception))

+         self.assertEqual(len(self.inserts), 0)

createImageBuild returns an error when build is not existing and buildinfo
is not a dict

Fixes: https://pagure.io/koji/issue/1106

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

a year ago

rebased onto 59f841ed2a4be4e8acd7ccde4038810e3a00d24a

a year ago

rebased onto 1279b85e5d6bcc8cc7458b4eb923d14172bdfb2b

a year ago

rebased onto e8eee70830d0a75052aef8ebeb4d883c0b150bad

a year ago

rebased onto b279276

a year ago

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

a year ago

Commit 8186460 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago