Пример #1
0
def test_api_action(read_json, registry):
    transport = Payload(read_json('transport.json'))
    params = [
        {
            PARAM['name']: 'foo',
            PARAM['value']: 1,
            PARAM['type']: TYPE_INTEGER
        },
        {
            PARAM['name']: 'bar',
            PARAM['value']: 2,
            PARAM['type']: TYPE_INTEGER
        },
    ]
    action = Action(
        **{
            'action': 'test',
            'params': params,
            'transport': transport,
            'component': None,
            'path': '/path/to/file.py',
            'name': 'dummy',
            'version': '1.0',
            'framework_version': '1.0.0',
        })

    assert action.get_action_name() == 'test'

    # Check request origin
    assert not action.is_origin()
    transport.set('meta/origin', ['dummy', '1.0', 'test'])
    assert action.is_origin()

    # Check setting of transport properties
    assert action.set_property('name', 'value') == action
    properties = transport.get('meta/properties', default=None)
    assert isinstance(properties, dict)
    assert properties.get('name') == 'value'

    # Property values must be strings
    with pytest.raises(TypeError):
        action.set_property('other', 1)
Пример #2
0
def test_api_action_download(read_json, registry):
    service_name = 'dummy'
    service_version = '1.0'
    transport = Payload(read_json('transport.json'))
    action = Action(
        **{
            'action': 'test',
            'params': [],
            'transport': transport,
            'component': None,
            'path': '/path/to/file.py',
            'name': service_name,
            'version': service_version,
            'framework_version': '1.0.0',
        })

    # Download accepts only a File instance
    with pytest.raises(TypeError):
        action.set_download('')

    # Create a new file and set is as download
    file = action.new_file('foo', path='/tmp/file.ext')
    transport.set('body', '')
    assert transport.get('body') == ''
    action.set_download(file)
    assert transport.get('body') == file_to_payload(file)

    # Clear download
    transport.set('body', '')
    assert transport.get('body') == ''

    # Check that registry does not have mappings
    assert not registry.has_mappings
    # Set file server mappings to False and try to set a download
    registry.update_registry(
        {service_name: {
            service_version: {
                'files': False
            }
        }})
    with pytest.raises(NoFileServerError):
        action.set_download(file)