1313from test .test_api import MOCK_RESPONSE , NEXT_CURSOR
1414from test .test_config import CLOUD_NAME , API_KEY , API_SECRET
1515
16+ CUSTOM_AGGREGATION = {"type" : "bytes" ,
17+ "ranges" : [{"key" : "tiny" , "to" : 500 }, {"key" : "medium" , "from" : 501 , "to" : 1999 },
18+ {"key" : "big" , "from" : 2000 }]}
19+
1620TEST_TAG = 'search_{}' .format (TEST_TAG )
1721UNIQUE_TAG = 'search_{}' .format (UNIQUE_TAG )
1822
@@ -100,6 +104,11 @@ def test_should_add_aggregations_arguments_as_array_as_dict(self):
100104 query = Search ().aggregate ('format' ).aggregate ('size_category' ).as_dict ()
101105 self .assertEqual (query , {"aggregate" : ["format" , "size_category" ]})
102106
107+ @unittest .skipUnless (cloudinary .config ().api_secret , "requires api_key/api_secret" )
108+ def test_should_add_custom_aggregations_arguments_as_array_as_dict (self ):
109+ query = Search ().aggregate ('format' ).aggregate ('size_category' ).aggregate (CUSTOM_AGGREGATION ).as_dict ()
110+ self .assertEqual (query , {"aggregate" : ["format" , "size_category" , CUSTOM_AGGREGATION ]})
111+
103112 @unittest .skipUnless (cloudinary .config ().api_secret , "requires api_key/api_secret" )
104113 def test_should_add_with_field_as_dict (self ):
105114
@@ -204,14 +213,16 @@ def test_should_include_context_tags_and_image_metadata(self):
204213 @patch (URLLIB3_REQUEST )
205214 def test_should_not_duplicate_values (self , mocker ):
206215 mocker .return_value = MOCK_RESPONSE
207-
216+ override_custom_aggregation = dict ( CUSTOM_AGGREGATION , ranges = [])
208217 Search () \
209218 .sort_by ('created_at' , 'asc' ) \
210219 .sort_by ('public_id' , 'asc' ) \
211220 .sort_by ('created_at' ) \
212221 .aggregate ('format' ) \
213222 .aggregate ('format' ) \
214223 .aggregate (['resource_type' , 'type' ]) \
224+ .aggregate (override_custom_aggregation ) \
225+ .aggregate (CUSTOM_AGGREGATION ) \
215226 .with_field ('context' ) \
216227 .with_field ('context' ) \
217228 .with_field ('tags' ) \
@@ -228,7 +239,7 @@ def test_should_not_duplicate_values(self, mocker):
228239 {'created_at' : 'desc' },
229240 {'public_id' : 'asc' },
230241 ],
231- 'aggregate' : ['format' , 'resource_type' , 'type' ],
242+ 'aggregate' : ['format' , 'resource_type' , 'type' , CUSTOM_AGGREGATION ],
232243 'with_field' : ['context' , 'tags' ],
233244 'fields' : ['tags' , 'context' , 'metadata' ],
234245 })
0 commit comments