def test_saves_promo_img(self, requests_mock, crush_mock): img_path = os.path.join(settings.ROOT, 'mkt', 'site', 'tests', 'images', 'game_1050.jpg') # Mock the image fetch request. with open(img_path, 'r') as content: requests_mock.return_value = mock.Mock( content=content.read(), headers={'ok': 'ok'}, status_code=200) result = fetch_promo_imgs(self.website.pk, 'http://mocked_url.ly') ok_(result) website = Website.objects.all()[0] eq_(website.promo_img_hash, '215dd2a2') # Check the actual saved image on disk. img_dir = website.get_promo_img_dir() for size in mkt.PROMO_IMG_SIZES: img_path = os.path.join(img_dir, '%s-%s.png' % (str(website.id), size)) with public_storage.open(img_path, 'r') as img: checker = ImageCheck(img) assert checker.is_image() eq_(checker.img.size[0], size)
def test_saves_promo_img(self, requests_mock, crush_mock): img_path = os.path.join(settings.ROOT, 'mkt', 'site', 'tests', 'images', 'game_1050.jpg') # Mock the image fetch request. with open(img_path, 'r') as content: requests_mock.return_value = mock.Mock(content=content.read(), headers={'ok': 'ok'}, status_code=200) result = fetch_promo_imgs(self.website.pk, 'http://mocked_url.ly') ok_(result) website = Website.objects.all()[0] eq_(website.promo_img_hash, '215dd2a2') # Check the actual saved image on disk. img_dir = website.get_promo_img_dir() for size in mkt.PROMO_IMG_SIZES: img_path = os.path.join(img_dir, '%s-%s.png' % (str(website.id), size)) with public_storage.open(img_path, 'r') as img: checker = ImageCheck(img) assert checker.is_image() eq_(checker.img.size[0], size)
def set_promo_imgs(self, instance, row): promo_img_url = self.clean_string(row["Promo Img URL"]) if promo_img_url: self.validate_url(promo_img_url) promo_img = fetch_promo_imgs(instance.pk, promo_img_url) if not promo_img: raise ValidationError("Promo img for %s failed fetching." % instance.name) else: raise ParsingError(u"%s has no icon" % (row["Name"],))
def set_promo_imgs(self, instance, row): promo_img_url = self.clean_string(row['Promo Img URL']) if promo_img_url: self.validate_url(promo_img_url) promo_img = fetch_promo_imgs(instance.pk, promo_img_url) if not promo_img: raise ValidationError('Promo img for %s failed fetching.' % instance.name) else: raise ParsingError(u'%s has no icon' % (row['Name'],))