]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: Don't group checks with different owners
authorStephen Finucane <stephen.finucane@intel.com>
Fri, 24 Jun 2016 16:28:15 +0000 (17:28 +0100)
committerStephen Finucane <stephen.finucane@intel.com>
Tue, 28 Jun 2016 09:16:11 +0000 (10:16 +0100)
This prevents CIs from overriding the results of another CI by using
the same context.

Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
patchwork/models.py
patchwork/tests/test_checks.py

index e07b15365d1251c65137793f1e15826bc2d0e4af..521b20c222b31e0176b945928f6c0d5a32bff005 100644 (file)
@@ -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)
index d7b8a25e84edae65bc66e9b8b34c0045c9271022..2ed5070e9770f25082a61bd357822724e0e50fbf 100644 (file)
@@ -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})