From b2c243fdc1a70fb0637472a355460602e4712fa5 Mon Sep 17 00:00:00 2001
From: Dan Callaghan <dcallagh@redhat.com>
Date: Mar 29 2018 06:50:53 +0000
Subject: more clearly indicate missing results in summary text


Fixes #145.

---

diff --git a/functional-tests/consumers/test_resultsdb.py b/functional-tests/consumers/test_resultsdb.py
index fb09157..49b3d19 100644
--- a/functional-tests/consumers/test_resultsdb.py
+++ b/functional-tests/consumers/test_resultsdb.py
@@ -83,7 +83,7 @@ def test_consume_new_result(
                 'scenario': None,
             }
         ],
-        'summary': '2 of 3 required tests not found',
+        'summary': '2 of 3 required test results missing',
         'subject': [
             {
                 'item': nvr,
@@ -399,7 +399,7 @@ def test_consume_compose_id_result(
         u'policies_satisfied': False,
         'product_version': 'fedora-rawhide',
         'subject': [{u'productmd.compose.id': compose_id}],
-        u'summary': u'1 of 2 required tests not found',
+        u'summary': u'1 of 2 required test results missing',
         'previous': old_decision,
         u'unsatisfied_requirements': [{
             u'item': {u'productmd.compose.id': compose_id},
diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py
index 72bf916..f7f3017 100644
--- a/functional-tests/test_api_v1.py
+++ b/functional-tests/test_api_v1.py
@@ -294,7 +294,7 @@ def test_make_a_decison_on_failed_result(requests_session, greenwave_server, tes
     res_data = r.json()
     assert res_data['policies_satisfied'] is False
     assert res_data['applicable_policies'] == ['1']
-    expected_summary = '1 of 71 required tests failed'
+    expected_summary = '1 of 71 required tests failed, 70 results missing'
     assert res_data['summary'] == expected_summary
     expected_unsatisfied_requirements = [
         {
@@ -329,7 +329,7 @@ def test_make_a_decison_on_no_results(requests_session, greenwave_server, testda
     res_data = r.json()
     assert res_data['policies_satisfied'] is False
     assert res_data['applicable_policies'] == ['1']
-    expected_summary = 'no test results found'
+    expected_summary = '71 of 71 required test results missing'
     assert res_data['summary'] == expected_summary
     expected_unsatisfied_requirements = [
         {
diff --git a/greenwave/policies.py b/greenwave/policies.py
index 38c655e..ed80b21 100644
--- a/greenwave/policies.py
+++ b/greenwave/policies.py
@@ -98,13 +98,14 @@ def summarize_answers(answers):
     if all(answer.is_satisfied for answer in answers):
         return 'all required tests passed'
     failure_count = len([answer for answer in answers if isinstance(answer, TestResultFailed)])
-    if failure_count:
-        return ('{} of {} required tests failed'.format(failure_count, len(answers)))
     missing_count = len([answer for answer in answers if isinstance(answer, TestResultMissing)])
-    if missing_count == len(answers):
-        return 'no test results found'
+    if failure_count and missing_count:
+        return '{} of {} required tests failed, {} result{} missing'.format(
+            failure_count, len(answers), missing_count, 's' if missing_count > 1 else '')
+    elif failure_count:
+        return '{} of {} required tests failed'.format(failure_count, len(answers))
     elif missing_count:
-        return '{} of {} required tests not found'.format(missing_count, len(answers))
+        return '{} of {} required test results missing'.format(missing_count, len(answers))
     return 'inexplicable result'
 
 
diff --git a/greenwave/tests/test_policies.py b/greenwave/tests/test_policies.py
index 500550f..8366f24 100644
--- a/greenwave/tests/test_policies.py
+++ b/greenwave/tests/test_policies.py
@@ -21,12 +21,16 @@ def test_summarize_answers():
     assert summarize_answers([TestResultFailed('item', 'test', None, 'id'), RuleSatisfied()]) == \
         '1 of 2 required tests failed'
     assert summarize_answers([TestResultMissing('item', 'test', None)]) == \
-        'no test results found'
+        '1 of 1 required test results missing'
     assert summarize_answers([TestResultMissing('item', 'test', None),
                               TestResultFailed('item', 'test', None, 'id')]) == \
-        '1 of 2 required tests failed'
+        '1 of 2 required tests failed, 1 result missing'
+    assert summarize_answers([TestResultMissing('item', 'testa', None),
+                              TestResultMissing('item', 'testb', None),
+                              TestResultFailed('item', 'test', None, 'id')]) == \
+        '1 of 3 required tests failed, 2 results missing'
     assert summarize_answers([TestResultMissing('item', 'test', None), RuleSatisfied()]) == \
-        '1 of 2 required tests not found'
+        '1 of 2 required test results missing'
 
 
 def test_waive_absence_of_result(tmpdir):

