コード例 #1
0
def test_hidden_input(client, mocker, config, mongo):
    mocker.patch('pika.adapters.blocking_connection.'
                 'BlockingChannel.basic_publish')

    juan = make_user('juan', 'Juan')

    res = client.post('/v1/execution',
                      headers={
                          **{
                              'Content-Type': 'application/json',
                          },
                          **make_auth(juan)
                      },
                      data=json.dumps({
                          'process_name':
                          'input-hidden',
                          'form_array': [{
                              'ref': 'start_form',
                              'data': {
                                  'data': 'yes',
                              },
                          }],
                      }))

    assert res.status_code == 201

    exc = Execution.get_all()[0]
    ptr = exc.proxy.pointers.get()[0]

    pika.adapters.blocking_connection.BlockingChannel.\
        basic_publish.assert_called_once()

    args = pika.adapters.blocking_connection.\
        BlockingChannel.basic_publish.call_args[1]

    json_message = {
        'command':
        'step',
        'pointer_id':
        ptr.id,
        'user_identifier':
        'juan',
        'input': [
            Form.state_json('start_form', [
                {
                    'label': 'data',
                    'type': 'text',
                    'value': 'yes',
                    'value_caption': 'yes',
                    'name': 'data',
                    'state': 'valid',
                    'hidden': True,
                },
            ])
        ],
    }

    assert json.loads(args['body']) == json_message
コード例 #2
0
def test_interpolated_name(config, client, mongo):
    juan = make_user('juan', 'Juan')
    name = 'Computes a name based on a Cow'

    res = client.post('/v1/execution',
                      headers={
                          **{
                              'Content-Type': 'application/json',
                          },
                          **make_auth(juan)
                      },
                      data=json.dumps({
                          'process_name':
                          'interpol',
                          'form_array': [{
                              'ref': 'form',
                              'data': {
                                  'field': 'Cow',
                              },
                          }],
                      }))

    # request succeeded
    assert res.status_code == 201

    # execution has name
    exc = Execution.get_all()[0]

    assert exc.name == name

    # execution collection has name
    reg2 = next(mongo[config["EXECUTION_COLLECTION"]].find())

    assert reg2['id'] == exc.id
    assert reg2['name'] == name

    # history has the name
    reg = next(mongo[config["POINTER_COLLECTION"]].find())

    assert reg['execution']['name'] == name
コード例 #3
0
def test_ifelifelse_else(config, mongo):
    ''' else will be executed if preceding condition is false'''
    # test setup
    handler = Handler(config)
    user = make_user('juan', 'Juan')
    ptr = make_pointer('else.2018-07-10.xml', 'start_node')
    channel = MagicMock()

    mongo[config["EXECUTION_COLLECTION"]].insert_one({
        '_type':
        'execution',
        'id':
        ptr.proxy.execution.get().id,
        'state':
        Xml.load(config, 'else').get_state(),
    })

    handler.call(
        {
            'command':
            'step',
            'pointer_id':
            ptr.id,
            'user_identifier':
            user.identifier,
            'input': [
                Form.state_json('secret01', [
                    {
                        'name': 'password',
                        'type': 'text',
                        'value': 'cuca',
                        'value_caption': 'cuca',
                    },
                ])
            ],
        }, channel)

    # pointer moved
    assert Pointer.get(ptr.id) is None
    ptr = Pointer.get_all()[0]
    assert ptr.node_id == 'condition01'

    # rabbit called
    channel.basic_publish.assert_called_once()
    args = channel.basic_publish.call_args[1]
    rabbit_call = {
        'command':
        'step',
        'pointer_id':
        ptr.id,
        'input': [
            Form.state_json('condition01', [
                {
                    'name': 'condition',
                    'name': 'condition',
                    'state': 'valid',
                    'type': 'bool',
                    'value': False,
                    'value_caption': 'False',
                },
            ])
        ],
        'user_identifier':
        '__system__',
    }
    assert json.loads(args['body']) == rabbit_call

    channel = MagicMock()
    handler.call(rabbit_call, channel)

    # pointer moved
    assert Pointer.get(ptr.id) is None
    ptr = Pointer.get_all()[0]
    assert ptr.node_id == 'elif01'

    # rabbit called
    channel.basic_publish.assert_called_once()
    args = channel.basic_publish.call_args[1]
    rabbit_call = {
        'command':
        'step',
        'pointer_id':
        ptr.id,
        'input': [
            Form.state_json('elif01', [
                {
                    'name': 'condition',
                    'state': 'valid',
                    'type': 'bool',
                    'value': False,
                    'value_caption': 'False',
                },
            ])
        ],
        'user_identifier':
        '__system__',
    }
    assert json.loads(args['body']) == rabbit_call

    channel = MagicMock()
    handler.call(rabbit_call, channel)

    # pointer moved
    assert Pointer.get(ptr.id) is None
    ptr = Pointer.get_all()[0]
    assert ptr.node_id == 'else01'

    # rabbit called
    channel.basic_publish.assert_called_once()
    args = channel.basic_publish.call_args[1]
    rabbit_call = {
        'command':
        'step',
        'pointer_id':
        ptr.id,
        'input': [
            Form.state_json('else01', [
                {
                    'name': 'condition',
                    'state': 'valid',
                    'type': 'bool',
                    'value': True,
                    'value_caption': 'True',
                },
            ])
        ],
        'user_identifier':
        '__system__',
    }
    assert json.loads(args['body']) == rabbit_call

    channel = MagicMock()
    handler.call(rabbit_call, channel)

    # pointer moved
    assert Pointer.get(ptr.id) is None
    ptr = Pointer.get_all()[0]
    assert ptr.node_id == 'action03'

    # rabbit called to notify the user
    channel.basic_publish.assert_called_once()
    args = channel.basic_publish.call_args[1]
    assert args['exchange'] == 'charpe_notify'

    channel = MagicMock()
    handler.call(
        {
            'command':
            'step',
            'pointer_id':
            ptr.id,
            'user_identifier':
            user.identifier,
            'input': [
                Form.state_json('form01', [
                    {
                        'name': 'answer',
                        'value': 'answer',
                        'value_caption': 'answer',
                    },
                ])
            ],
        }, channel)

    # execution finished
    assert len(Pointer.get_all()) == 0
    assert len(Execution.get_all()) == 0
コード例 #4
0
def test_call_node_render(config, mongo):
    handler = Handler(config)
    user = make_user('juan', 'Juan')
    ptr = make_pointer('call-render.2020-04-24.xml', 'start_node')
    channel = MagicMock()
    execution = ptr.proxy.execution.get()
    value = random_string()

    mongo[config["EXECUTION_COLLECTION"]].insert_one({
        '_type':
        'execution',
        'id':
        execution.id,
        'state':
        Xml.load(config, execution.process_name).get_state(),
    })

    # teardown of first node and wakeup of call node
    handler.call(
        {
            'command':
            'step',
            'pointer_id':
            ptr.id,
            'user_identifier':
            user.identifier,
            'input': [
                Form.state_json('start_form', [
                    {
                        'name': 'data',
                        'name': 'data',
                        'value': value,
                        'value_caption': value,
                    },
                ])
            ],
        }, channel)
    assert Pointer.get(ptr.id) is None
    ptr = execution.proxy.pointers.get()[0]
    assert ptr.node_id == 'call'

    new_ptr = next(Pointer.q().filter(node_id='start_node'))

    # aditional rabbit call for new process
    args = channel.basic_publish.call_args_list[0][1]

    assert args['exchange'] == ''
    assert args['routing_key'] == config['RABBIT_QUEUE']
    assert json.loads(args['body']) == {
        'command':
        'step',
        'pointer_id':
        new_ptr.id,
        'user_identifier':
        '__system__',
        'input': [
            Form.state_json('start_form', [
                {
                    'label': 'Info',
                    'name': 'data',
                    'state': 'valid',
                    'type': 'text',
                    'value': value,
                    'value_caption': value,
                    'hidden': False,
                },
            ])
        ],
    }

    # normal rabbit call
    args = channel.basic_publish.call_args_list[1][1]

    assert args['exchange'] == ''
    assert args['routing_key'] == config['RABBIT_QUEUE']
    assert json.loads(args['body']) == {
        'command': 'step',
        'pointer_id': ptr.id,
        'user_identifier': '__system__',
        'input': [],
    }

    # mongo log registry created for new process
    reg = next(mongo[config["POINTER_COLLECTION"]].find({
        'id': new_ptr.id,
    }))
    assert reg['node']['id'] == 'start_node'

    # mongo execution registry created for new process
    reg = next(mongo[config["EXECUTION_COLLECTION"]].find({
        'id':
        new_ptr.proxy.execution.get().id,
    }))
    assert reg['name'] == 'Simplest process ever started with: ' + value

    # teardown of the call node and end of first execution
    handler.call(
        {
            'command': 'step',
            'pointer_id': ptr.id,
            'user_identifier': '__system__',
            'input': [],
        }, channel)

    # old execution is gone, new is here
    assert Execution.get(execution.id) is None
    assert Pointer.get(ptr.id) is None
    execution = Execution.get_all()[0]
    assert execution.process_name == 'simple.2018-02-19.xml'