99
1010import cloudinary
1111from cloudinary import api , uploader , utils
12+ from cloudinary .utils import fq_public_id
1213from test .helper_test import SUFFIX , TEST_IMAGE , get_uri , get_params , get_list_param , get_param , TEST_DOC , get_method , \
1314 UNIQUE_TAG , api_response_mock , ignore_exception , cleanup_test_resources_by_tag , cleanup_test_transformation , \
1415 cleanup_test_resources , UNIQUE_TEST_FOLDER , EVAL_STR , get_json_body
@@ -461,6 +462,33 @@ def test09_delete_resources_tuple(self, mocker):
461462 self .assertIn (API_TEST_ID , param )
462463 self .assertIn (API_TEST_ID2 , param )
463464
465+ @patch ('urllib3.request.RequestMethods.request' )
466+ @unittest .skipUnless (cloudinary .config ().api_secret , "requires api_key/api_secret" )
467+ def test_add_related_assets (self , mocker ):
468+ """ should allow adding related assets """
469+ mocker .return_value = MOCK_RESPONSE
470+ api .add_related_assets (API_TEST_ID , [fq_public_id (API_TEST_ID2 ), fq_public_id (API_TEST_ID3 )])
471+ args , kargs = mocker .call_args
472+ self .assertEqual (args [0 ], 'POST' )
473+ self .assertTrue (get_uri (args ).endswith ('/resources/related_assets/image/upload/' + API_TEST_ID ))
474+ param = get_json_body (mocker )['assets_to_relate' ]
475+ self .assertIn (fq_public_id (API_TEST_ID2 ), param )
476+ self .assertIn (fq_public_id (API_TEST_ID3 ), param )
477+
478+ @patch ('urllib3.request.RequestMethods.request' )
479+ @unittest .skipUnless (cloudinary .config ().api_secret , "requires api_key/api_secret" )
480+ def test_delete_related_assets (self , mocker ):
481+ """ should allow deleting related assets """
482+ mocker .return_value = MOCK_RESPONSE
483+ api .delete_related_assets (API_TEST_ID , [fq_public_id (API_TEST_ID2 ), fq_public_id (API_TEST_ID3 )])
484+ args , kargs = mocker .call_args
485+ self .assertEqual (args [0 ], 'DELETE' )
486+ self .assertTrue (get_uri (args ).endswith ('/resources/related_assets/image/upload/' + API_TEST_ID ))
487+ param = get_json_body (mocker )['assets_to_unrelate' ]
488+ self .assertIn (fq_public_id (API_TEST_ID2 ), param )
489+ self .assertIn (fq_public_id (API_TEST_ID3 ), param )
490+
491+
464492 @patch ('urllib3.request.RequestMethods.request' )
465493 @unittest .skipUnless (cloudinary .config ().api_secret , "requires api_key/api_secret" )
466494 def test10_tags (self , mocker ):
@@ -869,11 +897,11 @@ def test_delete_folder(self, mocker):
869897 def test_root_folders_allows_next_cursor_and_max_results_parameter (self , mocker ):
870898 """ should allow next_cursor and max_results parameters """
871899 mocker .return_value = MOCK_RESPONSE
872-
900+
873901 api .root_folders (next_cursor = NEXT_CURSOR , max_results = 10 )
874-
902+
875903 args , kwargs = mocker .call_args
876-
904+
877905 self .assertTrue ("next_cursor" in get_params (args ))
878906 self .assertTrue ("max_results" in get_params (args ))
879907
@@ -882,11 +910,11 @@ def test_root_folders_allows_next_cursor_and_max_results_parameter(self, mocker)
882910 def test_subfolders_allows_next_cursor_and_max_results_parameter (self , mocker ):
883911 """ should allow next_cursor and max_results parameters """
884912 mocker .return_value = MOCK_RESPONSE
885-
913+
886914 api .subfolders (API_TEST_ID , next_cursor = NEXT_CURSOR , max_results = 10 )
887-
915+
888916 args , kwargs = mocker .call_args
889-
917+
890918 self .assertTrue ("next_cursor" in get_params (args ))
891919 self .assertTrue ("max_results" in get_params (args ))
892920
@@ -996,26 +1024,22 @@ def test_update_access_control(self, mocker):
9961024 self .assertEqual (exp_acl , params ["access_control" ])
9971025
9981026 @patch ('urllib3.request.RequestMethods.request' )
999- def test_cinemagraph_analysis_resource (self , mocker ):
1000- """ should allow the user to pass cinemagraph_analysis in the resource function """
1027+ def test_various_resource_parameters (self , mocker ):
1028+ """ should allow the user to pass various parameters to the resource function """
10011029 mocker .return_value = MOCK_RESPONSE
10021030
1003- api .resource (API_TEST_ID , cinemagraph_analysis = True )
1004-
1005- params = get_params (mocker .call_args [0 ])
1006-
1007- self .assertIn ("cinemagraph_analysis" , params )
1008-
1009- @patch ('urllib3.request.RequestMethods.request' )
1010- def test_accessibility_analysis_resource (self , mocker ):
1011- """ should allow the user to pass accessibility_analysis in the resource function """
1012- mocker .return_value = MOCK_RESPONSE
1031+ options = {
1032+ "cinemagraph_analysis" : True ,
1033+ "accessibility_analysis" : True ,
1034+ "related" : True ,
1035+ "related_next_cursor" : NEXT_CURSOR ,
1036+ }
10131037
1014- api .resource (API_TEST_ID , accessibility_analysis = True )
1038+ api .resource (TEST_IMAGE , ** options )
10151039
10161040 params = get_params (mocker .call_args [0 ])
1017-
1018- self .assertIn ("accessibility_analysis" , params )
1041+ for param in options . keys ():
1042+ self .assertIn (param , params )
10191043
10201044 @patch ('urllib3.request.RequestMethods.request' )
10211045 def test_api_url_escapes_special_characters (self , mocker ):
0 commit comments