def test_one_to_many_follow(self): child = OneToManyChild('child') parent = OneToManyParent('parent') parent.child = child self.session.add(parent) self.session.commit() assert parent.asdict(follow=['child']) == {'id': parent.id, 'name': parent.name, 'child': child.asdict()}
def test_one_to_many_plain(self): child = OneToManyChild('child') self.session.add(child) parent = OneToManyParent('parent') parent.child = child self.session.add(parent) self.session.commit() parent.fromdict( { 'name': 'Parent new name', 'child': { 'name': 'Child new name' } }, follow=['child']) result = parent.asdict(follow=['child']) expected = { 'id': parent.id, 'name': 'Parent new name', 'child': { 'id': child.id, 'name': 'Child new name' } } assert result == expected, "%r == %r" % (result, expected)
def test_one_to_many_follow_with_parent(self): child = OneToManyChild('child') parent = OneToManyParent('parent') parent.child = child self.session.add(parent) self.session.commit() assert parent.asdict(follow={ 'child': { 'parent': 'relationships', }, }) == { 'id': parent.id, 'name': parent.name, 'relationships': { 'child': child.asdict(), }, }