def test_preview_size(self, pngcrush_image_mock): addon = Addon.objects.get(pk=3615) name = 'non-animated.gif' form = forms.PreviewForm({ 'caption': 'test', 'upload_hash': name, 'position': 1 }) with storage.open(os.path.join(self.dest, name), 'w') as f: copyfileobj(open(get_image_path(name)), f) assert form.is_valid() form.save(addon) preview = addon.previews.all()[0] assert preview.sizes == ({ u'image': [250, 297], u'thumbnail': [126, 150], u'original': [250, 297] }) assert os.path.exists(preview.image_path) assert os.path.exists(preview.thumbnail_path) assert os.path.exists(preview.original_path) assert pngcrush_image_mock.call_count == 2 assert pngcrush_image_mock.call_args_list[0][0][0] == ( preview.thumbnail_path) assert pngcrush_image_mock.call_args_list[1][0][0] == ( preview.image_path)
def setUp(self): super(TestValidateFile, self).setUp() assert self.client.login(email='*****@*****.**') self.user = UserProfile.objects.get(email='*****@*****.**') self.file = File.objects.get(pk=100456) # Move the file into place as if it were a real file with storage.open(self.file.file_path, 'w') as dest: copyfileobj(open(self.file_path('invalid-id-20101206.xpi')), dest) self.addon = self.file.version.addon
def test_preview_modified(self, update_mock): addon = Addon.objects.get(pk=3615) name = 'transparent.png' form = forms.PreviewForm({'caption': 'test', 'upload_hash': name, 'position': 1}) with storage.open(os.path.join(self.dest, name), 'w') as f: copyfileobj(open(get_image_path(name)), f) assert form.is_valid() form.save(addon) assert update_mock.called
def test_preview_size(self): addon = Addon.objects.get(pk=3615) name = 'non-animated.gif' form = forms.PreviewForm({'caption': 'test', 'upload_hash': name, 'position': 1}) with storage.open(os.path.join(self.dest, name), 'w') as f: copyfileobj(open(get_image_path(name)), f) assert form.is_valid() form.save(addon) assert addon.previews.all()[0].sizes == ( {u'image': [250, 297], u'thumbnail': [126, 150]})
def test_icon_modified(self, update_mock): name = 'transparent.png' form = forms.AddonFormMedia({'icon_upload_hash': name}, request=self.request, instance=self.addon) dest = os.path.join(self.icon_path, name) with storage.open(dest, 'w') as f: copyfileobj(open(get_image_path(name)), f) assert form.is_valid() form.save(addon=self.addon) assert update_mock.called
def run_validator(path, for_appversions=None, test_all_tiers=False, overrides=None, compat=False, listed=True): """A pre-configured wrapper around the addon validator. *file_path* Path to addon / extension file to validate. *for_appversions=None* An optional dict of application versions to validate this addon for. The key is an application GUID and its value is a list of versions. *test_all_tiers=False* When False (default) the validator will not continue if it encounters fatal errors. When True, all tests in all tiers are run. See bug 615426 for discussion on this default. *overrides=None* Normally the validator gets info from the manifest but there are a few things we need to override. See validator for supported overrides. Example: {'targetapp_maxVersion': {'<app guid>': '<version>'}} *compat=False* Set this to `True` when performing a bulk validation. This allows the validator to ignore certain tests that should not be run during bulk validation (see bug 735841). *listed=True* If the addon is unlisted, treat it as if it was a self hosted one (don't fail on the presence of an updateURL). To validate the addon for compatibility with Firefox 5 and 6, you'd pass in:: for_appversions={amo.FIREFOX.guid: ['5.0.*', '6.0.*']} Not all application versions will have a set of registered compatibility tests. """ from validator.validate import validate apps = dump_apps.Command.get_json_path() if not os.path.exists(apps): call_command('dump_apps') suffix = '_' + os.path.basename(path) with NamedTemporaryFile(suffix=suffix, dir=settings.TMP_PATH) as temp: if path and not os.path.exists(path) and storage.exists(path): # This file doesn't exist locally. Write it to our # currently-open temp file and switch to that path. copyfileobj(storage.open(path), temp.file) path = temp.name with statsd.timer('devhub.validator'): json_result = validate( path, for_appversions=for_appversions, format='json', # When False, this flag says to stop testing after one # tier fails. determined=test_all_tiers, approved_applications=apps, overrides=overrides, compat_test=compat, listed=listed) track_validation_stats(json_result) return json_result
def run_validator(path, for_appversions=None, test_all_tiers=False, overrides=None, compat=False, listed=True): """A pre-configured wrapper around the addon validator. *file_path* Path to addon / extension file to validate. *for_appversions=None* An optional dict of application versions to validate this addon for. The key is an application GUID and its value is a list of versions. *test_all_tiers=False* When False (default) the validator will not continue if it encounters fatal errors. When True, all tests in all tiers are run. See bug 615426 for discussion on this default. *overrides=None* Normally the validator gets info from the manifest but there are a few things we need to override. See validator for supported overrides. Example: {'targetapp_maxVersion': {'<app guid>': '<version>'}} *compat=False* Set this to `True` when performing a bulk validation. This allows the validator to ignore certain tests that should not be run during bulk validation (see bug 735841). *listed=True* If the addon is unlisted, treat it as if it was a self hosted one (don't fail on the presence of an updateURL). To validate the addon for compatibility with Firefox 5 and 6, you'd pass in:: for_appversions={amo.FIREFOX.guid: ['5.0.*', '6.0.*']} Not all application versions will have a set of registered compatibility tests. """ from validator.validate import validate apps = dump_apps.Command.JSON_PATH if not os.path.exists(apps): call_command('dump_apps') with NamedTemporaryFile(suffix='_' + os.path.basename(path)) as temp: if path and not os.path.exists(path) and storage.exists(path): # This file doesn't exist locally. Write it to our # currently-open temp file and switch to that path. copyfileobj(storage.open(path), temp.file) path = temp.name with statsd.timer('devhub.validator'): json_result = validate( path, for_appversions=for_appversions, format='json', # When False, this flag says to stop testing after one # tier fails. determined=test_all_tiers, approved_applications=apps, overrides=overrides, compat_test=compat, listed=listed ) track_validation_stats(json_result) return json_result