changeset 8f911b65cb65 in modules/product_image:6.2 details: https://hg.tryton.org/modules/product_image?cmd=changeset&node=8f911b65cb65 description: Manage index argument to construct image URL
issue11455 review427091003 (grafted from d62a7a2497d1a8db58425f31f60769a787251cb2) diffstat: product.py | 3 +++ tests/test_product_image.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 0 deletions(-) diffs (51 lines): diff -r 9d6593b0497f -r 8f911b65cb65 product.py --- a/product.py Mon Nov 01 17:08:10 2021 +0100 +++ b/product.py Wed May 11 23:18:12 2022 +0200 @@ -47,9 +47,12 @@ })) if args: size = args.pop('s', None) + index = args.pop('i', None) args = {k: int(bool(v)) for k, v in args.items()} if size: args['s'] = size + if index is not None: + args['i'] = index url += '?' + urlencode(args) return url diff -r 9d6593b0497f -r 8f911b65cb65 tests/test_product_image.py --- a/tests/test_product_image.py Mon Nov 01 17:08:10 2021 +0100 +++ b/tests/test_product_image.py Wed May 11 23:18:12 2022 +0200 @@ -42,6 +42,31 @@ img = PIL.Image.open(io.BytesIO(image.get(size=100))) self.assertEqual(img.size, (100, 100)) + @with_transaction() + def test_get_image_url(self): + "Test get_image_url" + pool = Pool() + Image = pool.get('product.image') + Template = pool.get('product.template') + Uom = pool.get('product.uom') + + template = Template(name="Template", code="CODE") + template.default_uom, = Uom.search([], limit=1) + template.save() + + for _ in range(3): + image = Image(template=template) + image.image = urllib.request.urlopen( + 'https://picsum.photos/200').read() + image.save() + + self.assertRegex( + template.get_image_url(i=2), + r'/product/image/CODE/.*/Template\?i=2') + self.assertRegex( + template.get_image_url(s=400), + r'/product/image/CODE/.*/Template\?s=400') + def suite(): suite = test_suite()