async def do_upload(context, locale): """Upload the language pack for `locale` to AMO. Returns the JSON response from AMO """ locale_info = context.locales[locale] langpack_id = locale_info['id'] version = locale_info['version'] url = get_api_url(context, UPLOAD_VERSION, id=langpack_id, version=version) with open(context.locales[locale]['unsigned'], 'rb') as file: data = { 'channel': get_channel(context.task), 'upload': file, } try: result = await amo_put(context, url, data) except ClientResponseError as exc: # XXX: .code is deprecated in aiohttp 3.1 in favor of .status if exc.status == 409: raise AMOConflictError( "Addon <{}> already present on AMO with version <{}>". format( langpack_id, version, )) # If response code is not 409 - CONFLICT, bubble the exception raise exc return result
def test_get_api_formatted(context): host = 'https://addons.example.com' context.config['amo_server'] = host url = utils.get_api_url(context, 'some/formatted/{api}/path', api='magic_api') assert url.startswith(host) assert url.endswith('some/formatted/magic_api/path')
def test_get_api_formatted(context): host = "https://addons.example.com" context.config["amo_instances"][ "project:releng:addons.mozilla.org:server:dev"]["amo_server"] = host url = utils.get_api_url(context, "some/formatted/{api}/path", api="magic_api") assert url.startswith(host) assert url.endswith("some/formatted/magic_api/path")
def test_get_api_formatted(context): host = 'https://addons.example.com' context.config['amo_instances'][ 'project:releng:addons.mozilla.org:server:dev']['amo_server'] = host url = utils.get_api_url(context, 'some/formatted/{api}/path', api='magic_api') assert url.startswith(host) assert url.endswith('some/formatted/magic_api/path')
async def get_upload_status(context, locale, upload_pk): """Query AMO for the status of a given upload for `locale`. Returns the JSON response from AMO """ locale_info = context.locales[locale] langpack_id = locale_info['id'] version = locale_info['version'] url = get_api_url(context, UPLOAD_STATUS, id=langpack_id, version=version, upload_pk=upload_pk) return await amo_get(context, url)
async def do_upload(context, locale): """Upload the language pack for `locale` to AMO. Returns the JSON response from AMO """ locale_info = context.locales[locale] langpack_id = locale_info['id'] version = locale_info['version'] url = get_api_url(context, UPLOAD_VERSION, id=langpack_id, version=version) with open(context.locales[locale]['unsigned'], 'rb') as file: data = { 'channel': get_channel(context), 'upload': file, } return await amo_put(context, url, data)
async def get_upload_status(context, locale, upload_pk): """Query AMO for the status of a given upload for `locale`. Returns the JSON response from AMO """ locale_info = context.locales[locale] langpack_id = locale_info["id"] version = locale_info["version"] if upload_pk: format_string = UPLOAD_STATUS_PK else: # When the addon was already uploaded with this version we don't have # an upload_pk format_string = UPLOAD_STATUS url = get_api_url(context, format_string, id=langpack_id, version=version, upload_pk=upload_pk) return await amo_get(context, url)
async def add_version(context, version): """Add a new version to AMO. Use the `min_version` here, rather than the string with the buildid etc. Raises: AuthFailedError: If the automation credentials are misconfigured AuthInsufficientPermissionsError: If the automation credentials are missing permissions """ url = get_api_url(context, ADD_VERSION, version=version) try: result = await amo_put(context, url, data=None) except ClientResponseError as exc: if exc.status == 401: raise AuthFailedError("Addonscript credentials are misconfigured") elif exc.status == 403: raise AuthInsufficientPermissionsError("Addonscript creds are missing permissions") raise exc return result
def test_get_api_url(host, path, context): context.config["amo_instances"][ "project:releng:addons.mozilla.org:server:dev"]["amo_server"] = host url = utils.get_api_url(context, path) assert url.startswith(host) assert url.endswith(path)
def test_get_api_url(host, path, context): context.config['amo_server'] = host url = utils.get_api_url(context, path) assert url.startswith(host) assert url.endswith(path)