def test_preview_size(self): name = "non-animated.gif" form = forms.PreviewForm({"caption": "test", "upload_hash": name, "position": 1}) with storage.open(os.path.join(self.dest, name), "wb") as f: copyfileobj(open(get_image_path(name)), f) assert form.is_valid(), form.errors form.save(self.addon) eq_(self.addon.previews.all()[0].sizes, {u"image": [250, 297], u"thumbnail": [180, 214]})
def setUp(self): self.webapp_path = tempfile.mktemp(suffix='.webapp') with storage.open(self.webapp_path, 'wb') as f: copyfileobj(open(os.path.join(os.path.dirname(__file__), 'addons', 'mozball.webapp')), f) self.tmp_files = [] self.manifest = dict(name=u'Ivan Krsti\u0107', version=u'1.0', description=u'summary')
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 setUp(self): super(TestValidateFile, self).setUp() assert self.client.login(username="******", password="******") 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 upload(self, name): v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={})) fname = nfd_str(self.xpi_path(name)) if not storage.exists(fname): with storage.open(fname, 'w') as fs: copyfileobj(open(fname), fs) d = dict(path=fname, name='%s.xpi' % name, hash='sha256:%s' % name, validation=v) return FileUpload.objects.create(**d)
def setUp(self): super(TestValidateFile, self).setUp() assert self.client.login(username='******', password='******') 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): name = 'non-animated.gif' form = forms.PreviewForm({'upload_hash': name, 'position': 1}) with storage.open(os.path.join(self.dest, name), 'wb') as f: copyfileobj(open(get_image_path(name)), f) assert form.is_valid(), form.errors form.save(self.addon) eq_(self.addon.previews.all()[0].sizes, {u'image': [250, 297], u'thumbnail': [180, 214]})
def test_preview_size(self): name = 'non-animated.gif' form = forms.PreviewForm({'upload_hash': name, 'position': 1}) with storage.open(os.path.join(self.dest, name), 'wb') as f: copyfileobj(open(get_image_path(name)), f) assert form.is_valid(), form.errors form.save(self.addon) eq_(self.addon.previews.all()[0].sizes, {u'image': [250, 297], u'thumbnail': [100, 119]})
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) eq_(addon.previews.all()[0].sizes, {u'image': [250, 297], u'thumbnail': [126, 150]})
def upload(self, name): if os.path.splitext(name)[-1] not in [".xml", ".xpi", ".jar"]: name = name + ".xpi" v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={})) fname = nfd_str(self.xpi_path(name)) if not storage.exists(fname): with storage.open(fname, "w") as fs: copyfileobj(open(fname), fs) d = dict(path=fname, name=name, hash="sha256:%s" % name, validation=v) return FileUpload.objects.create(**d)
def upload(self, name): if os.path.splitext(name)[-1] not in ['.xml', '.xpi', '.jar']: name = name + '.xpi' v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={})) fname = nfd_str(self.xpi_path(name)) if not storage.exists(fname): with storage.open(fname, 'w') as fs: copyfileobj(open(fname), fs) d = dict(path=fname, name=name, hash='sha256:%s' % name, validation=v) return FileUpload.objects.create(**d)
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 upload(self, name): if os.path.splitext(name)[-1] not in ['.xml', '.xpi', '.jar']: name = name + '.xpi' v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={}, signing_summary={'trivial': 0, 'low': 0, 'medium': 0, 'high': 0}, passed_auto_validation=1)) fname = nfd_str(self.xpi_path(name)) if not storage.exists(fname): with storage.open(fname, 'w') as fs: copyfileobj(open(fname), fs) d = dict(path=fname, name=name, hash='sha256:%s' % name, validation=v) return FileUpload.objects.create(**d)
def run_validator(file_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 install.rdf 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') path = file_path if path and not os.path.exists(path) and storage.exists(path): path = tempfile.mktemp(suffix='_' + os.path.basename(file_path)) with open(path, 'wb') as f: copyfileobj(storage.open(file_path), f) temp = True else: temp = False try: with statsd.timer('devhub.validator'): return 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, spidermonkey=settings.SPIDERMONKEY, overrides=overrides, timeout=settings.VALIDATOR_TIMEOUT, compat_test=compat, listed=listed) finally: if temp: os.remove(path)
def packaged_copy_over(self, dest, name): with storage.open(dest, 'wb') as f: copyfileobj(open(self.packaged_app_path(name)), f)
def manifest_copy_over(self, dest, name): with storage.open(dest, 'wb') as f: copyfileobj(open(self.manifest_path(name)), f)
def run_validator(file_path, for_appversions=None, test_all_tiers=False, overrides=None): """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 install.rdf but there are a few things we need to override. See validator for supported overrides. Example: {'targetapp_maxVersion': {'<app guid>': '<version>'}} 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 # TODO(Kumar) remove this when validator is fixed, see bug 620503 from validator.testcases import scripting scripting.SPIDERMONKEY_INSTALLATION = settings.SPIDERMONKEY import validator.constants validator.constants.SPIDERMONKEY_INSTALLATION = settings.SPIDERMONKEY apps = dump_apps.Command.JSON_PATH if not os.path.exists(apps): call_command('dump_apps') path = file_path if path and not os.path.exists(path) and storage.exists(path): path = tempfile.mktemp(suffix='_' + os.path.basename(file_path)) with open(path, 'wb') as f: copyfileobj(storage.open(file_path), f) temp = True else: temp = False try: with statsd.timer('devhub.validator'): return 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, spidermonkey=settings.SPIDERMONKEY, overrides=overrides, timeout=settings.VALIDATOR_TIMEOUT) finally: if temp: os.remove(path)
def run_validator(file_path, for_appversions=None, test_all_tiers=False, overrides=None, compat=False): """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 install.rdf 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). 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') path = file_path if path and not os.path.exists(path) and storage.exists(path): path = tempfile.mktemp(suffix='_' + os.path.basename(file_path)) with open(path, 'wb') as f: copyfileobj(storage.open(file_path), f) temp = True else: temp = False try: with statsd.timer('devhub.validator'): return 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, spidermonkey=settings.SPIDERMONKEY, overrides=overrides, timeout=settings.VALIDATOR_TIMEOUT, compat_test=compat) finally: if temp: os.remove(path)
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 install.rdf 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. """ if not settings.VALIDATE_ADDONS: # This should only ever be set on development instances. # Don't run the validator, just return a skeleton passing result set. results = deepcopy(amo.VALIDATOR_SKELETON_RESULTS) results['metadata']['listed'] = listed return json.dumps(results) 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, spidermonkey=settings.SPIDERMONKEY, 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 install.rdf 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. """ if not settings.VALIDATE_ADDONS: # This should only ever be set on development instances. # Don't run the validator, just return a skeleton passing result set. results = deepcopy(amo.VALIDATOR_SKELETON_RESULTS) results['metadata']['listed'] = listed return json.dumps(results) 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, spidermonkey=settings.SPIDERMONKEY, overrides=overrides, compat_test=compat, listed=listed) track_validation_stats(json_result) return json_result