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()
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()
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()
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()
def add_dependency(dependency=None): """Create a new dependency Create a new dependency :param dependency: :type dependency: dict | bytes :rtype: Dependency """ if not connexion.request.is_json: return "Bad request, JSON required", 400 dependency = Dependency(**connexion.request.get_json()) session.add(dependency) return dependency.to_dict(), 201
def add_component(component=None): """Create a new component Create a new component :param component: :type component: dict | bytes :rtype: Component """ if not connexion.request.is_json: return "Bad request, JSON required", 400 component = Component(**connexion.request.get_json()) session.add(component) return component.to_dict(), 201
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()
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()
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()
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
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