예제 #1
0
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
예제 #2
0
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')
예제 #3
0
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")
예제 #4
0
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')
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
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)
예제 #8
0
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
예제 #9
0
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)
예제 #10
0
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)