@@ -78,7 +78,8 @@ def test_to_representation(self, image_upload_file, settings):
78
78
"600" : "/media/testapp/profile/image/600w.webp" ,
79
79
"700" : "/media/testapp/profile/image/700w.webp" ,
80
80
}
81
- }
81
+ },
82
+ "media" : "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px" ,
82
83
},
83
84
"1/1" : {
84
85
"sources" : {
@@ -92,7 +93,8 @@ def test_to_representation(self, image_upload_file, settings):
92
93
"600" : "/media/testapp/profile/image/1/600w.webp" ,
93
94
"700" : "/media/testapp/profile/image/1/700w.webp" ,
94
95
}
95
- }
96
+ },
97
+ "media" : "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px" ,
96
98
},
97
99
"3/2" : {
98
100
"sources" : {
@@ -106,7 +108,8 @@ def test_to_representation(self, image_upload_file, settings):
106
108
"600" : "/media/testapp/profile/image/3_2/600w.webp" ,
107
109
"700" : "/media/testapp/profile/image/3_2/700w.webp" ,
108
110
}
109
- }
111
+ },
112
+ "media" : "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px" ,
110
113
},
111
114
"16/9" : {
112
115
"sources" : {
@@ -120,7 +123,8 @@ def test_to_representation(self, image_upload_file, settings):
120
123
"600" : "/media/testapp/profile/image/16_9/600w.webp" ,
121
124
"700" : "/media/testapp/profile/image/16_9/700w.webp" ,
122
125
}
123
- }
126
+ },
127
+ "media" : "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px" ,
124
128
},
125
129
},
126
130
}
@@ -179,7 +183,7 @@ def test_to_representation__raise_value_error(
179
183
with pytest .raises (ValueError ) as e :
180
184
serializer .data ["image" ]
181
185
182
- assert str (e .value ) == "Invalid ratio : 21/11. Choices are: 1/1, 3/2, 16/9"
186
+ assert str (e .value ) == "Invalid ratios : 21/11. Choices are: 1/1, 3/2, 16/9"
183
187
184
188
@pytest .mark .django_db
185
189
def test_to_representation__blank (self , rf , image_upload_file , settings ):
@@ -195,6 +199,86 @@ def test_to_representation__blank(self, rf, image_upload_file, settings):
195
199
196
200
assert serializer .data ["image" ] is None
197
201
202
+ @pytest .mark .django_db
203
+ def test_to_representation__no_get_params (self , rf , image_upload_file , settings ):
204
+ settings .PICTURES ["USE_PLACEHOLDERS" ] = False
205
+
206
+ profile = models .Profile .objects .create (picture = image_upload_file )
207
+ request = rf .get ("/" )
208
+ request .GET ._mutable = True
209
+ request .GET ["foo" ] = "bar"
210
+ serializer = ProfileSerializer (profile , context = {"request" : request })
211
+ assert serializer .data ["image_mobile" ] == {
212
+ "url" : "/media/testapp/profile/image.png" ,
213
+ "width" : 800 ,
214
+ "height" : 800 ,
215
+ "ratios" : {
216
+ "3/2" : {
217
+ "sources" : {
218
+ "image/webp" : {
219
+ "800" : "/media/testapp/profile/image/3_2/800w.webp" ,
220
+ "100" : "/media/testapp/profile/image/3_2/100w.webp" ,
221
+ "200" : "/media/testapp/profile/image/3_2/200w.webp" ,
222
+ "300" : "/media/testapp/profile/image/3_2/300w.webp" ,
223
+ "400" : "/media/testapp/profile/image/3_2/400w.webp" ,
224
+ "500" : "/media/testapp/profile/image/3_2/500w.webp" ,
225
+ "600" : "/media/testapp/profile/image/3_2/600w.webp" ,
226
+ "700" : "/media/testapp/profile/image/3_2/700w.webp" ,
227
+ }
228
+ },
229
+ "media" : "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px" ,
230
+ }
231
+ },
232
+ }
233
+
234
+ @pytest .mark .django_db
235
+ def test_to_representation__multiple_ratios (self , rf , image_upload_file , settings ):
236
+ settings .PICTURES ["USE_PLACEHOLDERS" ] = False
237
+
238
+ profile = models .Profile .objects .create (picture = image_upload_file )
239
+ request = rf .get ("/" )
240
+ request .GET ._mutable = True
241
+ request .GET .setlist ("image_ratio" , ["3/2" , "16/9" ])
242
+ serializer = ProfileSerializer (profile , context = {"request" : request })
243
+ print (serializer .data ["image" ])
244
+ assert serializer .data ["image" ] == {
245
+ "url" : "/media/testapp/profile/image.png" ,
246
+ "width" : 800 ,
247
+ "height" : 800 ,
248
+ "ratios" : {
249
+ "3/2" : {
250
+ "sources" : {
251
+ "image/webp" : {
252
+ "800" : "/media/testapp/profile/image/3_2/800w.webp" ,
253
+ "100" : "/media/testapp/profile/image/3_2/100w.webp" ,
254
+ "200" : "/media/testapp/profile/image/3_2/200w.webp" ,
255
+ "300" : "/media/testapp/profile/image/3_2/300w.webp" ,
256
+ "400" : "/media/testapp/profile/image/3_2/400w.webp" ,
257
+ "500" : "/media/testapp/profile/image/3_2/500w.webp" ,
258
+ "600" : "/media/testapp/profile/image/3_2/600w.webp" ,
259
+ "700" : "/media/testapp/profile/image/3_2/700w.webp" ,
260
+ }
261
+ },
262
+ "media" : "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px" ,
263
+ },
264
+ "16/9" : {
265
+ "sources" : {
266
+ "image/webp" : {
267
+ "800" : "/media/testapp/profile/image/16_9/800w.webp" ,
268
+ "100" : "/media/testapp/profile/image/16_9/100w.webp" ,
269
+ "200" : "/media/testapp/profile/image/16_9/200w.webp" ,
270
+ "300" : "/media/testapp/profile/image/16_9/300w.webp" ,
271
+ "400" : "/media/testapp/profile/image/16_9/400w.webp" ,
272
+ "500" : "/media/testapp/profile/image/16_9/500w.webp" ,
273
+ "600" : "/media/testapp/profile/image/16_9/600w.webp" ,
274
+ "700" : "/media/testapp/profile/image/16_9/700w.webp" ,
275
+ }
276
+ },
277
+ "media" : "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px" ,
278
+ },
279
+ },
280
+ }
281
+
198
282
@pytest .mark .django_db
199
283
def test_to_representation__with_container (self , rf , image_upload_file , settings ):
200
284
settings .PICTURES ["USE_PLACEHOLDERS" ] = False
@@ -304,7 +388,8 @@ def test_to_representation__with_prefiltered_aspect_ratio_and_source(
304
388
"600" : "/media/testapp/profile/image/3_2/600w.webp" ,
305
389
"700" : "/media/testapp/profile/image/3_2/700w.webp" ,
306
390
}
307
- }
391
+ },
392
+ "media" : "(min-width: 0px) and (max-width: 1199px) 100vw, 1200px" ,
308
393
}
309
394
},
310
395
}
0 commit comments