Skip to content

Commit e2978eb

Browse files
committed
Remove on_commit handling in tests
1 parent 026d7d6 commit e2978eb

2 files changed

Lines changed: 50 additions & 74 deletions

File tree

app/tests/archives_tests/test_signals.py

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
@pytest.mark.django_db
1010
@pytest.mark.parametrize("reverse", [True, False])
11-
def test_archive_item_permissions_signal(
12-
client, reverse, django_capture_on_commit_callbacks
13-
):
11+
def test_archive_item_permissions_signal(reverse):
1412
ai1, ai2 = ArchiveItemFactory.create_batch(2)
1513
im1, im2, im3, im4 = ImageFactory.create_batch(4)
1614

@@ -21,19 +19,18 @@ def test_archive_item_permissions_signal(
2119
ComponentInterfaceValueFactory(image=im4),
2220
)
2321

24-
with django_capture_on_commit_callbacks(execute=True):
25-
if reverse:
26-
for civ in [civ1, civ2, civ3, civ4]:
27-
civ.archive_items.add(ai1, ai2)
28-
for civ in [civ3, civ4]:
29-
civ.archive_items.remove(ai1, ai2)
30-
for civ in [civ1, civ2]:
31-
civ.archive_items.remove(ai2)
32-
else:
33-
# Test that adding images works
34-
ai1.values.add(civ1, civ2, civ3, civ4)
35-
# Test that removing images works
36-
ai1.values.remove(civ3, civ4)
22+
if reverse:
23+
for civ in [civ1, civ2, civ3, civ4]:
24+
civ.archive_items.add(ai1, ai2)
25+
for civ in [civ3, civ4]:
26+
civ.archive_items.remove(ai1, ai2)
27+
for civ in [civ1, civ2]:
28+
civ.archive_items.remove(ai2)
29+
else:
30+
# Test that adding images works
31+
ai1.values.add(civ1, civ2, civ3, civ4)
32+
# Test that removing images works
33+
ai1.values.remove(civ3, civ4)
3734

3835
assert get_groups_with_set_perms(im1) == {
3936
ai1.archive.editors_group: {"view_image"},
@@ -49,28 +46,24 @@ def test_archive_item_permissions_signal(
4946
assert get_groups_with_set_perms(im4) == {}
5047

5148
# Test clearing
52-
with django_capture_on_commit_callbacks(execute=True):
53-
if reverse:
54-
civ1.archive_items.clear()
55-
civ2.archive_items.clear()
56-
else:
57-
ai1.values.clear()
49+
if reverse:
50+
civ1.archive_items.clear()
51+
civ2.archive_items.clear()
52+
else:
53+
ai1.values.clear()
5854

5955
assert get_groups_with_set_perms(im1) == {}
6056
assert get_groups_with_set_perms(im2) == {}
6157

6258

6359
@pytest.mark.django_db
64-
def test_deleting_archive_item_removes_permissions(
65-
django_capture_on_commit_callbacks,
66-
):
60+
def test_deleting_archive_item_removes_permissions():
6761
ai1, ai2 = ArchiveItemFactory.create_batch(2)
6862
im = ImageFactory()
6963
civ = ComponentInterfaceValueFactory(image=im)
7064

71-
with django_capture_on_commit_callbacks(execute=True):
72-
ai1.values.set([civ])
73-
ai2.values.set([civ])
65+
ai1.values.set([civ])
66+
ai2.values.set([civ])
7467

7568
assert get_groups_with_set_perms(im) == {
7669
ai1.archive.editors_group: {"view_image"},
@@ -81,8 +74,7 @@ def test_deleting_archive_item_removes_permissions(
8174
ai2.archive.users_group: {"view_image"},
8275
}
8376

84-
with django_capture_on_commit_callbacks(execute=True):
85-
ai1.delete()
77+
ai1.delete()
8678

8779
assert get_groups_with_set_perms(im) == {
8880
ai2.archive.editors_group: {"view_image"},
@@ -92,15 +84,12 @@ def test_deleting_archive_item_removes_permissions(
9284

9385

9486
@pytest.mark.django_db
95-
def test_changing_archive_updates_permissions(
96-
django_capture_on_commit_callbacks,
97-
):
87+
def test_changing_archive_updates_permissions():
9888
ai = ArchiveItemFactory()
9989
im = ImageFactory()
10090
civ = ComponentInterfaceValueFactory(image=im)
10191

102-
with django_capture_on_commit_callbacks(execute=True):
103-
ai.values.set([civ])
92+
ai.values.set([civ])
10493

10594
assert get_groups_with_set_perms(im) == {
10695
ai.archive.editors_group: {"view_image"},
@@ -112,8 +101,7 @@ def test_changing_archive_updates_permissions(
112101

113102
ai.archive = a2
114103

115-
with django_capture_on_commit_callbacks(execute=True):
116-
ai.save()
104+
ai.save()
117105

118106
assert get_groups_with_set_perms(im) == {
119107
a2.editors_group: {"view_image"},

app/tests/reader_studies_tests/test_signals.py

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ def test_assert_modification_allowed():
4949

5050
@pytest.mark.django_db
5151
@pytest.mark.parametrize("reverse", [True, False])
52-
def test_display_set_permissions_signal(
53-
client, reverse, django_capture_on_commit_callbacks
54-
):
52+
def test_display_set_permissions_signal(reverse):
5553
ds1, ds2 = DisplaySetFactory.create_batch(2)
5654
im1, im2, im3, im4 = ImageFactory.create_batch(4)
5755

@@ -62,19 +60,18 @@ def test_display_set_permissions_signal(
6260
ComponentInterfaceValueFactory(image=im4),
6361
)
6462

65-
with django_capture_on_commit_callbacks(execute=True):
66-
if reverse:
67-
for civ in [civ1, civ2, civ3, civ4]:
68-
civ.display_sets.add(ds1, ds2)
69-
for civ in [civ3, civ4]:
70-
civ.display_sets.remove(ds1, ds2)
71-
for civ in [civ1, civ2]:
72-
civ.display_sets.remove(ds2)
73-
else:
74-
# Test that adding images works
75-
ds1.values.add(civ1, civ2, civ3, civ4)
76-
# Test that removing images works
77-
ds1.values.remove(civ3, civ4)
63+
if reverse:
64+
for civ in [civ1, civ2, civ3, civ4]:
65+
civ.display_sets.add(ds1, ds2)
66+
for civ in [civ3, civ4]:
67+
civ.display_sets.remove(ds1, ds2)
68+
for civ in [civ1, civ2]:
69+
civ.display_sets.remove(ds2)
70+
else:
71+
# Test that adding images works
72+
ds1.values.add(civ1, civ2, civ3, civ4)
73+
# Test that removing images works
74+
ds1.values.remove(civ3, civ4)
7875

7976
assert get_groups_with_set_perms(im1) == {
8077
ds1.reader_study.editors_group: {"view_image"},
@@ -88,28 +85,24 @@ def test_display_set_permissions_signal(
8885
assert get_groups_with_set_perms(im4) == {}
8986

9087
# Test clearing
91-
with django_capture_on_commit_callbacks(execute=True):
92-
if reverse:
93-
civ1.display_sets.clear()
94-
civ2.display_sets.clear()
95-
else:
96-
ds1.values.clear()
88+
if reverse:
89+
civ1.display_sets.clear()
90+
civ2.display_sets.clear()
91+
else:
92+
ds1.values.clear()
9793

9894
assert get_groups_with_set_perms(im1) == {}
9995
assert get_groups_with_set_perms(im2) == {}
10096

10197

10298
@pytest.mark.django_db
103-
def test_deleting_display_set_removes_permissions(
104-
django_capture_on_commit_callbacks,
105-
):
99+
def test_deleting_display_set_removes_permissions():
106100
ds1, ds2 = DisplaySetFactory.create_batch(2)
107101
im = ImageFactory()
108102
civ = ComponentInterfaceValueFactory(image=im)
109103

110-
with django_capture_on_commit_callbacks(execute=True):
111-
ds1.values.set([civ])
112-
ds2.values.set([civ])
104+
ds1.values.set([civ])
105+
ds2.values.set([civ])
113106

114107
assert get_groups_with_set_perms(im) == {
115108
ds1.reader_study.editors_group: {"view_image"},
@@ -118,8 +111,7 @@ def test_deleting_display_set_removes_permissions(
118111
ds2.reader_study.readers_group: {"view_image"},
119112
}
120113

121-
with django_capture_on_commit_callbacks(execute=True):
122-
ds1.delete()
114+
ds1.delete()
123115

124116
assert get_groups_with_set_perms(im) == {
125117
ds2.reader_study.editors_group: {"view_image"},
@@ -128,15 +120,12 @@ def test_deleting_display_set_removes_permissions(
128120

129121

130122
@pytest.mark.django_db
131-
def test_changing_reader_study_updates_permissions(
132-
django_capture_on_commit_callbacks,
133-
):
123+
def test_changing_reader_study_updates_permissions():
134124
ds = DisplaySetFactory()
135125
im = ImageFactory()
136126
civ = ComponentInterfaceValueFactory(image=im)
137127

138-
with django_capture_on_commit_callbacks(execute=True):
139-
ds.values.set([civ])
128+
ds.values.set([civ])
140129

141130
assert get_groups_with_set_perms(im) == {
142131
ds.reader_study.editors_group: {"view_image"},
@@ -147,8 +136,7 @@ def test_changing_reader_study_updates_permissions(
147136

148137
ds.reader_study = rs
149138

150-
with django_capture_on_commit_callbacks(execute=True):
151-
ds.save()
139+
ds.save()
152140

153141
assert get_groups_with_set_perms(im) == {
154142
rs.editors_group: {"view_image"},

0 commit comments

Comments
 (0)