Пример #1
0
def test_delete_group(database, tmpdir):
    """Test creating and deleting workflow groups."""
    # -- Setup ----------------------------------------------------------------
    #
    # Create a database with two groups for a single workflow.
    fs = FileSystemStorage(basedir=tmpdir)
    with database.session() as session:
        user_id = model.create_user(session, active=True)
        wf_id = model.create_workflow(session)
        manager = WorkflowGroupManager(session=session, fs=fs)
        group_1 = manager.create_group(workflow_id=wf_id,
                                       name='A',
                                       user_id=user_id,
                                       parameters=ParameterIndex(),
                                       workflow_spec=dict()).group_id
        group_2 = manager.create_group(workflow_id=wf_id,
                                       name='B',
                                       user_id=user_id,
                                       parameters=ParameterIndex(),
                                       workflow_spec=dict()).group_id
    # -- Delete group ---------------------------------------------------------
    with database.session() as session:
        # Ensure that group directores are deleted.
        manager = WorkflowGroupManager(session=session, fs=fs)
        manager.delete_group(group_1)
        # Access to group 1 raises error while group 2 is still accessible.
        with pytest.raises(err.UnknownWorkflowGroupError):
            manager.get_group(group_1)
        assert manager.get_group(group_2) is not None
Пример #2
0
def test_create_group(database, tmpdir):
    """Test creating and retrieving new workflow groups."""
    # -- Setup ----------------------------------------------------------------
    #
    # Create a database with a single workflow.
    fs = FileSystemStorage(basedir=tmpdir)
    with database.session() as session:
        user_id = model.create_user(session, active=True)
        workflow_id = model.create_workflow(session)
    # -- Test create group ----------------------------------------------------
    with database.session() as session:
        manager = WorkflowGroupManager(session=session, fs=fs)
        group = manager.create_group(workflow_id=workflow_id,
                                     name='Group 1',
                                     user_id=user_id,
                                     parameters=ParameterIndex(),
                                     workflow_spec=dict())
        assert group.name == 'Group 1'
        assert group.owner_id == user_id
        assert group.engine_config is None
        assert len(group.members) == 1
        assert isinstance(group.parameters, dict)
        assert len(group.parameters) == 0
        assert isinstance(group.workflow_spec, dict)
        assert len(group.workflow_spec) == 0
        # Retrieve the group from the database
        group = manager.get_group(group.group_id)
        assert group.name == 'Group 1'
        assert group.owner_id == user_id
        assert len(group.members) == 1
        assert isinstance(group.parameters, dict)
        assert len(group.parameters) == 0
        assert isinstance(group.workflow_spec, dict)
        assert len(group.workflow_spec) == 0
    # -- Test create group with duplicate members and different config --------
    engine_config = {'workers': {'test': {'worker': 'docker'}}}
    with database.session() as session:
        manager = WorkflowGroupManager(session=session, fs=fs)
        group = manager.create_group(workflow_id=workflow_id,
                                     name='Group 2',
                                     user_id=user_id,
                                     parameters=ParameterIndex(),
                                     workflow_spec=dict(),
                                     members=[user_id, user_id, user_id],
                                     engine_config=engine_config)
        assert len(group.members) == 1
        assert group.engine_config == engine_config
        # Retrieve the group from the database
        group = manager.get_group(group.group_id)
        assert len(group.members) == 1
    # -- Test error cases -----------------------------------------------------
    with database.session() as session:
        manager = WorkflowGroupManager(session=session, fs=fs)
        # - Invalid name
        with pytest.raises(err.ConstraintViolationError):
            manager.create_group(workflow_id=workflow_id,
                                 name='A' * 513,
                                 user_id=user_id,
                                 parameters=ParameterIndex(),
                                 workflow_spec=dict())
        # - Duplicate name
        with pytest.raises(err.ConstraintViolationError):
            manager.create_group(workflow_id=workflow_id,
                                 name='Group 1',
                                 user_id=user_id,
                                 parameters=ParameterIndex(),
                                 workflow_spec=dict())
        # - Unknown user
        with pytest.raises(err.UnknownUserError):
            manager.create_group(workflow_id=workflow_id,
                                 name='D',
                                 user_id=user_id,
                                 parameters=ParameterIndex(),
                                 workflow_spec=dict(),
                                 members=[user_id, 'not a user'])
        # - Missing user
        with pytest.raises(err.UnknownUserError):
            manager.create_group(workflow_id=workflow_id,
                                 name='D',
                                 user_id=None,
                                 parameters=ParameterIndex(),
                                 workflow_spec=dict(),
                                 members=[user_id, 'not a user'])