Exemplo n.º 1
0
 def test_label_comparison_as_string(self):
     versions = [
         semver_db.parse("1.1.1-0.10.a.23.y.255").__composite_values__()[1],
         semver_db.parse("1.1.1-0.10.z.23.x.255").__composite_values__()[1],
         semver_db.parse("1.1.1-0.10.z.23.y.255").__composite_values__()[1],
         semver_db.parse("1.1.1-0.10.z.23.y.256").__composite_values__()[1],
         semver_db.parse("1.1.1-0.10.z.24.y.255").__composite_values__()[1],
         semver_db.parse("1.1.1-0.11.z.24.y.255").__composite_values__()[1],
         semver_db.parse("1.1.1-1.11.z.24.y.255").__composite_values__()[1],
         semver_db.parse("1.1.1-alp.1.2.3.4.5.6").__composite_values__()[1]]
     for i in range(len(versions) - 1):
         self.assertLess(versions[i], versions[i + 1])
Exemplo n.º 2
0
 def test_label_comparison_as_string(self):
     versions = [
         semver_db.parse("1.1.1-0.10.a.23.y.255").__composite_values__()[1],
         semver_db.parse("1.1.1-0.10.z.23.x.255").__composite_values__()[1],
         semver_db.parse("1.1.1-0.10.z.23.y.255").__composite_values__()[1],
         semver_db.parse("1.1.1-0.10.z.23.y.256").__composite_values__()[1],
         semver_db.parse("1.1.1-0.10.z.24.y.255").__composite_values__()[1],
         semver_db.parse("1.1.1-0.11.z.24.y.255").__composite_values__()[1],
         semver_db.parse("1.1.1-1.11.z.24.y.255").__composite_values__()[1],
         semver_db.parse("1.1.1-alp.1.2.3.4.5.6").__composite_values__()[1]
     ]
     for i in xrange(len(versions) - 1):
         self.assertLess(versions[i], versions[i + 1])
Exemplo n.º 3
0
def _set_version_fields(values):
    if 'type_version' in values:
        values['type_version'] = semver_db.parse(values['type_version'])
    if 'version' in values:
        values['version'] = semver_db.parse(values['version'])
Exemplo n.º 4
0
def _do_query_filters(filters):
    basic_conds = []
    tag_conds = []
    prop_conds = []

    # don't show deleted artifacts
    basic_conds.append([models.Artifact.state != 'deleted'])

    visibility = filters.pop('visibility', None)
    if visibility is not None:
        # ignore operator. always consider it EQ
        basic_conds.append(
            [models.Artifact.visibility == visibility[0]['value']])

    type_name = filters.pop('type_name', None)
    if type_name is not None:
        # ignore operator. always consider it EQ
        basic_conds.append([models.Artifact.type_name == type_name['value']])
        type_version = filters.pop('type_version', None)
        if type_version is not None:
            # ignore operator. always consider it EQ
            # TODO(mfedosin) add support of LIKE operator
            type_version = semver_db.parse(type_version['value'])
            basic_conds.append([models.Artifact.type_version == type_version])

    name = filters.pop('name', None)
    if name is not None:
        # ignore operator. always consider it EQ
        basic_conds.append([models.Artifact.name == name[0]['value']])

    versions = filters.pop('version', None)
    if versions is not None:
        for version in versions:
            value = semver_db.parse(version['value'])
            op = version['operator']
            fn = op_mappings[op]
            basic_conds.append([fn(models.Artifact.version, value)])

    state = filters.pop('state', None)
    if state is not None:
        # ignore operator. always consider it EQ
        basic_conds.append([models.Artifact.state == state['value']])

    owner = filters.pop('owner', None)
    if owner is not None:
        # ignore operator. always consider it EQ
        basic_conds.append([models.Artifact.owner == owner[0]['value']])

    id_list = filters.pop('id_list', None)
    if id_list is not None:
        basic_conds.append([models.Artifact.id.in_(id_list['value'])])

    name_list = filters.pop('name_list', None)
    if name_list is not None:
        basic_conds.append([models.Artifact.name.in_(name_list['value'])])

    tags = filters.pop('tags', None)
    if tags is not None:
        for tag in tags:
            tag_conds.append([models.ArtifactTag.value == tag['value']])

    # process remaining filters
    for filtername, filtervalues in filters.items():
        for filtervalue in filtervalues:

            db_prop_op = filtervalue['operator']
            db_prop_value = filtervalue['value']
            db_prop_type = filtervalue['type'] + "_value"
            db_prop_position = filtervalue.get('position')

            conds = [models.ArtifactProperty.name == filtername]

            if db_prop_op in op_mappings:
                fn = op_mappings[db_prop_op]
                result = fn(getattr(models.ArtifactProperty, db_prop_type),
                            db_prop_value)

                cond = [result]
                if db_prop_position is not 'any':
                    cond.append(
                        models.ArtifactProperty.position == db_prop_position)
                if db_prop_op == 'IN':
                    if (db_prop_position is not None and
                            db_prop_position is not 'any'):
                        msg = _LE("Cannot use this parameter with "
                                  "the operator IN")
                        LOG.error(msg)
                        raise exception.ArtifactInvalidPropertyParameter(
                            op='IN')
                    cond = [result,
                            models.ArtifactProperty.position >= 0]
            else:
                msg = _LE("Operator %s is not supported") % db_prop_op
                LOG.error(msg)
                raise exception.ArtifactUnsupportedPropertyOperator(
                    op=db_prop_op)

            conds.extend(cond)

            prop_conds.append(conds)
    return basic_conds, tag_conds, prop_conds
Exemplo n.º 5
0
 def test_too_long_numeric_segments(self):
     version = semver_db.parse('1.0.0-alpha.1234567')
     self.assertRaises(exception.InvalidVersion,
                       version.__composite_values__)
Exemplo n.º 6
0
 def test_label_comparison_as_long(self):
     v1 = semver_db.parse("1.1.1-alpha")
     v2 = semver_db.parse("1.1.1")
     self.assertTrue(
         v2.__composite_values__()[0] > v1.__composite_values__()[0])
Exemplo n.º 7
0
 def test_minor_comparison_as_long(self):
     v1 = semver_db.parse("1.1.100")
     v2 = semver_db.parse("2.0.0")
     self.assertTrue(
         v2.__composite_values__()[0] > v1.__composite_values__()[0])
Exemplo n.º 8
0
 def test_long_conversion(self):
     initial = '1.2.3-beta+07.17.2014'
     v = semver_db.parse(initial)
     l, prerelease, build = v.__composite_values__()
     v2 = semver_db.DBVersion(l, prerelease, build)
     self.assertEqual(initial, str(v2))
Exemplo n.º 9
0
 def test_too_long_numeric_segments(self):
     version = semver_db.parse("1.0.0-alpha.1234567")
     self.assertRaises(exception.InvalidVersion, version.__composite_values__)
Exemplo n.º 10
0
 def test_label_comparison_as_long(self):
     v1 = semver_db.parse("1.1.1-alpha")
     v2 = semver_db.parse("1.1.1")
     self.assertTrue(v2.__composite_values__()[0] > v1.__composite_values__()[0])
Exemplo n.º 11
0
 def test_minor_comparison_as_long(self):
     v1 = semver_db.parse("1.1.100")
     v2 = semver_db.parse("2.0.0")
     self.assertTrue(v2.__composite_values__()[0] > v1.__composite_values__()[0])
Exemplo n.º 12
0
 def test_long_conversion(self):
     initial = "1.2.3-beta+07.17.2014"
     v = semver_db.parse(initial)
     l, prerelease, build = v.__composite_values__()
     v2 = semver_db.DBVersion(l, prerelease, build)
     self.assertEqual(initial, str(v2))
Exemplo n.º 13
0
def _set_version_fields(values):
    if "type_version" in values:
        values["type_version"] = semver_db.parse(values["type_version"])
    if "version" in values:
        values["version"] = semver_db.parse(values["version"])
Exemplo n.º 14
0
def _do_query_filters(filters):
    basic_conds = []
    tag_conds = []
    prop_conds = []

    # don't show deleted artifacts
    basic_conds.append([models.Artifact.state != "deleted"])

    visibility = filters.pop("visibility", None)
    if visibility is not None:
        # ignore operator. always consider it EQ
        basic_conds.append([models.Artifact.visibility == visibility["value"]])

    type_name = filters.pop("type_name", None)
    if type_name is not None:
        # ignore operator. always consider it EQ
        basic_conds.append([models.Artifact.type_name == type_name["value"]])
        type_version = filters.pop("type_version", None)
        if type_version is not None:
            # ignore operator. always consider it EQ
            # TODO(mfedosin) add support of LIKE operator
            type_version = semver_db.parse(type_version["value"])
            basic_conds.append([models.Artifact.type_version == type_version])

    name = filters.pop("name", None)
    if name is not None:
        # ignore operator. always consider it EQ
        basic_conds.append([models.Artifact.name == name["value"]])
        version = filters.pop("version", None)
        if version is not None:
            # ignore operator. always consider it EQ
            # TODO(mfedosin) add support of LIKE operator
            version = semver_db.parse(version["value"])
            basic_conds.append([models.Artifact.version == version])

    state = filters.pop("state", None)
    if state is not None:
        # ignore operator. always consider it EQ
        basic_conds.append([models.Artifact.state == state["value"]])

    owner = filters.pop("owner", None)
    if owner is not None:
        # ignore operator. always consider it EQ
        basic_conds.append([models.Artifact.owner == owner["value"]])

    id_list = filters.pop("id_list", None)
    if id_list is not None:
        basic_conds.append([models.Artifact.id.in_(id_list["value"])])

    name_list = filters.pop("name_list", None)
    if name_list is not None:
        basic_conds.append([models.Artifact.name.in_(name_list["value"])])

    tags = filters.pop("tags", None)
    if tags is not None:
        for tag in tags["value"]:
            tag_conds.append([models.ArtifactTag.value == tag])

    # process remaining filters
    for filtername, filtervalue in filters.items():

        db_prop_op = filtervalue["operator"]
        db_prop_value = filtervalue["value"]
        db_prop_type = filtervalue["type"] + "_value"
        db_prop_position = filtervalue.get("position")

        conds = [models.ArtifactProperty.name == filtername]

        if db_prop_op in op_mappings:
            fn = op_mappings[db_prop_op]
            result = fn(getattr(models.ArtifactProperty, db_prop_type), db_prop_value)

            cond = [result, models.ArtifactProperty.position == db_prop_position]
            if db_prop_op == "IN":
                if db_prop_position is not None:
                    msg = _LE("Cannot use this parameter with " "the operator IN")
                    LOG.error(msg)
                    raise exception.ArtifactInvalidPropertyParameter(op="IN")
                cond = [result, models.ArtifactProperty.position >= 0]
        else:
            msg = _LE("Operator %s is not supported") % db_prop_op
            LOG.error(msg)
            raise exception.ArtifactUnsupportedPropertyOperator(op=db_prop_op)

        conds.extend(cond)

        prop_conds.append(conds)
    return basic_conds, tag_conds, prop_conds