Exemplo n.º 1
0
def test_arg_to_dict():

    from dictalchemy.utils import arg_to_dict

    assert arg_to_dict(None) == {}
    assert arg_to_dict([]) == {}
    assert arg_to_dict(['a', 'b']) == {'a': {}, 'b': {}}
    assert arg_to_dict({
        'a': {'is_a': True},
        'b': {'is_b': True},
    }) == {'a': {'is_a': True}, 'b': {'is_b': True}}
def test_arg_to_dict():

    from dictalchemy.utils import arg_to_dict

    assert arg_to_dict(None) == {}
    assert arg_to_dict([]) == {}
    assert arg_to_dict(['a', 'b']) == {'a': {}, 'b': {}}
    assert arg_to_dict({
        'a': {
            'is_a': True
        },
        'b': {
            'is_b': True
        },
    }) == {
        'a': {
            'is_a': True
        },
        'b': {
            'is_b': True
        }
    }
Exemplo n.º 3
0
    def ashal(self, **kwargs):
        kwargs['method'] = 'ashal'
        result = self.asdict(**kwargs)

        follow = arg_to_dict(kwargs.get('follow', None))
        _embedded = {}
        for (k, args) in follow.iteritems():
            if args.get('_embedded', None) and k in result:
                _embedded[k] = result.pop(k)

        result['_embedded'] = _embedded
        result['_links'] = self.get_hal_links()

        return result
Exemplo n.º 4
0
    def ashal(self, **kwargs):
        kwargs['method'] = 'ashal'
        result = self.asdict(**kwargs)

        follow = arg_to_dict(kwargs.get('follow', None))
        _embedded = {}
        for (k, args) in follow.iteritems():
            if args.get('_embedded', None) and k in result:
                _embedded[k] = result.pop(k)

        result['_embedded'] = _embedded
        result['_links'] = self.get_hal_links()

        return result