From 0b6abcfd7db31c3c7804431d733df625c8fda3ac Mon Sep 17 00:00:00 2001
From: Mikel Larreategi
"""
+ self.assertTrue(_ellipsis_match(expected, tag.strip()))
+
+ def testImgSrcSetCustomSrc(self):
+ """test that we can select a custom scale in the src attribute"""
+ self.scaling.available_sizes = {
+ "huge": (1600, 65536),
+ "great": (1200, 65536),
+ "larger": (1000, 65536),
+ "large": (800, 65536),
+ "teaser": (600, 65536),
+ "preview": (400, 65536),
+ "mini": (200, 65536),
+ "thumb": (128, 128),
+ "tile": (64, 64),
+ "icon": (32, 32),
+ "listing": (16, 16),
+ }
+ tag = self.scaling.srcset("image", sizes="50vw", scale_in_src="mini")
+ base = self.item.absolute_url()
+ expected = f"""
"""
+ self.assertTrue(_ellipsis_match(expected, tag.strip()))
+
+ def testImgSrcSetInexistentScale(self):
+ """test that when requesting an inexistent scale for the src attribute
+ we provide the biggest scale we can produce
+ """
+ self.scaling.available_sizes = {
+ "huge": (1600, 65536),
+ "great": (1200, 65536),
+ "larger": (1000, 65536),
+ "large": (800, 65536),
+ "teaser": (600, 65536),
+ "preview": (400, 65536),
+ "mini": (200, 65536),
+ "thumb": (128, 128),
+ "tile": (64, 64),
+ "icon": (32, 32),
+ "listing": (16, 16),
+ }
+ tag = self.scaling.srcset(
+ "image", sizes="50vw", scale_in_src="inexistent-scale-name"
+ )
+ base = self.item.absolute_url()
+ expected = f"""
"""
+ self.assertTrue(_ellipsis_match(expected, tag.strip()))
+
+ def testImgSrcSetCustomTitle(self):
+ """test passing a custom title to the srcset method"""
+ self.scaling.available_sizes = {
+ "huge": (1600, 65536),
+ "great": (1200, 65536),
+ "larger": (1000, 65536),
+ "large": (800, 65536),
+ "teaser": (600, 65536),
+ "preview": (400, 65536),
+ "mini": (200, 65536),
+ "thumb": (128, 128),
+ "tile": (64, 64),
+ "icon": (32, 32),
+ "listing": (16, 16),
+ }
+ tag = self.scaling.srcset("image", sizes="50vw", title="My Custom Title")
+ base = self.item.absolute_url()
+ expected = f"""
"""
+ self.assertTrue(_ellipsis_match(expected, tag.strip()))
+
+ def testImgSrcSetAdditionalAttributes(self):
+ """test that additional parameters are output as is, like alt, loading, ..."""
+ self.scaling.available_sizes = {
+ "huge": (1600, 65536),
+ "great": (1200, 65536),
+ "larger": (1000, 65536),
+ "large": (800, 65536),
+ "teaser": (600, 65536),
+ "preview": (400, 65536),
+ "mini": (200, 65536),
+ "thumb": (128, 128),
+ "tile": (64, 64),
+ "icon": (32, 32),
+ "listing": (16, 16),
+ }
+ tag = self.scaling.srcset(
+ "image",
+ sizes="50vw",
+ alt="This image shows nothing",
+ css_class="my-personal-class",
+ title="My Custom Title",
+ loading="lazy",
+ )
+ base = self.item.absolute_url()
+
+ expected = f"""
"""
+ self.assertTrue(_ellipsis_match(expected, tag.strip()))
+
class ImageTraverseTests(unittest.TestCase):
From 840a82f402bf1500fd90b51178bee3ad71e2ddc1 Mon Sep 17 00:00:00 2001
From: Mikel Larreategi
+srcset allows the browser to select the correct image, depending on the space the image has on a page. +
++To do so, the @@images view provides a srcset method, that will output the full srcset of this image, using all available image scales. It has as required parameter the value of the sizes attribute that the user of this method has to provide and will be output as is in the generated HTML. +
+
+
+
+
+
+
+