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

Test showing the difference #1716

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions news/1716.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test to ensure that the scale hash of an image is the same as the hash of the image block with this image. @sneridagh
55 changes: 55 additions & 0 deletions src/plone/restapi/tests/test_content_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from plone.app.testing import TEST_USER_ID
from plone.app.textfield.value import RichTextValue
from plone.namedfile.file import NamedBlobImage
from plone.restapi import HAS_PLONE_6
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from Products.CMFCore.utils import getToolByName
from z3c.relationfield import RelationValue
Expand Down Expand Up @@ -176,3 +177,57 @@ def test_get_content_related_items_without_workflow(self):
],
response.json()["relatedItems"],
)

@unittest.skipUnless(HAS_PLONE_6, "This not working in Plone 5.2")
def test_image_scales_get(self):
from plone.app.testing import applyProfile
from plone.restapi.interfaces import ISerializeToJson
from zope.component import getMultiAdapter

applyProfile(self.portal, "plone.restapi:blocks")

def serialize(self, obj=None):
if obj is None:
obj = self.portal.doc1
serializer = getMultiAdapter((obj, self.request), ISerializeToJson)
return serializer()

self.portal.invokeFactory("Image", id="imagewf")
self.portal.imagewf.title = "Image without workflow"
self.portal.imagewf.description = "This is an image"
image_file = os.path.join(os.path.dirname(__file__), "image.png")
with open(image_file, "rb") as f:
image_data = f.read()
self.portal.imagewf.image = NamedBlobImage(
data=image_data, contentType="image/png", filename="image.png"
)
transaction.commit()

image_uid = self.portal.imagewf.UID()
blocks = {"123": {"@type": "image", "url": f"../resolveuid/{image_uid}"}}
self.portal.invokeFactory("Document", id="doc_with_blocks")
self.portal.doc_with_blocks.blocks = blocks

transaction.commit()

response_image = requests.get(
self.portal.imagewf.absolute_url(),
headers={"Accept": "application/json"},
auth=(SITE_OWNER_NAME, SITE_OWNER_PASSWORD),
)
self.assertEqual(response_image.status_code, 200)
response_image = response_image.json()

response = requests.get(
self.portal.doc_with_blocks.absolute_url(),
headers={"Accept": "application/json"},
auth=(SITE_OWNER_NAME, SITE_OWNER_PASSWORD),
)
self.assertEqual(response.status_code, 200)

self.assertEqual(
response.json()["blocks"]["123"]["image_scales"]["image"][0][
"download"
].split("@@images/")[-1],
response_image["image"]["download"].split("@@images/")[-1],
)
Loading