Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix resolve_rendition, instantiating ImageRenditionObjectType by hand?! #330

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions grapple/types/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,10 @@ def resolve_rendition(self, info, **kwargs):
# Only allowed the defined filters (thus renditions)
if rendition_allowed(filters):
try:
img = self.get_rendition(filters)
return self.get_rendition(filters)
except SourceImageIOError:
return

rendition_type = get_rendition_type()

return rendition_type(
id=img.id,
url=get_media_item_url(img),
width=img.width,
height=img.height,
file=img.file,
image=self,
)

def resolve_src_set(self, info, sizes, format=None, **kwargs):
"""
Generate src set of renditions.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_grapple.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ def test_query_url_field(self):
executed["data"]["images"][0]["url"], executed["data"]["images"][0]["src"]
)

@unittest.skip("Important!passing this test depends on mering #329")
def test_query_rendition_url_field(self):
query = """
{
Expand Down Expand Up @@ -1035,6 +1036,7 @@ def test_renditions(self):
image(id: %d) {
rendition(width: 100) {
url
customRenditionProperty
}
}
}
Expand All @@ -1044,6 +1046,10 @@ def test_renditions(self):

executed = self.client.execute(query)
self.assertIn("width-100", executed["data"]["image"]["rendition"]["url"])
self.assertIn(
"Rendition Model!",
executed["data"]["image"]["rendition"]["customRenditionProperty"],
)

@override_settings(GRAPPLE={"ALLOWED_IMAGE_FILTERS": ["width-200"]})
def test_renditions_with_allowed_image_filters_restrictions(self):
Expand Down