Пример #1
0
def test_traverse_doc_handles_lists_2():
    path = 'sourceResource.language.name'
    doc = {
        'sourceResource': {
            'language': [{
                'name': 'English'
            }, {
                'name': 'Spanish'
            }]
        }
    }
    result = v2_handlers.traverse_doc(path, doc)
    assert result == ['English', 'Spanish']
Пример #2
0
def test_traverse_doc_handles_object():
    path = 'a'
    doc = {'a': {'b': 'c'}}
    result = v2_handlers.traverse_doc(path, doc)
    assert result == {'b': 'c'}
Пример #3
0
def test_traverse_doc_handles_empty_list():
    path = 'a'
    doc = {'a': []}
    result = v2_handlers.traverse_doc(path, doc)
    assert result is None
Пример #4
0
def test_traverse_doc_handles_nonexistent_field_2():
    path = 'a.b'
    doc = {'a': 'x'}
    result = v2_handlers.traverse_doc(path, doc)
    assert result is None
Пример #5
0
def test_traverse_doc_handles_nonexistent_field_1():
    path = 'a.b.c.d'
    doc = {'a': {'b': [{'foo': 'x'}]}}
    result = v2_handlers.traverse_doc(path, doc)
    assert result is None
Пример #6
0
def test_traverse_doc_handles_nested_arrays_and_objects():
    path = 'a.b.c.d'
    doc = {'a': {'b': [{'c': [{'d': 'the value'}]}]}}
    result = v2_handlers.traverse_doc(path, doc)
    assert result == 'the value'
Пример #7
0
def test_traverse_doc_handles_strings():
    path = 'sourceResource.language.name'
    doc = {'sourceResource': {'language': {'name': 'English'}}}
    result = v2_handlers.traverse_doc(path, doc)
    assert result == 'English'