def test_resolve_attribute_not_found(): data = { 'first': { 'second': { 'third': { 'a': 'b' }, }, }, } assert resolve_attribute('a.b.c', data) is None
def test_resolve_attribute(): data = { 'first': { 'second': { 'third': { 'a': 'b' }, }, }, } assert resolve_attribute('first.second.third', data) == {'a': 'b'}
def values(self, *fields): """ Returns a flat dictionary containing only the fields passed as arguments. Nested field can be specified using dot notation. Ex. .. code-block:: python values = resource.values('field', 'nested.field') :return: A dictionary containing field,value pairs. :rtype: dict """ results = {} item = self.get() for field in fields: results[field] = resolve_attribute(field, item) return results
def _get_values(self, item): return { field: resolve_attribute(field, item) for field in self._fields }