def test_cmp_strict(self): versions = (('1.5.1', '1.5.2b2', -1), ('161', '3.10a', ValueError), ('8.02', '8.02', 0), ('3.4j', '1996.07.12', ValueError), ('3.2.pl0', '3.1.1.6', ValueError), ('2g6', '11g', ValueError), ('0.9', '2.2', -1), ('1.2.1', '1.2', 1), ('1.1', '1.2.2', -1), ('1.2', '1.1', 1), ('1.2.1', '1.2.2', -1), ('1.2.2', '1.2', 1), ('1.2', '1.2.2', -1), ('0.4.0', '0.4', 0), ('1.13++', '5.5.kw', ValueError)) for v1, v2, wanted in versions: try: res = MozillaVersion(v1).__cmp__(MozillaVersion(v2)) except ValueError: if wanted is ValueError: continue else: raise AssertionError(("cmp(%s, %s) " "shouldn't raise ValueError") % (v1, v2)) self.assertEqual(res, wanted, 'cmp(%s, %s) should be %s, got %s' % (v1, v2, wanted, res))
def shouldServeUpdate(self, updateQuery): buildTarget = updateQuery['buildTarget'] locale = updateQuery['locale'] releaseVersion = self.getApplicationVersion(buildTarget, locale) if not releaseVersion: self.log.debug( "Matching rule has no application version, will not serve update." ) return False releaseVersion = MozillaVersion(releaseVersion) queryVersion = MozillaVersion(updateQuery['version']) if queryVersion > releaseVersion: self.log.debug( "Matching rule has older version than request, will not serve update." ) return False elif releaseVersion == queryVersion: if updateQuery['buildID'] >= self.getBuildID( updateQuery['buildTarget'], updateQuery['locale']): self.log.debug( "Matching rule has older buildid than request, will not serve update." ) return False if updateQuery['buildTarget'] not in self['platforms'].keys(): return False return True
def test_cmp_strict(self): versions = ( ("1.5.1", "1.5.2b2", -1), ("161", "3.10a", BadDataError), ("8.02", "8.02", 0), ("3.4j", "1996.07.12", BadDataError), ("3.2.pl0", "3.1.1.6", BadDataError), ("2g6", "11g", BadDataError), ("0.9", "2.2", -1), ("1.2.1", "1.2", 1), ("1.1", "1.2.2", -1), ("1.2", "1.1", 1), ("1.2.1", "1.2.2", -1), ("1.2.2", "1.2", 1), ("1.2", "1.2.2", -1), ("0.4.0", "0.4", 0), ("1.13++", "5.5.kw", BadDataError), ) def cmp(x, y): return (x > y) - (x < y) for v1, v2, wanted in versions: try: res = cmp(MozillaVersion(v1), MozillaVersion(v2)) except BadDataError: if wanted is BadDataError: continue else: raise AssertionError(("cmp(%s, %s) " "shouldn't raise BadDataError") % (v1, v2)) self.assertEqual(res, wanted, "cmp(%s, %s) should be %s, got %s" % (v1, v2, wanted, res))
def test_prerelease(self): version = MozillaVersion('1.2.3a1') self.assertEqual(version.version, (1, 2, 3)) self.assertEqual(version.prerelease, ('a', 1)) self.assertEqual(str(version), '1.2.3a1') version = MozillaVersion('1.2.0') self.assertEqual(str(version), '1.2')
def test_prerelease(self): version = MozillaVersion("1.2.3a1") self.assertEqual(version.version, (1, 2, 3)) self.assertEqual(version.prerelease, ("a", 1)) self.assertEqual(str(version), "1.2.3a1") version = MozillaVersion("1.2.0") self.assertEqual(str(version), "1.2")
def version_compare(value, compstr): """Do a version comparison between a string (representing a version), with another which may carry a comparison operator. A true version comparison is done. eg version_compare('1.1', '>1.0') is True """ opfunc, operand = get_op(compstr) value = MozillaVersion(value) operand = MozillaVersion(operand) return opfunc(value, operand)
def version_validator(field_value): logger.debug('starting in version_validator: version data is %s' % field_value) if not isinstance(field_value, str_types): return True # empty input is fine if field_value is None or field_value == '': return True rules_version_list = field_value.split(",") is_list_of_versions = len(rules_version_list) > 1 for rule_version in rules_version_list: try: op, operand = get_op(rule_version) if is_list_of_versions and op != operator.eq: raise JsonSchemaValidationError('Invalid input for %s .Relational Operators are not allowed' ' when providing a list of versions.' % field_value) version = MozillaVersion(operand) except JsonSchemaValidationError: raise except ValueError: raise JsonSchemaValidationError("ValueError. Couldn't parse version for %s. Invalid '%s' input value" % (field_value, field_value)) except: raise JsonSchemaValidationError('Invalid input for %s . No Operator or Match found.' % field_value) # MozillaVersion doesn't error on empty strings if not hasattr(version, 'version'): raise JsonSchemaValidationError("Couldn't parse the version for %s. No attribute 'version' was detected." % field_value) return True
def _validator(form, field): log.debug('starting in version_validator: field.data is %s' % field.data) # empty input if field.data is None: return rulesVersionList = field.data.split(",") isListOfVersions = len(rulesVersionList) > 1 for rule_version in rulesVersionList: try: op, operand = get_op(rule_version) if isListOfVersions and op != operator.eq: raise ValidationError( 'Invalid input for %s .Relational Operators are not allowed' ' when providing a list of versions.' % field.name) version = MozillaVersion(operand) except ValidationError: raise except ValueError: raise ValidationError( "ValueError. Couldn't parse version for %s. Invalid '%s' input value" % (field.name, field.name)) except: raise ValidationError( 'Invalid input for %s . No Operator or Match found.' % field.name) # MozillaVersion doesn't error on empty strings if not hasattr(version, 'version'): raise ValidationError( "Couldn't parse the version for %s. No attribute 'version' was detected." % field.name)
def getHeaderXML(self, updateQuery, update_type): """ In order to update some older versions of Firefox without prompting them for add-on compatibility, we need to be able to modify the appVersion and extVersion attributes. bug 998721 and bug 1174605 have additional background on this. It would be nicer to do this in _getUpdateLineXML to avoid overriding this method, but that doesn't have access to the updateQuery to lookup the version making the request. """ xml = super(ReleaseBlobV1, self).getHeaderXML(updateQuery, update_type) if self.get("oldVersionSpecialCases"): query_ver = MozillaVersion(updateQuery["version"]) real_appv = self.getAppv(updateQuery["buildTarget"], updateQuery["locale"]) real_extv = self.getExtv(updateQuery["buildTarget"], updateQuery["locale"]) if query_ver >= MozillaVersion( "2.0") and query_ver < MozillaVersion("3.5"): # 2.0 and 3.0 need a fake version, and extVersion omitted xml = xml.replace('version="%s"' % real_appv, 'version="%s"' % updateQuery["version"]) xml = xml.replace('extensionVersion="%s" ' % real_extv, '') elif query_ver >= MozillaVersion( "3.5") and query_ver < MozillaVersion("3.6"): # 3.5 needs extVersion omitted xml = xml.replace('extensionVersion="%s" ' % real_extv, '') elif query_ver >= MozillaVersion( "3.6") and query_ver < MozillaVersion("4.0"): # 3.6 needs a fake extensionVersion xml = xml.replace( 'extensionVersion="%s"' % real_extv, 'extensionVersion="%s"' % updateQuery["version"]) # and we don't use ReleaseBlobV1 to serve anything to 4.0 or later return xml
def _validator(form, field): log.debug('starting in version_validator: field.data is %s' % field.data) # empty input if field.data is None: return try: op, operand = get_op(field.data) version = MozillaVersion(operand) except ValueError: raise ValidationError("ValueError. Couldn't parse version for %s. Invalid '%s' input value" % (field.name, field.name)) except: raise ValidationError('Invalid input for %s . No Operator or Match found.' % field.name) # MozillaVersion doesn't error on empty strings if not hasattr(version, 'version'): raise ValidationError("Couldn't parse the version for %s. No attribute 'version' was detected." % field.name)
def test_special_version(self): version = MozillaVersion('3.6.3plugin1') self.assertEqual(version.version, (3, 6, 3)) self.assertEqual(version.prerelease, ('p', 1)) self.assertEqual(str(version), '3.6.3p1')
def test_long_version(self): version = MozillaVersion('1.5.0.12') self.assertEqual(version.version, (1, 5, 12)) self.assertEqual(version.prerelease, None) self.assertEqual(str(version), '1.5.12')
def test_special_version(self): version = MozillaVersion("3.6.3plugin1") self.assertEqual(version.version, (3, 6, 3)) self.assertEqual(version.prerelease, ("p", 1)) self.assertEqual(str(version), "3.6.3p1")