예제 #1
0
파일: test_v2.py 프로젝트: dpla/dplaapi
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
파일: test_v2.py 프로젝트: dpla/dplaapi
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
파일: test_v2.py 프로젝트: dpla/dplaapi
def test_traverse_doc_handles_empty_list():
    path = 'a'
    doc = {'a': []}
    result = v2_handlers.traverse_doc(path, doc)
    assert result is None
예제 #4
0
파일: test_v2.py 프로젝트: dpla/dplaapi
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
파일: test_v2.py 프로젝트: dpla/dplaapi
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
파일: test_v2.py 프로젝트: dpla/dplaapi
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
파일: test_v2.py 프로젝트: dpla/dplaapi
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'