Ejemplo n.º 1
0
def dependency(version, dependency_version):
    d = Dependency(component_version_id=version.id,
                   dependency_version_id=dependency_version.id)
    session.add(d)
    session.commit()
    yield d
    if Dependency.query.get(d.id):
        session.delete(d)
        session.commit()
Ejemplo n.º 2
0
def dependency_version(dependency_component):
    """A second randomly generated version of a secondly randomly generated component"""
    v = _make_version(dependency_component)
    session.add(v)
    session.commit()
    yield v
    if Version.query.get(v.id):
        session.delete(v)
        session.commit()
Ejemplo n.º 3
0
def version(component):
    """A randomly generated version of a randomly generated component"""
    v = _make_version(component)
    session.add(v)
    session.commit()
    yield v
    if Version.query.get(v.id):
        session.delete(v)
        session.commit()
Ejemplo n.º 4
0
def dependency_component(app):
    """A second randomly generated component"""
    c = _make_component()
    session.add(c)
    session.commit()
    yield c
    if Component.query.get(c.id):
        session.delete(c)
        session.commit()
Ejemplo n.º 5
0
def delete_dependency(dependency_id):
    """Delete a single dependency

    Delete a dependency

    :param dependency_id:
    :type dependency_id: str

    :rtype: None
    """
    dependency = Dependency.query.get(dependency_id)
    if dependency:
        session.delete(dependency)
        session.commit()
        return "Deleted", 200
    else:
        return "Dependency not found", 404
Ejemplo n.º 6
0
def delete_component(component_id):
    """Delete a single component

    Delete a component

    :param component_id:
    :type component_id: str

    :rtype: None
    """
    component = Component.query.get(component_id)
    if component:
        session.delete(component)
        session.commit()
        return "Deleted", 200
    else:
        return "Component not found", 404
Ejemplo n.º 7
0
def delete_version(version_id):
    """Delete a single version

    Delete a version

    :param version_id:
    :type version_id: str

    :rtype: None
    """
    version = Version.query.get(version_id)
    if version:
        session.delete(version)
        session.commit()
        return "Deleted", 200
    else:
        return "Version not found", 404
Ejemplo n.º 8
0
def update_dependency(dependency_id, dependency=None):
    """Update a single dependency

    Update a particular dependency

    :param dependency_id:
    :type dependency_id: str
    :param dependency:
    :type dependency: dict | bytes

    :rtype: Dependency
    """
    if not connexion.request.is_json:
        return "Bad request, JSON required", 400
    dependency = Dependency.query.get(dependency_id)
    if not dependency:
        return "Dependency not found", 404
    dependency.update(connexion.request.get_json())
    session.add(dependency)
    session.commit()
    return dependency.to_dict()
Ejemplo n.º 9
0
def update_component(component_id, component=None):
    """Update a single component

    Update a particular component

    :param component_id:
    :type component_id: str
    :param component:
    :type component: dict | bytes

    :rtype: Component
    """
    if not connexion.request.is_json:
        return "Bad request, JSON required", 400
    component = Component.query.get(component_id)
    if not component:
        return "Component not found", 404
    component.update(connexion.request.get_json())
    session.add(component)
    session.commit()
    return component.to_dict()
Ejemplo n.º 10
0
def update_version(version_id, version=None):
    """Update a single version

    Update a particular version

    :param version_id:
    :type version_id: str
    :param version:
    :type version: dict | bytes

    :rtype: Version
    """
    if not connexion.request.is_json:
        return "Bad request, JSON required", 400
    version = Version.query.get(version_id)
    if not version:
        return "Version not found", 404
    version.update(connexion.request.get_json())
    session.add(version)
    session.commit()
    return version.to_dict()
Ejemplo n.º 11
0
def add_version(version=None):
    """Create a new version

    Create a new version

    :param version:
    :type version: dict | bytes

    :rtype: Version
    """
    if not connexion.request.is_json:
        return "Bad request, JSON required", 400
    version_dict = connexion.request.get_json()
    if "component" in version_dict:
        component_name = version_dict.pop("component")
        component = Component.query.filter(
            Component.name == component_name).first()
        if not component:
            return f"Component {component_name} not found", 404
        version_dict["component_id"] = component.id
    version = Version(**version_dict)
    session.add(version)
    session.commit()
    return version.to_dict(), 201
Ejemplo n.º 12
0
def add_grid(grid=None):
    """add_grid

    Create a new dependency grid.

    :param grid:
    :type grid: dict | bytes

    :rtype: Grid
    """
    if not connexion.request.is_json:
        return "Bad request, JSON required", 400
    grid = connexion.request.get_json()
    component = Component.query.filter(
        Component.name == grid["component"]).first()
    if not component:
        return f"Component {grid['component']} not found", 404
    version = (Version.query.filter(Version.component == component).filter(
        Version.version == grid["version"]).first())
    if not version:
        version = Version(version=grid["version"], component=component)
        session.add(version)
        session.commit()
    for dependency in grid["dependencies"]:
        dep_component = Component.query.filter(
            Component.name == dependency["component"]).first()
        if not dep_component:
            return "Dependency component {dependency['component']} not found", 404
        dep_version = (Version.query.filter(
            Version.component == dep_component).filter(
                Version.version == dependency["version"]).first())
        if not dep_version:
            dep_version = Version(component=dep_component,
                                  version=dependency["version"])
            session.add(dep_version)
            session.commit()
        dep = Dependency(component_version_id=version.id,
                         dependency_version_id=dep_version.id)
        session.add(dep)
        session.commit()
    return grid, 201