[PATCH] changeset status: fix common case where a reviewer did not yet review anything

Thomas De Schampheleire patrickdepinguin at gmail.com
Mon Apr 20 11:20:57 EDT 2015


# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1429542162 -7200
#      Mon Apr 20 17:02:42 2015 +0200
# Node ID e5a5517fe74c2c7cc0f3a2a59f14313d8c812999
# Parent  7f5ee27ef0beb5883febb1a1ea5f5a7ce4f277d9
changeset status: fix common case where a reviewer did not yet review anything

When a reviewer did not yet make any review, its status for the changeset is
None, causing the code to crash. The unit tests also did not cover this case.

diff --git a/kallithea/model/changeset_status.py b/kallithea/model/changeset_status.py
--- a/kallithea/model/changeset_status.py
+++ b/kallithea/model/changeset_status.py
@@ -75,10 +75,10 @@ class ChangesetStatusModel(BaseModel):
         if not statuses:
             return ChangesetStatus.STATUS_UNDER_REVIEW
 
-        if all(st.status == ChangesetStatus.STATUS_APPROVED for st in statuses):
+        if all(st and st.status == ChangesetStatus.STATUS_APPROVED for st in statuses):
             return ChangesetStatus.STATUS_APPROVED
 
-        if any(st.status == ChangesetStatus.STATUS_REJECTED for st in statuses):
+        if any(st and st.status == ChangesetStatus.STATUS_REJECTED for st in statuses):
             return ChangesetStatus.STATUS_REJECTED
 
         return ChangesetStatus.STATUS_UNDER_REVIEW
diff --git a/kallithea/tests/models/test_changeset_status.py b/kallithea/tests/models/test_changeset_status.py
--- a/kallithea/tests/models/test_changeset_status.py
+++ b/kallithea/tests/models/test_changeset_status.py
@@ -32,6 +32,16 @@ class TestChangesetStatusCalculation(Bas
         ('reject_underreview', STATUS_REJECTED, [S(STATUS_REJECTED), S(STATUS_UNDER_REVIEW)]),
         ('reject_notreviewed', STATUS_REJECTED, [S(STATUS_REJECTED), S(STATUS_NOT_REVIEWED)]),
         ('notreviewed', STATUS_UNDER_REVIEW, [S(STATUS_NOT_REVIEWED)]),
+        ('approve_none', STATUS_UNDER_REVIEW, [S(STATUS_APPROVED), None]),
+        ('approve2_none', STATUS_UNDER_REVIEW, [S(STATUS_APPROVED), S(STATUS_APPROVED), None]),
+        ('approve_reject_none', STATUS_REJECTED, [S(STATUS_APPROVED), S(STATUS_REJECTED), None]),
+        ('approve_underreview_none', STATUS_UNDER_REVIEW, [S(STATUS_APPROVED), S(STATUS_UNDER_REVIEW), None]),
+        ('approve_notreviewed_none', STATUS_UNDER_REVIEW, [S(STATUS_APPROVED), S(STATUS_NOT_REVIEWED), None]),
+        ('underreview_none', STATUS_UNDER_REVIEW, [S(STATUS_UNDER_REVIEW), S(STATUS_UNDER_REVIEW), None]),
+        ('reject_none', STATUS_REJECTED, [S(STATUS_REJECTED), None]),
+        ('reject_underreview_none', STATUS_REJECTED, [S(STATUS_REJECTED), S(STATUS_UNDER_REVIEW), None]),
+        ('reject_notreviewed_none', STATUS_REJECTED, [S(STATUS_REJECTED), S(STATUS_NOT_REVIEWED), None]),
+        ('notreviewed_none', STATUS_UNDER_REVIEW, [S(STATUS_NOT_REVIEWED), None]),
     ])
     def test_result(self, name, expected_result, statuses):
         result = self.m._calculate_status(statuses)


More information about the kallithea-general mailing list