Esempio n. 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']
Esempio n. 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'}
Esempio n. 3
0
def test_traverse_doc_handles_empty_list():
    path = 'a'
    doc = {'a': []}
    result = v2_handlers.traverse_doc(path, doc)
    assert result is None
Esempio n. 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
Esempio n. 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
Esempio n. 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'
Esempio n. 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'