From: Stephen Finucane Date: Fri, 24 Jun 2016 16:28:15 +0000 (+0100) Subject: models: Don't group checks with different owners X-Git-Tag: v2.0.0-rc1~330 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fc11fea232292001a8355746cbe42ee8d888927;p=thirdparty%2Fpatchwork.git models: Don't group checks with different owners This prevents CIs from overriding the results of another CI by using the same context. Signed-off-by: Stephen Finucane Reviewed-by: Andy Doan --- diff --git a/patchwork/models.py b/patchwork/models.py index e07b1536..521b20c2 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 d7b8a25e..2ed5070e 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})