Skip to content

Commit 78d89dd

Browse files
committed
Add conditional inclusion of 'default_alt_text' in test assertions based on Wagtail version.
Technically this is a wagtail 6.4+ compatibility fix. But as 6.4 isn't a supported or tested version then 7.0+ is OK.
1 parent 9fcb4a4 commit 78d89dd

1 file changed

Lines changed: 40 additions & 33 deletions

File tree

tests/test_image_chooser_views.py

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.test import TestCase, TransactionTestCase, override_settings
44
from django.urls import reverse, reverse_lazy
55
from testapp.factories import CustomImageFactory
6+
from wagtail import VERSION as WAGTAIL_VERSION
67
from wagtail.test.utils import WagtailTestUtils
78

89
from .utils import TEST_ASSET_ID
@@ -40,18 +41,20 @@ def test_creates_image_if_asset_id_not_recognised(self):
4041
# Assertions
4142
create_object_mock.assert_called_once()
4243
self.assertEqual(response.status_code, 200)
43-
self.assertEqual(
44-
response.json(),
45-
{
46-
"step": "chosen",
47-
"result": {
48-
"id": str(image.id),
49-
"title": image.title,
50-
"preview": mock.ANY,
51-
"edit_url": reverse("wagtailimages:edit", args=[image.id]),
52-
},
44+
expected_json = {
45+
"step": "chosen",
46+
"result": {
47+
"id": str(image.id),
48+
"title": image.title,
49+
"preview": mock.ANY,
50+
"edit_url": reverse("wagtailimages:edit", args=[image.id]),
5351
},
54-
)
52+
}
53+
54+
if WAGTAIL_VERSION >= (7, 0):
55+
expected_json["result"].update({"default_alt_text": image.title})
56+
57+
self.assertEqual(response.json(), expected_json)
5558

5659
@mock.patch("wagtail_bynder.views.image.ImageChosenView.update_object")
5760
def test_uses_existing_image_without_updating(self, update_object_mock):
@@ -67,18 +70,20 @@ def test_uses_existing_image_without_updating(self, update_object_mock):
6770

6871
# Check response content
6972
self.assertEqual(response.status_code, 200)
70-
self.assertEqual(
71-
response.json(),
72-
{
73-
"step": "chosen",
74-
"result": {
75-
"id": str(image.id),
76-
"title": image.title,
77-
"preview": mock.ANY,
78-
"edit_url": reverse("wagtailimages:edit", args=[image.id]),
79-
},
73+
expected_json = {
74+
"step": "chosen",
75+
"result": {
76+
"id": str(image.id),
77+
"title": image.title,
78+
"preview": mock.ANY,
79+
"edit_url": reverse("wagtailimages:edit", args=[image.id]),
8080
},
81-
)
81+
}
82+
83+
if WAGTAIL_VERSION >= (7, 0):
84+
expected_json["result"].update({"default_alt_text": image.title})
85+
86+
self.assertEqual(response.json(), expected_json)
8287

8388
@override_settings(BYNDER_SYNC_EXISTING_IMAGES_ON_CHOOSE=True)
8489
@mock.patch("wagtail_bynder.views.image.ImageChosenView.update_object")
@@ -94,15 +99,17 @@ def test_uses_existing_image_and_updates_it(self, update_object_mock):
9499

95100
# Check response content
96101
self.assertEqual(response.status_code, 200)
97-
self.assertEqual(
98-
response.json(),
99-
{
100-
"step": "chosen",
101-
"result": {
102-
"id": str(image.id),
103-
"title": image.title,
104-
"preview": mock.ANY,
105-
"edit_url": reverse("wagtailimages:edit", args=[image.id]),
106-
},
102+
expected_json = {
103+
"step": "chosen",
104+
"result": {
105+
"id": str(image.id),
106+
"title": image.title,
107+
"preview": mock.ANY,
108+
"edit_url": reverse("wagtailimages:edit", args=[image.id]),
107109
},
108-
)
110+
}
111+
112+
if WAGTAIL_VERSION >= (7, 0):
113+
expected_json["result"].update({"default_alt_text": image.title})
114+
115+
self.assertEqual(response.json(), expected_json)

0 commit comments

Comments
 (0)