def test__serialize_with(self): class Example(Model): pass tag = Adjacent(tag='kind', content='data') tag._bind(Example) d = {'something': 1} assert tag._serialize_with(Example(), d) == {'kind': 'Example', 'data': d}
def test__deserialize_with(self): class Example(Model): pass class Example2(Example): pass tag = Adjacent(tag='kind', content='data') tag._bind(Example) model = Example() d = {'kind': 'Example2', 'data': {'something': 1}} result = tag._deserialize_with(model, d) assert result[0] is model assert result[0].__class__ is Example2 assert result[1] is d['data']
def test___init___basic(self): tag = Adjacent() assert tag.tag == 'tag' assert tag.content == 'content' assert tag.recurse is False assert tag.serializers == [] assert tag.deserializers == []
def test___init___options(self): tag = Adjacent(tag='kind', content='data', recurse=True, serializers=[None]) assert tag.tag == 'kind' assert tag.content == 'data' assert tag.recurse is True assert tag.deserializers == [] assert tag.serializers == [None]
def test__deserialize_with_untagged(self): class Example(Model): pass class Example2(Example): pass tag = Adjacent(tag='kind', content='data') with raises(ValidationError) as e: tag._deserialize_with(object(), {'something': 1}) assert e.value.messages() == "missing data, expected tag 'kind'" with raises(ValidationError) as e: tag._deserialize_with(object(), {'kind': 'Example2', 'something': 1}) assert e.value.messages() == "missing data, expected content 'data'"