]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: Return string from 'combined_check_status'
authorStephen Finucane <stephen.finucane@intel.com>
Fri, 24 Jun 2016 16:28:13 +0000 (17:28 +0100)
committerStephen Finucane <stephen.finucane@intel.com>
Tue, 28 Jun 2016 09:16:10 +0000 (10:16 +0100)
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@intel.com>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
patchwork/models.py
patchwork/rest_serializers.py
patchwork/tests/test_checks.py
patchwork/views/xmlrpc.py

index 0ddb4098579ae8484729763e185b6940c07ba507..a8e93edbf502bdfe31d464d0278661b81481ef07 100644 (file)
@@ -399,17 +399,18 @@ class Patch(Submission):
           * 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):
index 90fc16789779ed28091f477c274969b9c193e084..af6b1b7fa6759c51ac688f77904cbb35089aed52 100644 (file)
@@ -99,7 +99,7 @@ class PatchSerializer(URLSerializer):
     def to_representation(self, instance):
         data = super(PatchSerializer, self).to_representation(instance)
         data['checks_url'] = data['url'] + 'checks/'
-        data['check'] = self.check_names[instance.combined_check_state]
+        data['check'] = instance.combined_check_state
         headers = data.get('headers')
         if headers is not None:
             data['headers'] = email.parser.Parser().parsestr(headers, True)
index 85c02c118c6bc2c3bb4ec9da2d9d051820398b68..d7b8a25e84edae65bc66e9b8b34c0045c9271022 100644 (file)
@@ -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:
index 1f48959942e7a8706badc3a7e393ad9fcfc429dc..638b3b1a08c4a6dab24f5cdd8c8acdce25ac0b8b 100644 (file)
@@ -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]
     }