From patchwork Sun Oct 4 11:10:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 1376395 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C41Hb40zqz9sRR for ; Sun, 4 Oct 2020 22:10:51 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" header.d=that.guru header.i=@that.guru header.a=rsa-sha256 header.s=x header.b=nPBYe43J; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4C41Hb1fBRzDqHf for ; Sun, 4 Oct 2020 22:10:51 +1100 (AEDT) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=that.guru (client-ip=172.82.139.39; helo=qrelay39.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" header.d=that.guru header.i=@that.guru header.a=rsa-sha256 header.s=x header.b=nPBYe43J; dkim-atps=neutral Received: from qrelay39.mxroute.com (qrelay39.mxroute.com [172.82.139.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4C41Gt5QVCzDqD8 for ; Sun, 4 Oct 2020 22:10:13 +1100 (AEDT) Received: from filter003.mxroute.com ([168.235.111.26] 168-235-111-26.cloud.ramnode.com) (Authenticated sender: mN4UYu2MZsgR) by qrelay39.mxroute.com (ZoneMTA) with ESMTPA id 174f34dfb9d000354c.001 for ; Sun, 04 Oct 2020 11:10:08 +0000 X-Zone-Loop: 8ff491defbbab93be551b42fb9f9af4c583b8782f910 X-Originating-IP: [168.235.111.26] Received: from sunfire.mxrouting.net (sunfire.mxrouting.net [49.12.120.198]) by filter003.mxroute.com (Postfix) with ESMTPS id 7551360035 for ; Sun, 4 Oct 2020 11:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To: From:Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=OuXafIkw+4zsu+mHNFOYyy1wID+3hBmklwlXNcZeKK8=; b=n PBYe43J6og7fPFDISTsMrez53oyASM1gMUxh1lVV9E6++tlDNWgMf3XkP6bra8gtrdyS8xL6QL+ke hIl09Fe8jr0GS7y7cMJX8jm6gLfKbVQMHkIHXwn0COZTF22AiyFPteGCR+eXx8Au3SPoiGwJ2adcY EK0DeqBqM89a5RB3AbKvRR5V9/JQYp+Qfb2ZTnGRBi8RRf7Y1yESH+cgD5Q6TcfWgSn2xo8q+AbhA Kv2L6yCn+1Qz8rz+jYPu/4cPfCxIGPDfSi8DZCtCP2VFaKtCc3FCqo/R+ZXK3Iar9Sw5Ugb71GGJd FJT4x8Rr/UYFWwC6+SZzH1d17YQKps1Hw==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 1/3] tests: Rework 'create_relation' helper Date: Sun, 4 Oct 2020 12:10:00 +0100 Message-Id: <20201004111002.234895-1-stephen@that.guru> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This wasn't actually creating just a patch relation object - it was also creating patches, which is something we already have an explicit helper for. Clean this thing up. Signed-off-by: Stephen Finucane --- patchwork/tests/api/test_relation.py | 54 ++++++++++++++++------------ patchwork/tests/utils.py | 15 +++----- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git patchwork/tests/api/test_relation.py patchwork/tests/api/test_relation.py index d48c62bc..5f8048f2 100644 --- patchwork/tests/api/test_relation.py +++ patchwork/tests/api/test_relation.py @@ -48,8 +48,8 @@ class TestRelationSimpleAPI(utils.APITestCase): @utils.store_samples('relation-list') def test_list_two_patch_relation(self): - relation = create_relation(2, project=self.project) - patches = relation.patches.all() + relation = create_relation() + patches = create_patches(2, project=self.project, related=relation) # nobody resp = self.client.get(self.api_url(item=patches[0].pk)) @@ -101,8 +101,8 @@ class TestRelationSimpleAPI(utils.APITestCase): self.assertEqual(patches[1].related, patches[0].related) def test_delete_two_patch_relation_nobody(self): - relation = create_relation(project=self.project) - patch = relation.patches.all()[0] + relation = create_relation() + patch = create_patches(2, project=self.project, related=relation)[0] self.assertEqual(PatchRelation.objects.count(), 1) @@ -112,8 +112,8 @@ class TestRelationSimpleAPI(utils.APITestCase): @utils.store_samples('relation-delete') def test_delete_two_patch_relation_maintainer(self): - relation = create_relation(project=self.project) - patch = relation.patches.all()[0] + relation = create_relation() + patch = create_patches(2, project=self.project, related=relation)[0] self.assertEqual(PatchRelation.objects.count(), 1) @@ -145,8 +145,8 @@ class TestRelationSimpleAPI(utils.APITestCase): self.assertEqual(patches[1].related, patches[2].related) def test_delete_from_three_patch_relation(self): - relation = create_relation(3, project=self.project) - patch = relation.patches.all()[0] + relation = create_relation() + patch = create_patches(3, project=self.project, related=relation)[0] self.assertEqual(PatchRelation.objects.count(), 1) @@ -159,8 +159,9 @@ class TestRelationSimpleAPI(utils.APITestCase): @utils.store_samples('relation-extend-through-new') def test_extend_relation_through_new(self): - relation = create_relation(project=self.project) - existing_patch_a = relation.patches.first() + relation = create_relation() + existing_patch_a = create_patches( + 2, project=self.project, related=relation)[0] new_patch = create_patch(project=self.project) @@ -173,8 +174,9 @@ class TestRelationSimpleAPI(utils.APITestCase): self.assertEqual(relation.patches.count(), 3) def test_extend_relation_through_old(self): - relation = create_relation(project=self.project) - existing_patch_a = relation.patches.first() + relation = create_relation() + existing_patch_a = create_patches( + 2, project=self.project, related=relation)[0] new_patch = create_patch(project=self.project) @@ -188,8 +190,9 @@ class TestRelationSimpleAPI(utils.APITestCase): self.assertEqual(relation.patches.count(), 3) def test_extend_relation_through_new_two(self): - relation = create_relation(project=self.project) - existing_patch_a = relation.patches.first() + relation = create_relation() + existing_patch_a = create_patches( + 2, project=self.project, related=relation)[0] new_patch_a = create_patch(project=self.project) new_patch_b = create_patch(project=self.project) @@ -210,8 +213,9 @@ class TestRelationSimpleAPI(utils.APITestCase): @utils.store_samples('relation-extend-through-old') def test_extend_relation_through_old_two(self): - relation = create_relation(project=self.project) - existing_patch_a = relation.patches.first() + relation = create_relation() + existing_patch_a = create_patches( + 2, project=self.project, related=relation)[0] new_patch_a = create_patch(project=self.project) new_patch_b = create_patch(project=self.project) @@ -232,9 +236,10 @@ class TestRelationSimpleAPI(utils.APITestCase): self.assertEqual(relation.patches.count(), 4) def test_remove_one_patch_from_relation_bad(self): - relation = create_relation(3, project=self.project) - keep_patch_a = relation.patches.all()[1] - keep_patch_b = relation.patches.all()[2] + relation = create_relation() + patches = create_patches(3, project=self.project, related=relation) + keep_patch_a = patches[1] + keep_patch_b = patches[1] # this should do nothing - it is interpreted as # _adding_ keep_patch_b again which is a no-op. @@ -248,8 +253,9 @@ class TestRelationSimpleAPI(utils.APITestCase): self.assertEqual(relation.patches.count(), 3) def test_remove_one_patch_from_relation_good(self): - relation = create_relation(3, project=self.project) - target_patch = relation.patches.all()[0] + relation = create_relation() + target_patch = create_patches( + 3, project=self.project, related=relation)[0] # maintainer self.client.force_authenticate(user=self.maintainer) @@ -263,8 +269,10 @@ class TestRelationSimpleAPI(utils.APITestCase): @utils.store_samples('relation-forbid-moving-between-relations') def test_forbid_moving_patch_between_relations(self): """Test the break-before-make logic""" - relation_a = create_relation(project=self.project) - relation_b = create_relation(project=self.project) + relation_a = create_relation() + create_patches(2, project=self.project, related=relation_a) + relation_b = create_relation() + create_patches(2, project=self.project, related=relation_b) patch_a = relation_a.patches.first() patch_b = relation_b.patches.first() diff --git patchwork/tests/utils.py patchwork/tests/utils.py index c464979f..17dc3fcb 100644 --- patchwork/tests/utils.py +++ patchwork/tests/utils.py @@ -308,6 +308,11 @@ def create_series_reference(**kwargs): return SeriesReference.objects.create(**values) +def create_relation(**kwargs): + """Create 'PatchRelation' object.""" + return PatchRelation.objects.create(**kwargs) + + def _create_submissions(create_func, count=1, **kwargs): """Create 'count' SubmissionMixin-based objects. @@ -364,13 +369,3 @@ def create_covers(count=1, **kwargs): kwargs (dict): Overrides for various cover letter fields """ return _create_submissions(create_cover, count, **kwargs) - - -def create_relation(count_patches=2, **kwargs): - relation = PatchRelation.objects.create() - values = { - 'related': relation - } - values.update(kwargs) - create_patches(count_patches, **values) - return relation