[PATCH v2 5/6] models: Don't group checks with different owners
Stephen Finucane
stephen.finucane at intel.com
Sat Mar 26 04:27:22 AEDT 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>
---
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 7b6a821..d0c07dc 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -403,15 +403,19 @@ class Patch(EmailMixin, models.Model):
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})
--
2.0.0
More information about the Patchwork
mailing list