Skip to content

Commit dd19914

Browse files
committed
tests: Rework 'create_relation' helper
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 <[email protected]> (cherry picked from commit 87e9f51)
1 parent 289f937 commit dd19914

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

patchwork/tests/api/test_relation.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def test_no_relation(self):
4848

4949
@utils.store_samples('relation-list')
5050
def test_list_two_patch_relation(self):
51-
relation = create_relation(2, project=self.project)
52-
patches = relation.patches.all()
51+
relation = create_relation()
52+
patches = create_patches(2, project=self.project, related=relation)
5353

5454
# nobody
5555
resp = self.client.get(self.api_url(item=patches[0].pk))
@@ -101,8 +101,8 @@ def test_create_two_patch_relation_maintainer(self):
101101
self.assertEqual(patches[1].related, patches[0].related)
102102

103103
def test_delete_two_patch_relation_nobody(self):
104-
relation = create_relation(project=self.project)
105-
patch = relation.patches.all()[0]
104+
relation = create_relation()
105+
patch = create_patches(2, project=self.project, related=relation)[0]
106106

107107
self.assertEqual(PatchRelation.objects.count(), 1)
108108

@@ -112,8 +112,8 @@ def test_delete_two_patch_relation_nobody(self):
112112

113113
@utils.store_samples('relation-delete')
114114
def test_delete_two_patch_relation_maintainer(self):
115-
relation = create_relation(project=self.project)
116-
patch = relation.patches.all()[0]
115+
relation = create_relation()
116+
patch = create_patches(2, project=self.project, related=relation)[0]
117117

118118
self.assertEqual(PatchRelation.objects.count(), 1)
119119

@@ -145,8 +145,8 @@ def test_create_three_patch_relation(self):
145145
self.assertEqual(patches[1].related, patches[2].related)
146146

147147
def test_delete_from_three_patch_relation(self):
148-
relation = create_relation(3, project=self.project)
149-
patch = relation.patches.all()[0]
148+
relation = create_relation()
149+
patch = create_patches(3, project=self.project, related=relation)[0]
150150

151151
self.assertEqual(PatchRelation.objects.count(), 1)
152152

@@ -159,8 +159,9 @@ def test_delete_from_three_patch_relation(self):
159159

160160
@utils.store_samples('relation-extend-through-new')
161161
def test_extend_relation_through_new(self):
162-
relation = create_relation(project=self.project)
163-
existing_patch_a = relation.patches.first()
162+
relation = create_relation()
163+
existing_patch_a = create_patches(
164+
2, project=self.project, related=relation)[0]
164165

165166
new_patch = create_patch(project=self.project)
166167

@@ -173,8 +174,9 @@ def test_extend_relation_through_new(self):
173174
self.assertEqual(relation.patches.count(), 3)
174175

175176
def test_extend_relation_through_old(self):
176-
relation = create_relation(project=self.project)
177-
existing_patch_a = relation.patches.first()
177+
relation = create_relation()
178+
existing_patch_a = create_patches(
179+
2, project=self.project, related=relation)[0]
178180

179181
new_patch = create_patch(project=self.project)
180182

@@ -188,8 +190,9 @@ def test_extend_relation_through_old(self):
188190
self.assertEqual(relation.patches.count(), 3)
189191

190192
def test_extend_relation_through_new_two(self):
191-
relation = create_relation(project=self.project)
192-
existing_patch_a = relation.patches.first()
193+
relation = create_relation()
194+
existing_patch_a = create_patches(
195+
2, project=self.project, related=relation)[0]
193196

194197
new_patch_a = create_patch(project=self.project)
195198
new_patch_b = create_patch(project=self.project)
@@ -210,8 +213,9 @@ def test_extend_relation_through_new_two(self):
210213

211214
@utils.store_samples('relation-extend-through-old')
212215
def test_extend_relation_through_old_two(self):
213-
relation = create_relation(project=self.project)
214-
existing_patch_a = relation.patches.first()
216+
relation = create_relation()
217+
existing_patch_a = create_patches(
218+
2, project=self.project, related=relation)[0]
215219

216220
new_patch_a = create_patch(project=self.project)
217221
new_patch_b = create_patch(project=self.project)
@@ -232,9 +236,10 @@ def test_extend_relation_through_old_two(self):
232236
self.assertEqual(relation.patches.count(), 4)
233237

234238
def test_remove_one_patch_from_relation_bad(self):
235-
relation = create_relation(3, project=self.project)
236-
keep_patch_a = relation.patches.all()[1]
237-
keep_patch_b = relation.patches.all()[2]
239+
relation = create_relation()
240+
patches = create_patches(3, project=self.project, related=relation)
241+
keep_patch_a = patches[1]
242+
keep_patch_b = patches[1]
238243

239244
# this should do nothing - it is interpreted as
240245
# _adding_ keep_patch_b again which is a no-op.
@@ -248,8 +253,9 @@ def test_remove_one_patch_from_relation_bad(self):
248253
self.assertEqual(relation.patches.count(), 3)
249254

250255
def test_remove_one_patch_from_relation_good(self):
251-
relation = create_relation(3, project=self.project)
252-
target_patch = relation.patches.all()[0]
256+
relation = create_relation()
257+
target_patch = create_patches(
258+
3, project=self.project, related=relation)[0]
253259

254260
# maintainer
255261
self.client.force_authenticate(user=self.maintainer)
@@ -263,8 +269,10 @@ def test_remove_one_patch_from_relation_good(self):
263269
@utils.store_samples('relation-forbid-moving-between-relations')
264270
def test_forbid_moving_patch_between_relations(self):
265271
"""Test the break-before-make logic"""
266-
relation_a = create_relation(project=self.project)
267-
relation_b = create_relation(project=self.project)
272+
relation_a = create_relation()
273+
create_patches(2, project=self.project, related=relation_a)
274+
relation_b = create_relation()
275+
create_patches(2, project=self.project, related=relation_b)
268276

269277
patch_a = relation_a.patches.first()
270278
patch_b = relation_b.patches.first()

patchwork/tests/utils.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ def create_series_reference(**kwargs):
297297
return SeriesReference.objects.create(**values)
298298

299299

300+
def create_relation(**kwargs):
301+
"""Create 'PatchRelation' object."""
302+
return PatchRelation.objects.create(**kwargs)
303+
304+
300305
def _create_submissions(create_func, count=1, **kwargs):
301306
"""Create 'count' Submission-based objects.
302307
@@ -353,13 +358,3 @@ def create_covers(count=1, **kwargs):
353358
kwargs (dict): Overrides for various cover letter fields
354359
"""
355360
return _create_submissions(create_cover, count, **kwargs)
356-
357-
358-
def create_relation(count_patches=2, **kwargs):
359-
relation = PatchRelation.objects.create()
360-
values = {
361-
'related': relation
362-
}
363-
values.update(kwargs)
364-
create_patches(count_patches, **values)
365-
return relation

0 commit comments

Comments
 (0)