From 0d1b7d9b5f78b4c00705a456e180445e55759481 Mon Sep 17 00:00:00 2001
From: Yashvardhan Nanavati <yashn@bu.edu>
Date: Mar 14 2019 13:51:31 +0000
Subject: [PATCH 1/2] Add tests for subject type bodhi


---

diff --git a/conf/policies/fedora.yaml b/conf/policies/fedora.yaml
index c038d3d..7d46c68 100644
--- a/conf/policies/fedora.yaml
+++ b/conf/policies/fedora.yaml
@@ -102,3 +102,14 @@ decision_context: container-image-test
 subject_type: container-image
 rules:
   - !PassingTestCaseRule {test_case_name: baseos-qe.baseos-ci.tier1.functional}
+
+--- !Policy
+id: "bodhi-test-policy"
+product_versions:
+- fedora-26
+decision_context: bodhi_update_push
+subject_type: bodhi_update
+rules:
+  - !PassingTestCaseRule {test_case_name: dist.abicheck}
+  - !PassingTestCaseRule {test_case_name: dist.rpmdeplint}
+  - !PassingTestCaseRule {test_case_name: dist.upgradepath}
diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py
index 82b2de2..59b0caf 100644
--- a/functional-tests/test_api_v1.py
+++ b/functional-tests/test_api_v1.py
@@ -36,7 +36,7 @@ def test_inspect_policies(requests_session, greenwave_server):
     assert r.status_code == 200
     body = r.json()
     policies = body['policies']
-    assert len(policies) == 12
+    assert len(policies) == 14
     assert any(p['id'] == 'taskotron_release_critical_tasks' for p in policies)
     assert any(p['decision_context'] == 'bodhi_update_push_stable' for p in policies)
     assert any(p['product_versions'] == ['fedora-26'] for p in policies)
@@ -1183,3 +1183,44 @@ def test_verbose_retrieve_latest_results(requests_session, greenwave_server, tes
     assert len(res_data['results']) == 3
     for result in res_data['results']:
         assert result['outcome'] == 'PASSED'
+
+
+def test_make_decision_passed_on_subject_type_bodhi_with_waiver(
+        requests_session, greenwave_server, testdatabuilder):
+    nvr = testdatabuilder.unique_nvr()
+    # First one failed but was waived
+    testdatabuilder.create_result(item=nvr,
+                                  testcase_name=TASKTRON_RELEASE_CRITICAL_TASKS[0],
+                                  outcome='FAILED',
+                                  _type='bodhi_update')
+    testdatabuilder.create_waiver(nvr=nvr,
+                                  product_version='fedora-26',
+                                  testcase_name=TASKTRON_RELEASE_CRITICAL_TASKS[0],
+                                  comment='This is fine',
+                                  subject_type='bodhi_update')
+
+    for testcase_name in TASKTRON_RELEASE_CRITICAL_TASKS[1:]:
+        testdatabuilder.create_result(item=nvr,
+                                      testcase_name=testcase_name,
+                                      outcome='PASSED',
+                                      _type='bodhi_update')
+
+    data = {
+        'decision_context': 'bodhi_update_push',
+        'product_version': 'fedora-26',
+        'subject_type': 'bodhi_update',
+        'subject_identifier': nvr,
+    }
+
+    r = requests_session.post(greenwave_server + 'api/v1.0/decision',
+                              headers={'Content-Type': 'application/json'},
+                              data=json.dumps(data))
+    assert r.status_code == 200
+    res_data = r.json()
+    assert res_data['policies_satisfied'] is True
+
+    assert res_data['applicable_policies'] == [
+        'bodhi-test-policy',
+    ]
+    expected_summary = 'All required tests passed'
+    assert res_data['summary'] == expected_summary

From 76981a5219a96ff63f1132a774601bce80ef3741 Mon Sep 17 00:00:00 2001
From: Yashvardhan Nanavati <yashn@bu.edu>
Date: Mar 15 2019 15:35:16 +0000
Subject: [PATCH 2/2] Add test to confirm all results are returned when verbose flag is set


When the verbose flag is set, Greenwave should also return the test results that are
not included in the matching policy but have the same subject type

---

diff --git a/conf/policies/fedora.yaml b/conf/policies/fedora.yaml
index 7d46c68..2820167 100644
--- a/conf/policies/fedora.yaml
+++ b/conf/policies/fedora.yaml
@@ -113,3 +113,12 @@ rules:
   - !PassingTestCaseRule {test_case_name: dist.abicheck}
   - !PassingTestCaseRule {test_case_name: dist.rpmdeplint}
   - !PassingTestCaseRule {test_case_name: dist.upgradepath}
+
+--- !Policy
+id: "koji-test-policy-missing-results"
+product_versions:
+- fedora-30
+decision_context: koji_build_push_missing_results
+subject_type: koji_build
+rules:
+  - !PassingTestCaseRule {test_case_name: dist.rpmdeplint}
diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py
index 59b0caf..f325e2e 100644
--- a/functional-tests/test_api_v1.py
+++ b/functional-tests/test_api_v1.py
@@ -1224,3 +1224,41 @@ def test_make_decision_passed_on_subject_type_bodhi_with_waiver(
     ]
     expected_summary = 'All required tests passed'
     assert res_data['summary'] == expected_summary
+
+
+def test_make_a_decision_with_verbose_flag_all_results_returned(
+        requests_session, greenwave_server, testdatabuilder):
+    nvr = testdatabuilder.unique_nvr()
+    results = []
+    expected_waivers = []
+    # First one failed but was waived
+    results.append(testdatabuilder.create_result(item=nvr,
+                                                 testcase_name=TASKTRON_RELEASE_CRITICAL_TASKS[0],
+                                                 outcome='FAILED'))
+    expected_waivers.append(
+        testdatabuilder.create_waiver(nvr=nvr,
+                                      product_version='fedora-30',
+                                      testcase_name=TASKTRON_RELEASE_CRITICAL_TASKS[0],
+                                      comment='This is fine'))
+    for testcase_name in TASKTRON_RELEASE_CRITICAL_TASKS[1:]:
+        results.append(testdatabuilder.create_result(item=nvr,
+                                                     testcase_name=testcase_name,
+                                                     outcome='PASSED'))
+
+    data = {
+        'decision_context': 'koji_build_push_missing_results',
+        'product_version': 'fedora-30',
+        'subject_type': 'koji_build',
+        'subject_identifier': nvr,
+        'verbose': True,
+    }
+    r = requests_session.post(greenwave_server + 'api/v1.0/decision',
+                              headers={'Content-Type': 'application/json'},
+                              data=json.dumps(data))
+    assert r.status_code == 200
+    res_data = r.json()
+
+    assert len(res_data['results']) == len(results)
+    assert res_data['results'] == list(reversed(results))
+    assert len(res_data['waivers']) == len(expected_waivers)
+    assert res_data['waivers'] == expected_waivers

