Skip to content

Commit eaac447

Browse files
ashutoshkrrissherwinski
authored andcommitted
feat(urlbuilder): ability to allow less than 5 variable qualities
1 parent e5e5fd0 commit eaac447

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

imgix/urlbuilder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def _build_srcset_DPR(
331331
variable_qualities = options.get("variable_qualities", {})
332332
if variable_qualities:
333333
validate_variable_qualities(variable_qualities)
334+
targets = range(1, len(variable_qualities)+1)
334335

335336
qualities = {**DPR_QUALITIES, **variable_qualities}
336337

tests/test_srcset.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,22 @@ def test_create_srcset_with_variable_qualities():
114114
assert expected == actual
115115

116116

117+
def test_create_srcset_with_less_than_five_variable_qualities():
118+
ub = imgix.UrlBuilder(DOMAIN, include_library_param=False)
119+
actual = ub.create_srcset(
120+
JPG_PATH,
121+
{"w": 100},
122+
{"variable_qualities": {1: 100, 2: 90, 3: 80}},
123+
)
124+
expected = (
125+
"https://testing.imgix.net/image.jpg?dpr=1&q=100&w=100 1x,\n"
126+
+ "https://testing.imgix.net/image.jpg?dpr=2&q=90&w=100 2x,\n"
127+
+ "https://testing.imgix.net/image.jpg?dpr=3&q=80&w=100 3x"
128+
)
129+
130+
assert expected == actual
131+
132+
117133
def test_create_srcset_start_equals_stop():
118134
ub = imgix.UrlBuilder(DOMAIN, include_library_param=False)
119135
actual = ub.create_srcset(JPG_PATH, start=713, stop=713)

0 commit comments

Comments
 (0)