def from_json(elem): assert elem["class"] == Team.__name__ del elem["class"] elem = dict(elem) elem["users"] = [User.from_json(u) for u in elem["users"]] elem["connections"] = { int(k): v for k, v in elem["connections"].items() } return Team(**elem)
def test_cycles(): elem = json.loads(user1.to_json()) cycled = User.from_json(elem) assert cycled == user1