def my_team(monkeypatch): user1 = User(1, "https://randomuser.me/api/portraits/lego/8.jpg", "Elijah", "Ku", friday=4) user2 = User(2, "https://randomuser.me/api/portraits/lego/8.jpg", "Sam", "Ku", monday=0) monkeypatch.setattr(persistence, "_all_users", {1: user1, 2: user2}) my_team = Team(1, "IFS", [user1, user2]) yield my_team
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_save_data(tmpdir): user1 = User(1, "https://randomuser.me/api/portraits/lego/8.jpg", "Elijah", "Ku") amazon_team = Team(1, "IFS", [user1]) persistence.add_user(user1) persistence.add_team(amazon_team) persistence.save_data(f"{tmpdir}/bla.json")
import json from data_model.team import Team from data_model.user import User user1 = User(1, "https://randomuser.me/api/portraits/lego/8.jpg", "Elijah", "Ku") user2 = User(2, "https://randomuser.me/api/portraits/lego/8.jpg", "Eli", "Kuh") amazon_team = Team(1, "IFS", [user1, user2]) amazon_team.add_connection(1, 2) def test_cycles(): elem = json.loads(amazon_team.to_json()) cycled = Team.from_json(elem) assert cycled == amazon_team
def test_cycles(): elem = json.loads(user1.to_json()) cycled = User.from_json(elem) assert cycled == user1