New 'buildtype' test for policies
Fixes: https://pagure.io/koji/issue/1225
This commit is contained in:
parent
2cf37f6c4e
commit
b0f0c3ff45
3 changed files with 59 additions and 0 deletions
|
|
@ -209,6 +209,9 @@ Available tests
|
|||
* for the tag policies, determines the build tag from the build data,
|
||||
which will by null for imported builds
|
||||
|
||||
``buildtype``
|
||||
* checks the build type(s) against the arguments
|
||||
|
||||
``skip_tag``
|
||||
* checks to see if the --skip-tag option was used
|
||||
* only applicable to the build_from_* policies
|
||||
|
|
|
|||
|
|
@ -8349,6 +8349,15 @@ def policy_get_build_tags(data):
|
|||
return tags
|
||||
|
||||
|
||||
def policy_get_build_types(data):
|
||||
if 'btypes' in data:
|
||||
# btypes can be already populated by caller
|
||||
return set(data['btypes'])
|
||||
if 'build' in data:
|
||||
binfo = get_build(data['build'], strict=True)
|
||||
return set(get_build_type(binfo).keys())
|
||||
return set()
|
||||
|
||||
class NewPackageTest(koji.policy.BaseSimpleTest):
|
||||
"""Checks to see if a package exists yet"""
|
||||
name = 'is_new_package'
|
||||
|
|
@ -8504,6 +8513,18 @@ class BuildTagTest(koji.policy.BaseSimpleTest):
|
|||
return False
|
||||
|
||||
|
||||
class BuildTypeTest(koji.policy.BaseSimpleTest):
|
||||
"""Check the build type(s) of the build"""
|
||||
|
||||
name = 'buildtype'
|
||||
def run(self, data):
|
||||
args = self.str.split()[1:]
|
||||
for btype in policy_get_build_types(data):
|
||||
if multi_fnmatch(btype, args):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class ImportedTest(koji.policy.BaseSimpleTest):
|
||||
"""Check if any part of a build was imported
|
||||
|
||||
|
|
|
|||
|
|
@ -245,3 +245,38 @@ class TestHasTagTest(unittest.TestCase):
|
|||
# check no match case
|
||||
self.list_tags.return_value = []
|
||||
self.assertFalse(obj.run(data))
|
||||
|
||||
|
||||
class TestBuildTypeTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.get_build_type = mock.patch('kojihub.get_build_type').start()
|
||||
self.get_build = mock.patch('kojihub.get_build').start()
|
||||
|
||||
def tearDown(self):
|
||||
mock.patch.stopall()
|
||||
|
||||
def test_invalid(self):
|
||||
binfo = {'id': 1, 'name': 'nvr-1-2'}
|
||||
self.get_build.return_value = binfo
|
||||
self.get_build_type.return_value = {'rpm': None}
|
||||
obj = kojihub.BuildTypeTest('buildtype foo-*')
|
||||
data = {'build': 'nvr-1-2'}
|
||||
self.assertFalse(obj.run(data))
|
||||
self.get_build_type.assert_called_once_with(binfo)
|
||||
|
||||
def test_valid(self):
|
||||
binfo = {'id': 1, 'name': 'nvr-1-2'}
|
||||
self.get_build.return_value = binfo
|
||||
self.get_build_type.return_value = {'rpm': None}
|
||||
obj = kojihub.BuildTypeTest('buildtype rpm')
|
||||
data = {'build': 'nvr-1-2'}
|
||||
self.assertTrue(obj.run(data))
|
||||
self.get_build_type.assert_called_once_with(binfo)
|
||||
|
||||
def test_prepopulated(self):
|
||||
#self.get_build.return_value = {'id': 1, 'name': 'nvr-1-2'}
|
||||
self.get_build_type.return_value = {'rpm': None}
|
||||
obj = kojihub.BuildTypeTest('buildtype rpm')
|
||||
data = {'build': 123, 'btypes': set(['rpm'])}
|
||||
self.assertTrue(obj.run(data))
|
||||
self.get_build_type.assert_not_called()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue