1313from plone .restapi .interfaces import IFieldSerializer
1414from plone .restapi .serializer .dxfields import DefaultFieldSerializer
1515from plone .restapi .testing import PLONE_RESTAPI_DX_INTEGRATION_TESTING
16- from plone .scale import storage
16+ from plone .restapi . tests . helpers import patch_scale_uuid
1717from plone .uuid .interfaces import IUUID
1818from unittest import TestCase
19- from unittest .mock import patch
2019from z3c .form .interfaces import IDataManager
2120from zope .component import getMultiAdapter
2221from zope .interface .verify import verifyClass
@@ -387,7 +386,8 @@ def test_namedimage_field_serialization_returns_dict_with_original_scale(self):
387386 with open (image_file , "rb" ) as f :
388387 image_data = f .read ()
389388 fn = "test_namedimage_field"
390- with patch .object (storage , "uuid4" , return_value = "uuid_1" ):
389+ scale_url_uuid = "uuid_1"
390+ with patch_scale_uuid (scale_url_uuid ):
391391 value = self .serialize (
392392 fn ,
393393 NamedImage (
@@ -396,7 +396,6 @@ def test_namedimage_field_serialization_returns_dict_with_original_scale(self):
396396 )
397397 self .assertTrue (isinstance (value , dict ), "Not a <dict>" )
398398
399- scale_url_uuid = "uuid_1"
400399 obj_url = self .doc1 .absolute_url ()
401400
402401 # Original image is still a "scale"
@@ -483,7 +482,8 @@ def test_namedimage_field_serialization_doesnt_choke_on_corrupt_image(self):
483482 is returned as is and we need to check it, but the scales should be empty"""
484483 image_data = b"INVALID IMAGE DATA"
485484 fn = "test_namedimage_field"
486- with patch .object (storage , "uuid4" , return_value = "uuid_1" ):
485+ scale_url_uuid = "uuid_1"
486+ with patch_scale_uuid (scale_url_uuid ):
487487 value = self .serialize (
488488 fn ,
489489 NamedImage (
@@ -492,7 +492,6 @@ def test_namedimage_field_serialization_doesnt_choke_on_corrupt_image(self):
492492 )
493493
494494 obj_url = self .doc1 .absolute_url ()
495- scale_url_uuid = "uuid_1"
496495 self .assertEqual (
497496 {
498497 "content-type" : "image/gif" ,
@@ -514,7 +513,8 @@ def test_namedblobimage_field_serialization_returns_dict_with_original_scale(sel
514513 with open (image_file , "rb" ) as f :
515514 image_data = f .read ()
516515 fn = "test_namedblobimage_field"
517- with patch .object (storage , "uuid4" , return_value = "uuid_1" ):
516+ scale_url_uuid = "uuid_1"
517+ with patch_scale_uuid (scale_url_uuid ):
518518 value = self .serialize (
519519 fn ,
520520 NamedBlobImage (
@@ -523,7 +523,6 @@ def test_namedblobimage_field_serialization_returns_dict_with_original_scale(sel
523523 )
524524 self .assertTrue (isinstance (value , dict ), "Not a <dict>" )
525525
526- scale_url_uuid = "uuid_1"
527526 obj_url = self .doc1 .absolute_url ()
528527
529528 # Original image is still a "scale"
@@ -610,7 +609,8 @@ def test_namedblobimage_field_serialization_doesnt_choke_on_corrupt_image(self):
610609 is returned as is and we need to check it, but the scales should be empty"""
611610 image_data = b"INVALID IMAGE DATA"
612611 fn = "test_namedblobimage_field"
613- with patch .object (storage , "uuid4" , return_value = "uuid_1" ):
612+ scale_url_uuid = "uuid_1"
613+ with patch_scale_uuid (scale_url_uuid ):
614614 value = self .serialize (
615615 fn ,
616616 NamedBlobImage (
@@ -619,7 +619,6 @@ def test_namedblobimage_field_serialization_doesnt_choke_on_corrupt_image(self):
619619 )
620620
621621 obj_url = self .doc1 .absolute_url ()
622- scale_url_uuid = "uuid_1"
623622 self .assertEqual (
624623 {
625624 "content-type" : "image/gif" ,
0 commit comments