def setUp(self): self.provider = ImgixImageResizingProvider() self.patch_g( imgix_domain='example.com', imgix_signing=False, s3_media_direct=False, )
class TestImgixResizer(RedditTestCase): def setUp(self): self.provider = ImgixImageResizingProvider() self.patch_g( imgix_domain='example.com', imgix_signing=False, ) def test_no_resize(self): image = dict(url='http://s3.amazonaws.com/a.jpg', width=1200, height=800) url = self.provider.resize_image(image) self.assertEqual(url, 'https://example.com/a.jpg') def test_too_small(self): image = dict(url='http://s3.amazonaws.com/a.jpg', width=12, height=8) with self.assertRaises(NotLargeEnough): self.provider.resize_image(image, 108) def test_resize(self): image = dict(url='http://s3.amazonaws.com/a.jpg', width=1200, height=800) for width in (108, 216, 320, 640, 960, 1080): url = self.provider.resize_image(image, width) self.assertEqual(url, 'https://example.com/a.jpg?w=%d' % width) def test_cropping(self): image = dict(url='http://s3.amazonaws.com/a.jpg', width=1200, height=800) max_ratio = 0.5 url = self.provider.resize_image(image, max_ratio=max_ratio) crop = URLENCODED_COMMA.join(('faces', 'entropy')) self.assertEqual(url, ('https://example.com/a.jpg?fit=crop&crop=%s&arh=%s' % (crop, max_ratio))) width = 108 url = self.provider.resize_image(image, width, max_ratio=max_ratio) self.assertEqual(url, ('https://example.com/a.jpg?fit=crop&crop=%s&arh=%s&w=%s' % (crop, max_ratio, width))) def test_sign_url(self): u = UrlParser('http://examples.imgix.net/frog.jpg?w=100') signed_url = self.provider._sign_url(u, 'abcdef') self.assertEqual(signed_url.unparse(), 'http://examples.imgix.net/frog.jpg?w=100&s=cd3bdf071108af73b15c21bdcee5e49c') u = UrlParser('http://examples.imgix.net/frog.jpg') u.update_query(w=100) signed_url = self.provider._sign_url(u, 'abcdef') self.assertEqual(signed_url.unparse(), 'http://examples.imgix.net/frog.jpg?w=100&s=cd3bdf071108af73b15c21bdcee5e49c') def test_censor(self): image = dict(url='http://s3.amazonaws.com/a.jpg', width=1200, height=800) url = self.provider.resize_image(image, censor_nsfw=True) self.assertEqual(url, 'https://example.com/a.jpg?blur=600&px=32')
class TestImgixResizer(RedditTestCase): def setUp(self): self.provider = ImgixImageResizingProvider() self.patch_g( imgix_domain='example.com', imgix_signing=False, ) def test_no_resize(self): image = dict(url='http://s3.amazonaws.com/a.jpg', width=1200, height=800) url = self.provider.resize_image(image) self.assertEqual(url, 'https://example.com/a.jpg') def test_too_small(self): image = dict(url='http://s3.amazonaws.com/a.jpg', width=12, height=8) with self.assertRaises(NotLargeEnough): self.provider.resize_image(image, 108) def test_resize(self): image = dict(url='http://s3.amazonaws.com/a.jpg', width=1200, height=800) for width in (108, 216, 320, 640, 960, 1080): url = self.provider.resize_image(image, width) self.assertEqual(url, 'https://example.com/a.jpg?w=%d' % width) def test_cropping(self): image = dict(url='http://s3.amazonaws.com/a.jpg', width=1200, height=800) max_ratio = 0.5 url = self.provider.resize_image(image, max_ratio=max_ratio) crop = URLENCODED_COMMA.join(('faces', 'entropy')) self.assertEqual(url, ('https://example.com/a.jpg?fit=crop&crop=%s&arh=%s' % (crop, max_ratio))) width = 108 url = self.provider.resize_image(image, width, max_ratio=max_ratio) self.assertEqual( url, ('https://example.com/a.jpg?fit=crop&crop=%s&arh=%s&w=%s' % (crop, max_ratio, width))) def test_sign_url(self): u = UrlParser('http://examples.imgix.net/frog.jpg?w=100') signed_url = self.provider._sign_url(u, 'abcdef') self.assertEqual( signed_url.unparse(), 'http://examples.imgix.net/frog.jpg?w=100&s=cd3bdf071108af73b15c21bdcee5e49c' ) u = UrlParser('http://examples.imgix.net/frog.jpg') u.update_query(w=100) signed_url = self.provider._sign_url(u, 'abcdef') self.assertEqual( signed_url.unparse(), 'http://examples.imgix.net/frog.jpg?w=100&s=cd3bdf071108af73b15c21bdcee5e49c' ) def test_censor(self): image = dict(url='http://s3.amazonaws.com/a.jpg', width=1200, height=800) url = self.provider.resize_image(image, censor_nsfw=True) self.assertEqual(url, 'https://example.com/a.jpg?blur=600&px=32')
def setUpClass(cls): cls.provider = ImgixImageResizingProvider() cls.old_imgix_domain = g.imgix_domain g.imgix_domain = 'example.com' cls.old_imgix_signing = g.imgix_signing g.imgix_signing = False