Esempio n. 1
0
def test_merge_simple_dicts_with_precedence():
    a = {'a': 'value', 'ab': 'overwritten'}
    b = {'b': 'other value', 'ab': 'keep'}
    assert utils.merge(a, b) == {
        'a': 'value',
        'b': 'other value',
        'ab': 'keep'
    }
Esempio n. 2
0
def parameters_for(apidoc):

    params = []

    route = apidoc.get('route')

    if route is None:
        raise ValueError(
            'route value cannot be empty. Every function must be decorated with @doc.route("/route/path")'
        )

    expected_paramaters = expected_params(apidoc)
    doc_params = apidoc.get('params', {})
    path_params = extract_path_params(route)

    all_params = merge(merge(expected_paramaters, doc_params), path_params)

    for name, param in all_params.items():
        param = create_parameter(name, param)
        params.append(param)

    return params if len(params) > 0 else None
Esempio n. 3
0
def test_merge_recursions_with_empty():
    a = {}
    b = {
        'b': 'other value',
        'ab': 'keep',
        'nested_b': {
            'b': 'nested'
        },
        'nested_a_b': {
            'b': 'b only',
            'ab': 'keep'
        }
    }
    assert utils.merge(a, b) == b
Esempio n. 4
0
def test_merge_recursions():
    a = {
        'a': 'value',
        'ab': 'overwritten',
        'nested_a': {
            'a': 'nested'
        },
        'nested_a_b': {
            'a': 'a only',
            'ab': 'overwritten'
        }
    }
    b = {
        'b': 'other value',
        'ab': 'keep',
        'nested_b': {
            'b': 'nested'
        },
        'nested_a_b': {
            'b': 'b only',
            'ab': 'keep'
        }
    }
    assert utils.merge(a, b) == {
        'a': 'value',
        'b': 'other value',
        'ab': 'keep',
        'nested_a': {
            'a': 'nested'
        },
        'nested_b': {
            'b': 'nested'
        },
        'nested_a_b': {
            'a': 'a only',
            'b': 'b only',
            'ab': 'keep'
        }
    }
Esempio n. 5
0
def test_merge_simple_dicts_without_precedence():
    a = {'a': 'value'}
    b = {'b': 'other value'}
    assert utils.merge(a, b) == {'a': 'value', 'b': 'other value'}
Esempio n. 6
0
 def wrapper(documented):
     current_doc = getattr(documented, '__apidoc__', {})
     if 'name' not in current_doc:
         kwargs['name'] = documented.__name__
     documented.__apidoc__ = merge(current_doc, kwargs)
     return documented