From patchwork Fri Mar 25 17:27:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 602071 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qWqy53nVdz9s8d for ; Sat, 26 Mar 2016 04:27:57 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3qWqy531s8zDqF7 for ; Sat, 26 Mar 2016 04:27:57 +1100 (AEDT) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lists.ozlabs.org (Postfix) with ESMTP id 3qWqxh34sfzDq71 for ; Sat, 26 Mar 2016 04:27:35 +1100 (AEDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 25 Mar 2016 10:27:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,392,1455004800"; d="scan'208";a="771485890" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 25 Mar 2016 10:27:33 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u2PHRXoq000818; Fri, 25 Mar 2016 17:27:33 GMT Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id u2PHRX8C029747; Fri, 25 Mar 2016 17:27:33 GMT Received: (from sfinucan@localhost) by sivswdev01.ir.intel.com with id u2PHRXuP029742; Fri, 25 Mar 2016 17:27:33 GMT From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 3/6] models: Return string from 'combined_check_status' Date: Fri, 25 Mar 2016 17:27:20 +0000 Message-Id: <1458926843-29681-3-git-send-email-stephen.finucane@intel.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1458926843-29681-1-git-send-email-stephen.finucane@intel.com> References: <1458926843-29681-1-git-send-email-stephen.finucane@intel.com> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" 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 --- 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] }