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