#2796 api: getVolume with strict
Merged a year ago by tkopecek. Opened a year ago by jcupova.
jcupova/koji issue1592  into  master

file modified
+4 -1
@@ -10708,7 +10708,10 @@ 

          volume, or None if no match.

          If strict is true, raises an error if no match.

          """

-         return lookup_name('volume', volume, strict=strict)

+         result = lookup_name('volume', volume)

+         if not result and strict:

+             raise koji.GenericError("No such volume: %s" % volume)

+         return result

  

      def applyVolumePolicy(self, build, strict=False):

          """Apply the volume policy to a given build

@@ -0,0 +1,32 @@ 

+ import unittest

+ import mock

+ 

+ import koji

+ import kojihub

+ 

+ 

+ class TestGetVolume(unittest.TestCase):

+ 

+     def setUp(self):

+         self.exports = kojihub.RootExports()

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

+ 

+     def test_non_exist_volume_with_strict(self):

+         volume = ['test-volume']

+         self.lookup_name.return_value = None

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

+             self.exports.getVolume(volume, strict=True)

+         self.assertEqual("No such volume: %s" % volume, str(cm.exception))

+ 

+     def test_non_exist_volume_with_strict(self):

+         volume = ['test-volume']

+         self.lookup_name.return_value = None

+         result = self.exports.getVolume(volume)

+         self.assertEqual(None, result)

+ 

+     def test_valid_volume(self):

+         volume = ['test-volume']

+         volume_dict = {'id': 0, 'name': 'DEFAULT'}

+         self.lookup_name.return_value = volume_dict

+         result = self.exports.getVolume(volume)

+         self.assertEqual(volume_dict, result)

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

a year ago

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

a year ago

Commit b206d9e fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago