From b4a9ada49dfa44f83d114dc04bceff44aef0bbd8 Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Jan 20 2021 14:28:43 +0000 Subject: Fix optional decision_context if decision_contexts is available JIRA: RHELWF-2743 --- diff --git a/greenwave/policies.py b/greenwave/policies.py index 34a49e2..f979a65 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -811,7 +811,7 @@ class RemotePolicy(Policy): 'id': SafeYAMLString(optional=True), 'product_versions': SafeYAMLList(str, default=['*'], optional=True), 'subject_type': SafeYAMLString(optional=True, default='koji_build'), - 'decision_context': SafeYAMLString(), + 'decision_context': SafeYAMLString(optional=True), 'decision_contexts': SafeYAMLList(str, optional=True), 'rules': SafeYAMLList(Rule), 'blacklist': SafeYAMLList(str, optional=True), diff --git a/greenwave/tests/test_policies.py b/greenwave/tests/test_policies.py index 363b680..e354c30 100644 --- a/greenwave/tests/test_policies.py +++ b/greenwave/tests/test_policies.py @@ -961,10 +961,11 @@ def test_parse_policies_missing_product_versions(): """)) -def test_parse_policies_missing_decision_context(): +@pytest.mark.parametrize('policy_class', [Policy, RemotePolicy]) +def test_parse_policies_missing_decision_context(policy_class): expected_error = "No decision contexts provided" with pytest.raises(SafeYAMLError, match=expected_error): - Policy.safe_load_all(dedent(""" + policy_class.safe_load_all(dedent(""" --- !Policy id: test product_versions: [fedora-rawhide] @@ -975,10 +976,11 @@ def test_parse_policies_missing_decision_context(): """)) -def test_parse_policies_both_decision_contexts_set(): +@pytest.mark.parametrize('policy_class', [Policy, RemotePolicy]) +def test_parse_policies_both_decision_contexts_set(policy_class): expected_error = 'Both properties "decision_contexts" and "decision_context" were set' with pytest.raises(SafeYAMLError, match=expected_error): - Policy.safe_load_all(dedent(""" + policy_class.safe_load_all(dedent(""" --- !Policy id: test product_versions: [fedora-rawhide] @@ -1113,6 +1115,19 @@ def test_parse_policies_remote_missing_id_is_ok(): assert policies[0].id is None +def test_parse_policies_remote_decision_contexts(): + policies = RemotePolicy.safe_load_all(dedent(""" + --- !Policy + product_versions: [fedora-rawhide] + decision_contexts: [test1, test2] + subject_type: koji_build + rules: + - !PassingTestCaseRule {test_case_name: test.case.name} + """)) + assert len(policies) == 1 + assert policies[0].all_decision_contexts == ["test1", "test2"] + + def test_parse_policies_remote_missing_subject_type_is_ok(): policies = RemotePolicy.safe_load_all(dedent(""" --- !Policy