def on_deserialize(self, value):
        value = callable_to_dict(value)

        for key in value:
            item = value[key]
            if item is not None and not checkers.is_callable(item):
                raise SQLAthanorError('on_deserialize for %s must be callable' % key)

        self._on_deserialize = value
Beispiel #2
0
def test_AttributeConfiguration__init__(kwargs):
    if kwargs is None:
        result = AttributeConfiguration()
        kwargs = {}
    else:
        result = AttributeConfiguration(**kwargs)

    assert result.name == kwargs.get('name', None)
    assert result.supports_csv == bool_to_tuple(kwargs.get('supports_csv',
                                                           (False, False)))
    assert result.csv_sequence == kwargs.get('csv_sequence', None)
    assert result.supports_json == bool_to_tuple(kwargs.get('supports_json',
                                                            (False, False)))
    assert result.supports_yaml == bool_to_tuple(kwargs.get('supports_yaml',
                                                            (False, False)))
    assert result.supports_dict == bool_to_tuple(kwargs.get('supports_dict',
                                                            (False, False)))

    assert result.on_serialize is not None
    assert isinstance(result.on_serialize, dict)
    input_on_serialize = callable_to_dict(
        kwargs.get('on_serialize', BLANK_ON_SERIALIZE) or BLANK_ON_SERIALIZE
    )
    for key in result.on_serialize:
        assert key in input_on_serialize
        assert result.on_serialize[key] == input_on_serialize[key]

    assert result.on_deserialize is not None
    assert isinstance(result.on_deserialize, dict)

    input_on_deserialize = callable_to_dict(
        kwargs.get('on_deserialize', BLANK_ON_SERIALIZE) or BLANK_ON_SERIALIZE
    )

    for key in result.on_deserialize:
        assert key in input_on_deserialize
        assert result.on_deserialize[key] == input_on_deserialize[key]
Beispiel #3
0
def test_callable_to_dict(value):
    result = callable_to_dict(value)

    assert isinstance(result, dict)
    assert 'csv' in result
    assert 'json' in result
    assert 'yaml' in result
    assert 'dict' in result

    if isinstance(value, dict):
        assert result['csv'] == value['csv']
        assert result['json'] == value['json']
        assert result['yaml'] == value['yaml']
        assert result['dict'] == value['dict']
    else:
        for key in result:
            assert result[key] == value