[PATCH 4/5] models: Don't group checks with different owners

Stephen Finucane stephen.finucane at intel.com
Sat Jun 25 02:28:15 AEST 2016


This prevents CIs from overriding the results of another CI by using
the same context.

Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
Reviewed-by: Andy Doan <andy.doan at linaro.org>
---
 patchwork/models.py            |   12 ++++++++----
 patchwork/tests/test_checks.py |   14 ++++++++++++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/patchwork/models.py b/patchwork/models.py
index eb12635..7c3cacf 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -429,15 +429,19 @@ class Patch(Submission):
 
         for check in self.check_set.all():
             ctx = check.context
+            user = check.user
 
-            if ctx in unique:
+            if user in unique and ctx in unique[user]:
                 # recheck condition - ignore the older result
-                if unique[ctx].date > check.date:
+                if unique[user][ctx].date > check.date:
                     duplicates.append(check.id)
                     continue
-                duplicates.append(unique[ctx].id)
+                duplicates.append(unique[user][ctx].id)
 
-            unique[ctx] = check
+            if user not in unique:
+                unique[user] = {}
+
+            unique[user][ctx] = check
 
         # filter out the "duplicates" or older, now-invalid results
         return self.check_set.all().exclude(id__in=duplicates)
diff --git a/patchwork/tests/test_checks.py b/patchwork/tests/test_checks.py
index d7b8a25..2ed5070 100644
--- a/patchwork/tests/test_checks.py
+++ b/patchwork/tests/test_checks.py
@@ -108,11 +108,16 @@ class PatchChecksTest(TransactionTestCase):
         self.create_check(date=(dt.now() - timedelta(days=1)))
         check = self.create_check()
         # this isn't a realistic scenario (dates shouldn't be set by user so
-        #   they will always increment), but it's useful to verify the removal
-        #   of older duplicates by the function
+        # they will always increment), but it's useful to verify the removal
+        # of older duplicates by the function
         self.create_check(date=(dt.now() - timedelta(days=2)))
         self.assertChecksEqual(self.patch, [check])
 
+    def test_checks__nultiple_users(self):
+        check_a = self.create_check()
+        check_b = self.create_check(user=create_user())
+        self.assertChecksEqual(self.patch, [check_a, check_b])
+
     def test_check_count__no_checks(self):
         self.assertCheckCountEqual(self.patch, 0)
 
@@ -125,6 +130,11 @@ class PatchChecksTest(TransactionTestCase):
         self.create_check(context='new/test1')
         self.assertCheckCountEqual(self.patch, 2, {Check.STATE_SUCCESS: 2})
 
+    def test_check_count__multiple_users(self):
+        self.create_check()
+        self.create_check(user=create_user())
+        self.assertCheckCountEqual(self.patch, 2, {Check.STATE_SUCCESS: 2})
+
     def test_check_count__duplicate_check_same_state(self):
         self.create_check(date=(dt.now() - timedelta(days=1)))
         self.assertCheckCountEqual(self.patch, 1, {Check.STATE_SUCCESS: 1})
-- 
1.7.4.1



More information about the Patchwork mailing list