Skip to content

Commit 01e8af5

Browse files
ashutoshkrrissherwinski
authored andcommitted
feat(srcset): added testcases to test customization of target device pixel ratios
1 parent 9eb8742 commit 01e8af5

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

tests/test_srcset.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,92 @@ def test_create_srcset_with_less_than_five_variable_qualities():
130130
assert expected == actual
131131

132132

133+
def test_create_srcset_with_custom_serial_target_dpr():
134+
ub = imgix.UrlBuilder(DOMAIN, include_library_param=False)
135+
actual = ub.create_srcset(
136+
JPG_PATH,
137+
{"w": 100},
138+
{"device_pixel_ratios": [1, 2]},
139+
)
140+
expected = (
141+
"https://testing.imgix.net/image.jpg?dpr=1&q=75&w=100 1x,\n"
142+
+ "https://testing.imgix.net/image.jpg?dpr=2&q=50&w=100 2x"
143+
)
144+
145+
assert expected == actual
146+
147+
148+
def test_create_srcset_with_custom_random_target_dpr():
149+
ub = imgix.UrlBuilder(DOMAIN, include_library_param=False)
150+
actual = ub.create_srcset(
151+
JPG_PATH,
152+
{"w": 100},
153+
{"device_pixel_ratios": [1, 4]},
154+
)
155+
expected = (
156+
"https://testing.imgix.net/image.jpg?dpr=1&q=75&w=100 1x,\n"
157+
+ "https://testing.imgix.net/image.jpg?dpr=4&q=23&w=100 4x"
158+
)
159+
160+
assert expected == actual
161+
162+
163+
def test_create_srcset_with_custom_serial_target_dpr_and_variable_qualities():
164+
ub = imgix.UrlBuilder(DOMAIN, include_library_param=False)
165+
actual = ub.create_srcset(
166+
JPG_PATH,
167+
{"w": 100},
168+
{
169+
"device_pixel_ratios": [1, 2, 3],
170+
"variable_qualities": {1: 100, 2: 90, 3: 80},
171+
},
172+
)
173+
expected = (
174+
"https://testing.imgix.net/image.jpg?dpr=1&q=100&w=100 1x,\n"
175+
+ "https://testing.imgix.net/image.jpg?dpr=2&q=90&w=100 2x,\n"
176+
+ "https://testing.imgix.net/image.jpg?dpr=3&q=80&w=100 3x"
177+
)
178+
179+
assert expected == actual
180+
181+
182+
def test_create_srcset_with_less_random_target_dpr_and_variable_qualities():
183+
ub = imgix.UrlBuilder(DOMAIN, include_library_param=False)
184+
actual = ub.create_srcset(
185+
JPG_PATH,
186+
{"w": 100},
187+
{
188+
"device_pixel_ratios": [1, 3],
189+
"variable_qualities": {1: 100, 2: 90, 3: 80},
190+
},
191+
)
192+
expected = (
193+
"https://testing.imgix.net/image.jpg?dpr=1&q=100&w=100 1x,\n"
194+
+ "https://testing.imgix.net/image.jpg?dpr=3&q=80&w=100 3x"
195+
)
196+
197+
assert expected == actual
198+
199+
200+
def test_create_srcset_with_random_target_dpr_and_less_variable_qualities():
201+
ub = imgix.UrlBuilder(DOMAIN, include_library_param=False)
202+
actual = ub.create_srcset(
203+
JPG_PATH,
204+
{"w": 100},
205+
{
206+
"device_pixel_ratios": [1, 2, 3],
207+
"variable_qualities": {1: 100, 3: 80},
208+
},
209+
)
210+
expected = (
211+
"https://testing.imgix.net/image.jpg?dpr=1&q=100&w=100 1x,\n"
212+
"https://testing.imgix.net/image.jpg?dpr=2&q=50&w=100 2x,\n"
213+
+ "https://testing.imgix.net/image.jpg?dpr=3&q=80&w=100 3x"
214+
)
215+
216+
assert expected == actual
217+
218+
133219
def test_create_srcset_start_equals_stop():
134220
ub = imgix.UrlBuilder(DOMAIN, include_library_param=False)
135221
actual = ub.create_srcset(JPG_PATH, start=713, stop=713)

0 commit comments

Comments
 (0)