[PATCH 3/4] models: Return string from 'combined_check_status'

Stephen Finucane stephen.finucane at intel.com
Sat Mar 26 03:19:21 AEDT 2016


Previously the 'combined_check_status' function returned the checks
enum integer for the status field. However, the string representation
is more meaningful and is the only representation seen by users at
moment. Change this function so it returns, for example, 'success'
instead of '1'.

Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
 patchwork/models.py            | 7 ++++---
 patchwork/tests/test_checks.py | 4 +++-
 patchwork/views/xmlrpc.py      | 4 +---
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/patchwork/models.py b/patchwork/models.py
index 267c08e..b924f68 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -373,17 +373,18 @@ class Patch(EmailMixin, models.Model):
           * success, if latest checks for all contexts reports as
               success
         """
+        state_names = dict(Check.STATE_CHOICES)
         states = [check.state for check in self.checks]
 
         if not states:
-            return Check.STATE_PENDING
+            return state_names[Check.STATE_PENDING]
 
         for state in [Check.STATE_FAIL, Check.STATE_WARNING,
                       Check.STATE_PENDING]:  # order sensitive
             if state in states:
-                return state
+                return state_names[state]
 
-        return Check.STATE_SUCCESS
+        return state_names[Check.STATE_SUCCESS]
 
     @property
     def checks(self):
diff --git a/patchwork/tests/test_checks.py b/patchwork/tests/test_checks.py
index 85c02c1..d7b8a25 100644
--- a/patchwork/tests/test_checks.py
+++ b/patchwork/tests/test_checks.py
@@ -60,7 +60,9 @@ class PatchChecksTest(TransactionTestCase):
         return check
 
     def assertCheckEqual(self, patch, check_state):
-        self.assertEqual(self.patch.combined_check_state, check_state)
+        state_names = dict(Check.STATE_CHOICES)
+        self.assertEqual(self.patch.combined_check_state,
+                         state_names[check_state])
 
     def assertChecksEqual(self, patch, checks=None):
         if not checks:
diff --git a/patchwork/views/xmlrpc.py b/patchwork/views/xmlrpc.py
index 1f48959..638b3b1 100644
--- a/patchwork/views/xmlrpc.py
+++ b/patchwork/views/xmlrpc.py
@@ -353,10 +353,8 @@ def check_to_dict(obj):
 
 def patch_check_to_dict(obj):
     """Return a combined patch check."""
-    state_names = dict(Check.STATE_CHOICES)
-
     return {
-        'state': state_names[obj.combined_check_state],
+        'state': obj.combined_check_state,
         'total': len(obj.checks),
         'checks': [check_to_dict(check) for check in obj.checks]
     }
-- 
2.0.0



More information about the Patchwork mailing list