Example #1
0
def test_version_dict():
    assert version_dict('5.0.*') == ({
        'major': 5,
        'minor1': 0,
        'minor2': 65535,
        'minor3': None,
        'alpha': None,
        'alpha_ver': None,
        'pre': None,
        'pre_ver': None
    })

    assert version_dict('5.0.*', asterisk_value=1234) == ({
        'major': 5,
        'minor1': 0,
        'minor2': 1234,
        'minor3': None,
        'alpha': None,
        'alpha_ver': None,
        'pre': None,
        'pre_ver': None
    })

    assert version_dict('*.0.*', asterisk_value='@') == ({
        'major': '@',
        'minor1': 0,
        'minor2': '@',
        'minor3': None,
        'alpha': None,
        'alpha_ver': None,
        'pre': None,
        'pre_ver': None
    })
Example #2
0
 def put(self, request, *args, **kwargs):
     # For each request, we'll try to create up to 3 versions for each app,
     # one for the parameter in the URL, one for the corresponding "release"
     # version if it's different (if 79.0a1 is passed, the base would be
     # 79.0. If 79.0 is passed, then we'd skip that one as they are the
     # same) and a last one for the corresponding max version with a star
     # (if 79.0 or 79.0a1 is passed, then this would be 79.*)
     # We validate the app parameter, but always try to create the versions
     # for both Firefox and Firefox for Android anyway, because at the
     # extension manifest level there is no difference so for validation
     # purposes we want to keep both in sync.
     application = amo.APPS.get(kwargs.get('application'))
     if not application:
         raise ParseError('Invalid application parameter')
     requested_version = kwargs.get('version')
     if not requested_version or not version_re.match(requested_version):
         raise ParseError('Invalid version parameter')
     version_data = version_dict(requested_version)
     release_version = '%d.%d' % (version_data['major'], version_data['minor1'] or 0)
     star_version = '%d.*' % version_data['major']
     created_firefox = self.create_versions_for_app(
         application=amo.FIREFOX,
         requested_version=requested_version,
         release_version=release_version,
         star_version=star_version,
     )
     created_android = self.create_versions_for_app(
         application=amo.ANDROID,
         requested_version=requested_version,
         release_version=release_version,
         star_version=star_version,
     )
     created = created_firefox or created_android
     status_code = HTTP_201_CREATED if created else HTTP_202_ACCEPTED
     return Response(status=status_code)
Example #3
0
 def fix_max_appversion_for_version(self, version):
     for app in (amo.FIREFOX, amo.ANDROID):
         if app not in version.compatible_apps:
             log.info(
                 'Version %s for addon %s min version is not compatible '
                 'with %s, skipping this version for that app.', version,
                 version.addon, app.pretty)
             continue
         if version.compatible_apps[app].max.version != '*':
             log.info(
                 'Version %s for addon %s max version is not "*" for %s '
                 'app, skipping this version for that app.', version,
                 version.addon, app.pretty)
             continue
         min_appversion_str = version.compatible_apps[app].min.version
         max_appversion_str = '%d.*' % version_dict(
             min_appversion_str)['major']
         log.warn(
             'Version %s for addon %s min version is %s for %s app, '
             'max will be changed to %s instead of *', version,
             version.addon, min_appversion_str, app.pretty,
             max_appversion_str)
         max_appversion = AppVersion.objects.get(application=app.id,
                                                 version=max_appversion_str)
         version.compatible_apps[app].max = max_appversion
         version.compatible_apps[app].save()
Example #4
0
def version_sidebar(request, form_data, aggregations):
    appver = ''
    # If appver is in the request, we read it cleaned via form_data.
    if 'appver' in request.GET or form_data.get('appver'):
        appver = form_data.get('appver')

    app = unicode(request.APP.pretty)
    exclude_versions = getattr(request.APP, 'exclude_versions', [])
    # L10n: {0} is an application, such as Firefox. This means "any version of
    # Firefox."
    rv = [FacetLink(_(u'Any {0}').format(app), dict(appver='any'), not appver)]
    vs = [dict_from_int(f['key']) for f in aggregations['appversions']]

    # Insert the filtered app version even if it's not a facet.
    av_dict = version_dict(appver)

    if av_dict and av_dict not in vs and av_dict['major']:
        vs.append(av_dict)

    # Valid versions must be in the form of `major.minor`.
    vs = set((v['major'], v['minor1'] if v['minor1'] not in (None, 99) else 0)
             for v in vs)
    versions = ['%s.%s' % v for v in sorted(vs, reverse=True)]

    for version, floated in zip(versions, map(float, versions)):
        if (floated not in exclude_versions
                and floated > request.APP.min_display_version):
            rv.append(
                FacetLink('%s %s' % (app, version), dict(appver=version),
                          appver == version))
    return rv
Example #5
0
def version_sidebar(request, form_data, aggregations):
    appver = ''
    # If appver is in the request, we read it cleaned via form_data.
    if 'appver' in request.GET or form_data.get('appver'):
        appver = form_data.get('appver')

    app = unicode(request.APP.pretty)
    exclude_versions = getattr(request.APP, 'exclude_versions', [])
    # L10n: {0} is an application, such as Firefox. This means "any version of
    # Firefox."
    rv = [FacetLink(_(u'Any {0}').format(app), dict(appver='any'), not appver)]
    vs = [dict_from_int(f['key']) for f in aggregations['appversions']]

    # Insert the filtered app version even if it's not a facet.
    av_dict = version_dict(appver)

    if av_dict and av_dict not in vs and av_dict['major']:
        vs.append(av_dict)

    # Valid versions must be in the form of `major.minor`.
    vs = set((v['major'], v['minor1'] if v['minor1'] not in (None, 99) else 0)
             for v in vs)
    versions = ['%s.%s' % v for v in sorted(vs, reverse=True)]

    for version, floated in zip(versions, map(float, versions)):
        if (floated not in exclude_versions and
                floated > request.APP.min_display_version):
            rv.append(FacetLink('%s %s' % (app, version), dict(appver=version),
                                appver == version))
    return rv
Example #6
0
 def put(self, request, *args, **kwargs):
     # For each request, we'll try to create up to 3 versions, one for the
     # parameter in the URL, one for the corresponding "release" version if
     # it's different (if 79.0a1 is passed, the base would be 79.0. If 79.0
     # is passed, then we'd skip that one as they are the same) and a last
     # one for the corresponding max version with a star (if 79.0 or 79.0a1
     # is passed, then this would be 79.*)
     application = amo.APPS.get(kwargs.get('application'))
     if not application:
         raise ParseError('Invalid application parameter')
     requested_version = kwargs.get('version')
     if not requested_version or not version_re.match(requested_version):
         raise ParseError('Invalid version parameter')
     version_data = version_dict(requested_version)
     release_version = '%d.%d' % (version_data['major'],
                                  version_data['minor1'] or 0)
     star_version = '%d.*' % version_data['major']
     _, created_requested = AppVersion.objects.get_or_create(
         application=application.id, version=requested_version)
     if requested_version != release_version:
         _, created_release = AppVersion.objects.get_or_create(
             application=application.id, version=release_version)
     else:
         created_release = False
     if requested_version != star_version:
         _, created_star = AppVersion.objects.get_or_create(
             application=application.id, version=star_version)
     else:
         created_star = False
     created = created_requested or created_release or created_star
     status_code = HTTP_201_CREATED if created else HTTP_202_ACCEPTED
     return Response(status=status_code)
Example #7
0
def test_version_dict():
    assert version_dict('5.0') == (
        {'major': 5,
         'minor1': 0,
         'minor2': None,
         'minor3': None,
         'alpha': None,
         'alpha_ver': None,
         'pre': None,
         'pre_ver': None})
Example #8
0
def test_version_dict():
    assert version_dict('5.0') == ({
        'major': 5,
        'minor1': 0,
        'minor2': None,
        'minor3': None,
        'alpha': None,
        'alpha_ver': None,
        'pre': None,
        'pre_ver': None
    })
Example #9
0
 def __init__(self, *args, **kwargs):
     super(AppVersion, self).__init__(*args, **kwargs)
     # Add all the major, minor, ..., version attributes to the object.
     self.__dict__.update(compare.version_dict(self.version or ''))
Example #10
0
 def __init__(self, *args, **kwargs):
     super(AppVersion, self).__init__(*args, **kwargs)
     # Add all the major, minor, ..., version attributes to the object.
     self.__dict__.update(compare.version_dict(self.version or ''))