Merge "Update logic on allowed list"

This commit is contained in:
Zuul 2021-08-12 09:53:57 +00:00 committed by Gerrit Code Review
commit a9b1caf933
2 changed files with 49 additions and 16 deletions

View File

@ -42,20 +42,26 @@ class ListAllowedYaml(Lister):
if len(yaml_file) > 0:
if parsed_args.group:
everything = yaml_file.get('groups', [])
tests = list(filter(
group_tests = list(filter(
lambda x:
x.get('name', '') == parsed_args.group, everything))
tests = list(filter(
group_tests = list(filter(
lambda x:
parsed_args.release in x.get('releases', []), tests))
parsed_args.release in x.get('releases', []),
group_tests))
if len(group_tests) > 0:
tests = group_tests
if parsed_args.job:
everything = yaml_file.get('jobs', [])
tests = list(filter(
job_tests = list(filter(
lambda x: x.get('name', '') == parsed_args.job,
everything))
tests = list(filter(
job_tests = list(filter(
lambda x:
parsed_args.release in x.get('releases', []), tests))
parsed_args.release in x.get('releases', []),
job_tests))
if len(job_tests) > 0:
tests = job_tests
if len(tests) > 0:
return tests[0].get('tests')
return []
@ -67,16 +73,12 @@ class ListAllowedYaml(Lister):
help='List the tests to be included in the '
'YAML file'
)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--job', dest='job',
help='List the tests to be included in the '
'given job'
)
group.add_argument('--group', dest='group',
help='List the tests to be included in the '
'given group'
)
parser.add_argument('--job', dest='job',
help='List the tests to be included in the '
'given job', required=True)
parser.add_argument('--group', dest='group',
help='List the tests to be included in the '
'given group', default='')
parser.add_argument('--release', dest='release',
help='Filter the tests per release',
default='master')

View File

@ -82,6 +82,37 @@ class TestListYamlAllowed(base.TestCase):
list_tests = [test for test in cmd_result[1]]
self.assertEqual(expected, list_tests)
def test_list_allowed_with_existing_group_and_job(self):
self.parser.group = 'group1'
self.parser.job = 'job2'
cmd_result = self.cmd.take_action(self.parser)
expected = [('test4',), ('test5',)]
list_tests = [test for test in cmd_result[1]]
self.assertEqual(expected, list_tests)
def test_list_allowed_with_existing_group_and_no_existing_job(self):
self.parser.group = 'group1'
self.parser.job = 'jobnoexist'
cmd_result = self.cmd.take_action(self.parser)
expected = [('test_group_1',), ('test_group_2',)]
list_tests = [test for test in cmd_result[1]]
self.assertEqual(expected, list_tests)
def test_list_allowed_with_no_existing_group_and_no_existing_job(self):
self.parser.group = 'groupnoexist'
self.parser.job = 'jobnoexist'
cmd_result = self.cmd.take_action(self.parser)
list_tests = [test for test in cmd_result[1]]
self.assertEqual([], list_tests)
def test_list_allowed_with_no_existing_group_and_existing_job(self):
self.parser.group = 'groupnoexist'
self.parser.job = 'job2'
cmd_result = self.cmd.take_action(self.parser)
list_tests = [test for test in cmd_result[1]]
expected = [('test4',), ('test5',)]
self.assertEqual(expected, list_tests)
def test_list_allowed_with_no_group(self):
self.parser.group = 'no-exist'
cmd_result = self.cmd.take_action(self.parser)