Exemplo n.º 1
0
 def test_foreign_url(self):
     """ if someone tries to thumbnail an image not at MEDIA_ROOT return it unchanged """
     path = "http://www.notus.com/path/to/img.jpg"
     attrs = compute_img(path, "resize", "100x100")
     self.assertEqual(attrs['height'], '')
     self.assertEqual(attrs['width'], '')
     self.assertEqual(attrs['src'], path)
Exemplo n.º 2
0
 def test_bad_geo(self):
     """ if the geometry won't parse we should return the original image and it's width/height """
     with patch("lazythumbs.util.quack", self.get_fake_quack("path/img.jpg", width=10, height=20)):
         attrs = compute_img(Mock(), "resize", "XsxeX")
         self.assertEqual(attrs["src"], settings.MEDIA_URL + "path/img.jpg")
         self.assertEqual(attrs["width"], "10")
         self.assertEqual(attrs["height"], "20")
Exemplo n.º 3
0
 def test_no_url(self):
     """ If there is no url all attrs shoudl be '' """
     with patch("lazythumbs.util.quack", self.get_fake_quack(width=10, height=20)):
         attrs = compute_img(Mock(), "resize", "100x200")
         self.assertEqual(attrs["src"], "")
         self.assertEqual(attrs["width"], "")
         self.assertEqual(attrs["height"], "")
Exemplo n.º 4
0
 def test_thumb_height(self):
     """ thumbnail with height only computes the proper height """
     with patch("lazythumbs.util.quack", self.get_fake_quack("path/img.jpg", width=100, height=200)):
         attrs = compute_img(Mock(), "thumbnail", "x10")
         self.assertEqual(attrs["src"], settings.LAZYTHUMBS_URL + "lt_cache/thumbnail/5/path/img.jpg")
         self.assertEqual(attrs["width"], "5")
         self.assertEqual(attrs["height"], "10")
Exemplo n.º 5
0
 def test_bad_geo(self):
     """ if the geometry won't parse we should return the original image and it's width/height """
     with patch('lazythumbs.util.quack', self.get_fake_quack('path/img.jpg', width=10, height=20)):
         attrs = compute_img(Mock(), 'resize', 'XsxeX')
         self.assertEqual(attrs['src'], settings.MEDIA_URL + 'path/img.jpg')
         self.assertEqual(attrs['width'], '10')
         self.assertEqual(attrs['height'], '20')
Exemplo n.º 6
0
 def test_no_url(self):
     """ If there is no url all attrs shoudl be '' """
     with patch('lazythumbs.util.quack', self.get_fake_quack(width=10, height=20)):
         attrs = compute_img(Mock(), 'resize', '100x200')
         self.assertEqual(attrs['src'], '')
         self.assertEqual(attrs['width'], '')
         self.assertEqual(attrs['height'], '')
Exemplo n.º 7
0
 def test_thumb_height(self):
     """ thumbnail with height only computes the proper height """
     with patch('lazythumbs.util.quack', self.get_fake_quack('path/img.jpg', width=100, height=200)):
         attrs = compute_img(Mock(), 'thumbnail', 'x10')
         self.assertEqual(attrs['src'], settings.LAZYTHUMBS_URL + 'lt_cache/thumbnail/5/path/img.jpg')
         self.assertEqual(attrs['width'], '5')
         self.assertEqual(attrs['height'], '10')
Exemplo n.º 8
0
 def test_foreign_url(self):
     """ if someone tries to thumbnail an image not at MEDIA_ROOT return it unchanged """
     path = "http://www.notus.com/path/to/img.jpg"
     attrs = compute_img(path, "resize", "100x100")
     self.assertEqual(attrs["height"], "")
     self.assertEqual(attrs["width"], "")
     self.assertEqual(attrs["src"], path)
Exemplo n.º 9
0
 def test_LAZYTHUMGS_DUMMY(self):
     settings.LAZYTHUMBS_DUMMY = True
     url = settings.MEDIA_URL + 'path/img.jpg'
     attrs = compute_img(url, "resize", "200x200")
     self.assertEqual(attrs['height'], '200')
     self.assertEqual(attrs['width'], '200')
     self.assertEqual(attrs['src'], 'http://placekitten.com/200/200')
     settings.LAZYTHUMBS_DUMMY = False
Exemplo n.º 10
0
 def test_no_url(self):
     """ If there is no url all attrs shoudl be '' """
     with patch('lazythumbs.util.quack',
                self.get_fake_quack(width=10, height=20)):
         attrs = compute_img(Mock(), 'resize', '100x200')
         self.assertEqual(attrs['src'], '')
         self.assertEqual(attrs['width'], '')
         self.assertEqual(attrs['height'], '')
Exemplo n.º 11
0
 def test_bad_geo(self):
     """ if the geometry won't parse we should return the original image and it's width/height """
     with patch('lazythumbs.util.quack',
                self.get_fake_quack('path/img.jpg', width=10, height=20)):
         attrs = compute_img(Mock(), 'resize', 'XsxeX')
         self.assertEqual(attrs['src'], settings.MEDIA_URL + 'path/img.jpg')
         self.assertEqual(attrs['width'], '10')
         self.assertEqual(attrs['height'], '20')
Exemplo n.º 12
0
 def test_LAZYTHUMGS_DUMMY(self):
     settings.LAZYTHUMBS_DUMMY = True
     url = settings.MEDIA_URL + 'path/img.jpg'
     attrs = compute_img(url, "resize", "200x200")
     self.assertEqual(attrs['height'], '200')
     self.assertEqual(attrs['width'], '200')
     self.assertEqual(attrs['src'], 'http://placekitten.com/200/200')
     settings.LAZYTHUMBS_DUMMY = False
Exemplo n.º 13
0
 def test_thumb_both(self):
     """ thumbnail with both dimensions works """
     old_x_for_dim = getattr(settings, "LAZYTHUMBS_USE_X_FOR_DIMENSIONS", None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     with patch("lazythumbs.util.quack", self.get_fake_quack("path/img.jpg", width=100, height=200)):
         attrs = compute_img(Mock(), "thumbnail", "5x5")
         self.assertEqual(attrs["src"], settings.LAZYTHUMBS_URL + "lt_cache/thumbnail/5/path/img.jpg")
         self.assertEqual(attrs["width"], "5")
         self.assertEqual(attrs["height"], "5")
Exemplo n.º 14
0
 def test_thumb_both(self):
     """ thumbnail with both dimensions works """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS', None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     with patch('lazythumbs.util.quack', self.get_fake_quack('path/img.jpg', width=100, height=200)):
         attrs = compute_img(Mock(), 'thumbnail', '5x5')
         self.assertEqual(attrs['src'], settings.LAZYTHUMBS_URL + 'lt_cache/thumbnail/5/path/img.jpg')
         self.assertEqual(attrs['width'], '5')
         self.assertEqual(attrs['height'], '5')
Exemplo n.º 15
0
 def test_geometry_responsive(self):
     """ thumbnail with responsive geometry should give us a placeholder """
     attrs = compute_img('path/img.jpg', 'resize', 'responsive')
     self.assertEqual(attrs['height'], '')
     self.assertEqual(attrs['width'], '')
     self.assertEqual(
         attrs['src'],
         "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
     )
Exemplo n.º 16
0
 def test_height_resize(self):
     """ resize with only height returns the proper path and size """
     old_x_for_dim = getattr(settings, "LAZYTHUMBS_USE_X_FOR_DIMENSIONS", None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     with patch("lazythumbs.util.quack", self.get_fake_quack("path/img.jpg", width=100, height=200)):
         attrs = compute_img(Mock(), "resize", "x5")
         self.assertEqual(attrs["src"], settings.LAZYTHUMBS_URL + "lt_cache/resize/5/5/path/img.jpg")
         self.assertEqual(attrs["width"], "5")
         self.assertEqual(attrs["height"], "5")
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 17
0
 def test_width_bigger_than_img(self):
     """  """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS', None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     with patch('lazythumbs.util.quack', self.get_fake_quack('path/img.jpg', width=100, height=200)):
         attrs = compute_img(Mock(), 'resize', '300')
         self.assertEqual(attrs['src'], settings.MEDIA_URL + 'path/img.jpg')
         self.assertEqual(attrs['width'], '100')
         self.assertEqual(attrs['height'], '200')
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 18
0
 def test_local_url(self):
     """ if thing is a url and it's local we can attempt to resize it """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS', None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     url = settings.MEDIA_URL + 'path/img.jpg'
     attrs = compute_img(url, "resize", "200x200")
     self.assertEqual(attrs['height'], '200')
     self.assertEqual(attrs['width'], '200')
     self.assertEqual(attrs['src'], settings.LAZYTHUMBS_URL + 'lt_cache/resize/200/200/path/img.jpg')
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 19
0
 def test_width_bigger_than_img_force_scale(self):
     """ if the force_scale parameter is passed, scale image even though it is smaller """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS', None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     with patch('lazythumbs.util.quack', self.get_fake_quack('path/img.jpg', width=100, height=200)):
         attrs = compute_img(Mock(), 'mresize', '200x400', options={'force_scale': 'true'})
         self.assertEqual(attrs['src'], settings.LAZYTHUMBS_URL + 'lt_cache/mresize/200/400/path/img.jpg')
         self.assertEqual(attrs['width'], '200')
         self.assertEqual(attrs['height'], '400')
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 20
0
 def test_height_resize(self):
     """ resize with only height returns the proper path and size """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS', None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     with patch('lazythumbs.util.quack', self.get_fake_quack('path/img.jpg', width=100, height=200)):
         attrs = compute_img(Mock(), 'resize', 'x5')
         self.assertEqual(attrs['src'], settings.LAZYTHUMBS_URL + 'lt_cache/resize/5/5/path/img.jpg')
         self.assertEqual(attrs['width'], '5')
         self.assertEqual(attrs['height'], '5')
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 21
0
 def test_local_url(self):
     """ if thing is a url and it's local we can attempt to resize it """
     old_x_for_dim = getattr(settings, "LAZYTHUMBS_USE_X_FOR_DIMENSIONS", None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     url = settings.MEDIA_URL + "path/img.jpg"
     attrs = compute_img(url, "resize", "200x200")
     self.assertEqual(attrs["height"], "200")
     self.assertEqual(attrs["width"], "200")
     self.assertEqual(attrs["src"], settings.LAZYTHUMBS_URL + "lt_cache/resize/200/200/path/img.jpg")
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 22
0
 def test_mapped_secondary_url(self):
     """ if someone tries to thumbnail an image for different known url, mapping should be done """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS', None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     path = "http://example.com/media/path/to/img.jpg"
     attrs = compute_img(path, "resize", "100x100")
     self.assertEqual(attrs['height'], '100')
     self.assertEqual(attrs['width'], '100')
     self.assertEqual(attrs['src'], 'http://example.com/media/lt/lt_cache/resize/100/100/path/to/img.jpg')
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 23
0
 def test_thumb_height(self):
     """ thumbnail with height only computes the proper height """
     with patch('lazythumbs.util.quack',
                self.get_fake_quack('path/img.jpg', width=100, height=200)):
         attrs = compute_img(Mock(), 'thumbnail', 'x10')
         self.assertEqual(
             attrs['src'],
             settings.LAZYTHUMBS_URL + 'lt_cache/thumbnail/5/path/img.jpg')
         self.assertEqual(attrs['width'], '5')
         self.assertEqual(attrs['height'], '10')
Exemplo n.º 24
0
    def render(self, context):

        thing = self.thing.resolve(context)
        action = self.action
        geometry = self.geometry.resolve(context)

        context.push()
        context[self.as_var] = compute_img(thing, action, geometry)
        output = self.nodelist.render(context)
        context.pop()
        return output
Exemplo n.º 25
0
    def render(self, context):

        thing = self.thing.resolve(context)
        action = self.action
        geometry = self.geometry.resolve(context)

        context.push()
        context[self.as_var] = compute_img(thing, action, geometry)
        output = self.nodelist.render(context)
        context.pop()
        return output
Exemplo n.º 26
0
 def test_width_bigger_than_img(self):
     """  """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS',
                             None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     with patch('lazythumbs.util.quack',
                self.get_fake_quack('path/img.jpg', width=100, height=200)):
         attrs = compute_img(Mock(), 'resize', '300')
         self.assertEqual(attrs['src'], settings.MEDIA_URL + 'path/img.jpg')
         self.assertEqual(attrs['width'], '100')
         self.assertEqual(attrs['height'], '200')
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 27
0
 def test_thumb_both(self):
     """ thumbnail with both dimensions works """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS',
                             None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     with patch('lazythumbs.util.quack',
                self.get_fake_quack('path/img.jpg', width=100, height=200)):
         attrs = compute_img(Mock(), 'thumbnail', '5x5')
         self.assertEqual(
             attrs['src'],
             settings.LAZYTHUMBS_URL + 'lt_cache/thumbnail/5/path/img.jpg')
         self.assertEqual(attrs['width'], '5')
         self.assertEqual(attrs['height'], '5')
Exemplo n.º 28
0
 def test_local_url(self):
     """ if thing is a url and it's local we can attempt to resize it """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS',
                             None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     url = settings.MEDIA_URL + 'path/img.jpg'
     attrs = compute_img(url, "resize", "200x200")
     self.assertEqual(attrs['height'], '200')
     self.assertEqual(attrs['width'], '200')
     self.assertEqual(
         attrs['src'],
         settings.LAZYTHUMBS_URL + 'lt_cache/resize/200/200/path/img.jpg')
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 29
0
 def test_height_resize(self):
     """ resize with only height returns the proper path and size """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS',
                             None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     with patch('lazythumbs.util.quack',
                self.get_fake_quack('path/img.jpg', width=100, height=200)):
         attrs = compute_img(Mock(), 'resize', 'x5')
         self.assertEqual(
             attrs['src'],
             settings.LAZYTHUMBS_URL + 'lt_cache/resize/5/5/path/img.jpg')
         self.assertEqual(attrs['width'], '5')
         self.assertEqual(attrs['height'], '5')
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 30
0
 def test_mapped_secondary_url(self):
     """ if someone tries to thumbnail an image for different known url, mapping should be done """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS',
                             None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     path = "http://example.com/media/path/to/img.jpg"
     attrs = compute_img(path, "resize", "100x100")
     self.assertEqual(attrs['height'], '100')
     self.assertEqual(attrs['width'], '100')
     self.assertEqual(
         attrs['src'],
         'http://example.com/media/lt/lt_cache/resize/100/100/path/to/img.jpg'
     )
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 31
0
    def render(self, context):

        thing = self.thing.resolve(context)
        action = self.action
        geometry = self.geometry.resolve(context)

        options = {}
        for k, v in self.kwargs.items():
            options[k] = v.resolve(context)

        context.push()
        context[self.as_var] = compute_img(thing, action, geometry, options)
        output = self.nodelist.render(context)
        context.pop()
        return output
Exemplo n.º 32
0
    def render(self, context):

        thing = self.thing.resolve(context)
        action = self.action
        geometry = self.geometry.resolve(context)

        options = {}
        for k, v in self.kwargs.items():
            options[k] = v.resolve(context)

        context.push()
        context[self.as_var] = compute_img(thing, action, geometry, options)
        output = self.nodelist.render(context)
        context.pop()
        return output
Exemplo n.º 33
0
 def test_width_bigger_than_img_force_scale(self):
     """ if the force_scale parameter is passed, scale image even though it is smaller """
     old_x_for_dim = getattr(settings, 'LAZYTHUMBS_USE_X_FOR_DIMENSIONS',
                             None)
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = False
     with patch('lazythumbs.util.quack',
                self.get_fake_quack('path/img.jpg', width=100, height=200)):
         attrs = compute_img(Mock(),
                             'mresize',
                             '200x400',
                             options={'force_scale': 'true'})
         self.assertEqual(
             attrs['src'], settings.LAZYTHUMBS_URL +
             'lt_cache/mresize/200/400/path/img.jpg')
         self.assertEqual(attrs['width'], '200')
         self.assertEqual(attrs['height'], '400')
     settings.LAZYTHUMBS_USE_X_FOR_DIMENSIONS = old_x_for_dim
Exemplo n.º 34
0
 def test_geometry_responsive(self):
     """ thumbnail with responsive geometry should give us a placeholder """
     attrs = compute_img('path/img.jpg', 'resize', 'responsive')
     self.assertEqual(attrs['height'], '')
     self.assertEqual(attrs['width'], '')
     self.assertEqual(attrs['src'], "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")