Example #1
0
def test_resolve_attribute_not_found():
    data = {
        'first': {
            'second': {
                'third': {
                    'a': 'b'
                },
            },
        },
    }

    assert resolve_attribute('a.b.c', data) is None
Example #2
0
def test_resolve_attribute():
    data = {
        'first': {
            'second': {
                'third': {
                    'a': 'b'
                },
            },
        },
    }

    assert resolve_attribute('first.second.third', data) == {'a': 'b'}
Example #3
0
    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
Example #4
0
 def _get_values(self, item):
     return {
         field: resolve_attribute(field, item)
         for field in self._fields
     }