changeset 2805176709c9 in modules/product_image:6.4
details: 
https://hg.tryton.org/modules/product_image?cmd=changeset&node=2805176709c9
description:
        Manage index argument to construct image URL

        issue11455
        review427091003
        (grafted from d62a7a2497d1a8db58425f31f60769a787251cb2)
diffstat:

 product.py           |   3 +++
 tests/test_module.py |  25 +++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diffs (50 lines):

diff -r 045aeaaecbf6 -r 2805176709c9 product.py
--- a/product.py        Mon May 02 16:55:00 2022 +0200
+++ 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 045aeaaecbf6 -r 2805176709c9 tests/test_module.py
--- a/tests/test_module.py      Mon May 02 16:55:00 2022 +0200
+++ b/tests/test_module.py      Wed May 11 23:18:12 2022 +0200
@@ -40,5 +40,30 @@
         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')
+
 
 del ModuleTestCase

Reply via email to