Skip to content

Commit

Permalink
Fixed failing test for Wagtail 5.2+ (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubMastalerz authored Jan 5, 2024
1 parent 5818f7b commit 25927d1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 34 additions & 1 deletion tests/test_image_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 = """
Expand Down

0 comments on commit 25927d1

Please sign in to comment.