From 25927d1239d976412a9fbfc4447460b96015b5d0 Mon Sep 17 00:00:00 2001 From: Jakub Mastalerz <81862675+JakubMastalerz@users.noreply.github.com> Date: Fri, 5 Jan 2024 16:41:03 +0100 Subject: [PATCH] Fixed failing test for Wagtail 5.2+ (#378) --- CHANGELOG.md | 4 ++++ tests/test_image_types.py | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2acb95e1..0f67c8cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Unreleased +### Fixed + +- `test_src_set_invalid_format` not working with Wagtail 5.2 and above. ([#378](https://github.com/torchbox/wagtail-grapple/pull/378)) @JakubMastalerz + ## [0.23.0] - 2023-09-29 ### Added diff --git a/tests/test_image_types.py b/tests/test_image_types.py index 20cc9969..feb0b235 100644 --- a/tests/test_image_types.py +++ b/tests/test_image_types.py @@ -152,7 +152,17 @@ def test_src_set_with_format(self): self.assertIn("width-100.format-webp.webp", data["srcSet"]) self.assertIn("width-300.format-webp.webp", data["srcSet"]) - def test_src_set_invalid_format(self): + @skipIf( + WAGTAIL_VERSION >= (5, 2), + "Exception message is different in Wagtail 5.2+", + ) + def test_src_set_invalid_format_wagtail_below_5_2(self): + """ + Ensure that an exception is raised when image format is not of valid type. + Works with Wagtail versions below 5.2. For versions 5.2 and above see: + `test_src_set_invalid_format_wagtail_above_5_2`. + """ + query = """ query ($id: ID!) { image(id: $id) { @@ -165,6 +175,29 @@ def test_src_set_invalid_format(self): self.assertEqual(len(results["errors"]), 1) self.assertIn("Format must be either 'jpeg'", results["errors"][0]["message"]) + @skipIf( + WAGTAIL_VERSION < (5, 2), + "Exception message is different in Wagtail verions below 5.2", + ) + def test_src_set_invalid_format_wagtail_above_5_2(self): + """ + Ensure that an exception is raised when image format is not of valid type. + Works with Wagtail versions 5.2 and above. For versions below 5.2 see: + `test_src_set_invalid_format_wagtail_below_5_2`. + """ + + query = """ + query ($id: ID!) { + image(id: $id) { + srcSet(sizes: [100, 300], format: "foobar") + } + } + """ + + results = self.client.execute(query, variables={"id": self.example_image.id}) + self.assertEqual(len(results["errors"]), 1) + self.assertIn("Format must be one of: jpeg", results["errors"][0]["message"]) + @override_settings(GRAPPLE={"ALLOWED_IMAGE_FILTERS": ["width-200"]}) def test_src_set_disallowed_filter(self): query = """