def test_RodelbahnboxDictConverter():
v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
- class Sledrun(object):
- pass
other = collections.OrderedDict([
(u'Position', (47.30982, 9.986508)),
(u'Position oben', (None, None)),
(u'Bild', u'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
(u'In Übersichtskarte', True),
(u'Forumid', 72)])
- sledrun = v.to_python((other, Sledrun()))
+ sledrun = v.to_python(other)
assert sledrun.forum_id == 72
other2 = v.from_python(sledrun)
assert other == other2
"""Converts a dict with Rodelbahnbox properties to a Sledrun class. Does no validation."""
def to_python(self, value, state=None):
- """value is a tuple (props, sledrun) where the sledrun class will be populated or updated."""
- props, sledrun = value
+ """value is a dict of properties. If state is an object with the attribute sledrun, this sledrun class will be populated or updated."""
+ props = value
+ if isinstance(state, object) and hasattr(state, 'sledrun'):
+ sledrun = state.sledrun
+ else:
+ class Sledrun(object):
+ pass
+ sledrun = Sledrun()
for k, v in props.iteritems():
if k == u'Position': sledrun.position_latitude, sledrun.position_longitude = v
elif k == u'Position oben': sledrun.top_latitude, sledrun.top_longitude = v