Exemplo n.º 1
0
def update(
    *,
    db_session,
    service_plugin: ServicePlugin,
    service_plugin_in: ServicePluginUpdate,
) -> ServicePlugin:
    """
    Updates a service_plugin.
    """

    if service_plugin_in.service:
        service = service_service.get(db_session=db_session,
                                      service_id=service_plugin_in.service.id)
        service_plugin.service = service

    if service_plugin_in.plugin:
        plugin = plugin_service.get(db_session=db_session,
                                    plugin_id=service_plugin_in.plugin.id)
        service_plugin.plugin = plugin

    service_plugin_data = jsonable_encoder(service_plugin)

    update_data = service_plugin_in.dict(skip_defaults=True,
                                         exclude={"service", "plugin"})

    for field in service_plugin_data:
        if field in update_data:
            setattr(service_plugin, field, update_data[field])

    db_session.add(service_plugin)
    db_session.commit()
    return service_plugin
Exemplo n.º 2
0
def create(*, db_session, workflow_in: WorkflowCreate) -> Workflow:
    """Creates a new workflow."""
    workflow = Workflow(**workflow_in.dict(exclude={"plugin"}), )
    plugin = plugin_service.get(db_session=db_session,
                                plugin_id=workflow_in.plugin.id)
    workflow.plugin = plugin

    db_session.add(workflow)
    db_session.commit()
    return workflow
Exemplo n.º 3
0
def create(*, db_session, workflow_in: WorkflowCreate) -> Workflow:
    """Creates a new workflow."""
    plugin = plugin_service.get(db_session=db_session, plugin_id=workflow_in.plugin.id)
    project = project_service.get_by_name(db_session=db_session, name=workflow_in.project.name)
    workflow = Workflow(
        **workflow_in.dict(exclude={"plugin", "project"}),
        plugin=plugin,
        project=project,
    )

    db_session.add(workflow)
    db_session.commit()
    return workflow
Exemplo n.º 4
0
def update(*, db_session, workflow: Workflow, workflow_in: WorkflowUpdate) -> Workflow:
    """Updates a workflow."""
    workflow_data = jsonable_encoder(workflow)
    update_data = workflow_in.dict(skip_defaults=True, exclude={"plugin"})

    for field in workflow_data:
        if field in update_data:
            setattr(workflow, field, update_data[field])

    plugin = plugin_service.get(db_session=db_session, plugin_id=workflow_in.plugin.id)
    workflow.plugin = plugin

    db_session.add(workflow)
    db_session.commit()

    return workflow
Exemplo n.º 5
0
def get_or_create(
    *, db_session, service_id: int, plugin_id: int, service_plugin_type: str,
) -> ServicePlugin:
    """Gets an existing service_plugin object or creates a new one."""
    service_plugin = (
        db_session.query(ServicePlugin)
        .filter(ServicePlugin.service_id == service_id)
        .filter(ServicePlugin.plugin_contact_id == plugin_id)
        .one_or_none()
    )

    if not service_plugin:
        # We get information about the plugin
        plugin = plugin_service.get(db_session=db_session, plugin_id=plugin_id)

        service_plugin_in = ServicePluginCreate(
            service_plugin_type=service_plugin_type, plugin=plugin
        )
        service_plugin = create(db_session=db_session, service_plugin_in=service_plugin_in)

    return service_plugin
Exemplo n.º 6
0
def test_get(session, plugin):
    from dispatch.plugin.service import get

    t_plugin = get(db_session=session, plugin_id=plugin.id)
    assert t_plugin.id == plugin.id