From: Stephen Finucane Date: Fri, 24 Jun 2016 16:28:13 +0000 (+0100) Subject: models: Return string from 'combined_check_status' X-Git-Tag: v2.0.0-rc1~332 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ada0e90906835c5bb88b4bad99ed555df013de46;p=thirdparty%2Fpatchwork.git models: Return string from 'combined_check_status' 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 Reviewed-by: Andy Doan --- diff --git a/patchwork/models.py b/patchwork/models.py index 0ddb4098..a8e93edb 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -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): diff --git a/patchwork/rest_serializers.py b/patchwork/rest_serializers.py index 90fc1678..af6b1b7f 100644 --- a/patchwork/rest_serializers.py +++ b/patchwork/rest_serializers.py @@ -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) diff --git a/patchwork/tests/test_checks.py b/patchwork/tests/test_checks.py index 85c02c11..d7b8a25e 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 1f489599..638b3b1a 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] }