Exemplo n.º 1
0
def test_resolve_attribute_not_found():
    data = {
        'first': {
            'second': {
                'third': {
                    'a': 'b'
                },
            },
        },
    }

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

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