def run_validator(file_path, url=None): """A pre-configured wrapper around the app validator.""" temp_path = None # Make a copy of the file since we can't assume the # uploaded file is on the local filesystem. temp_path = tempfile.mktemp() copy_stored_file( file_path, temp_path, src_storage=private_storage, dst_storage=local_storage) with statsd.timer('mkt.developers.validator'): is_packaged = zipfile.is_zipfile(temp_path) if is_packaged: log.info(u'Running `validate_packaged_app` for path: %s' % (file_path)) with statsd.timer('mkt.developers.validate_packaged_app'): return validate_packaged_app( temp_path, market_urls=settings.VALIDATOR_IAF_URLS, timeout=settings.VALIDATOR_TIMEOUT, spidermonkey=settings.SPIDERMONKEY) else: log.info(u'Running `validate_app` for path: %s' % (file_path)) with statsd.timer('mkt.developers.validate_app'): return validate_app(open(temp_path).read(), market_urls=settings.VALIDATOR_IAF_URLS, url=url) # Clean up copied files. os.unlink(temp_path)
def run_validator(file_path, url=None): """A pre-configured wrapper around the app validator.""" temp_path = None # Make a copy of the file since we can't assume the # uploaded file is on the local filesystem. temp_path = tempfile.mktemp() with open(temp_path, "wb") as local_f: with private_storage.open(file_path) as remote_f: copyfileobj(remote_f, local_f) with statsd.timer("mkt.developers.validator"): is_packaged = zipfile.is_zipfile(temp_path) if is_packaged: log.info(u"Running `validate_packaged_app` for path: %s" % (file_path)) with statsd.timer("mkt.developers.validate_packaged_app"): return validate_packaged_app( temp_path, market_urls=settings.VALIDATOR_IAF_URLS, timeout=settings.VALIDATOR_TIMEOUT, spidermonkey=settings.SPIDERMONKEY, ) else: log.info(u"Running `validate_app` for path: %s" % (file_path)) with statsd.timer("mkt.developers.validate_app"): return validate_app(open(temp_path).read(), market_urls=settings.VALIDATOR_IAF_URLS, url=url) # Clean up copied files. os.unlink(temp_path)
def run_validator(file_path): """A pre-configured wrapper around the app validator.""" with statsd.timer('mkt.developers.validator'): is_packaged = zipfile.is_zipfile(file_path) if is_packaged: log.info(u'Running `validate_packaged_app` for path: %s' % (file_path)) with statsd.timer('mkt.developers.validate_packaged_app'): return validate_packaged_app(file_path, market_urls=settings.VALIDATOR_IAF_URLS, timeout=settings.VALIDATOR_TIMEOUT, spidermonkey=settings.SPIDERMONKEY) else: log.info(u'Running `validate_app` for path: %s' % (file_path)) with statsd.timer('mkt.developers.validate_app'): return validate_app(storage.open(file_path).read(), market_urls=settings.VALIDATOR_IAF_URLS)
def run_validator(file_path): """A pre-configured wrapper around the app validator.""" # 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 with statsd.timer('mkt.developers.validator'): is_packaged = zipfile.is_zipfile(file_path) if is_packaged: log.info(u'Running `validate_packaged_app` for path: %s' % (file_path)) with statsd.timer('mkt.developers.validate_packaged_app'): return validate_packaged_app(file_path, market_urls=settings.VALIDATOR_IAF_URLS, timeout=settings.VALIDATOR_TIMEOUT) else: log.info(u'Running `validate_app` for path: %s' % (file_path)) with statsd.timer('mkt.developers.validate_app'): return validate_app(storage.open(file_path).read(), market_urls=settings.VALIDATOR_IAF_URLS)
import sys from appvalidator import validate_app, validate_packaged_app path = sys.argv[1] if path.endswith(".webapp"): print validate_app(path, format="json") else: print validate_packaged_app(path, format="json")
def test_webapp_new(): """Test that webapps can be validated.""" with open("tests/resources/testwebapp.webapp") as file_: out = validate_app(file_.read()) j = json.loads(out) assert j["success"], "Expected not to fail: %s" % j
def test_webapp_new(): """Test that webapps can be validated with the new api.""" with open("tests/resources/testwebapp.webapp") as file_: out = validate_app(file_.read()) j = json.loads(out) assert j["success"], "Expected not to fail: %s" % j