def complete(self, draft: Draft, league: League, transaction: Transaction): state = self.public_repo.get_state() start_week = state.current_week if state.locks and state.locks.any_locks(): start_week += 1 league.draft_state = DraftState.COMPLETE league.league_start_week = start_week self.league_repo.update(league, transaction) draft.complete = True self.league_config_repo.set_draft(league.id, draft, transaction)
def test_can_update_when_not_started(): league = League.construct(id="league1") league_repo = LeagueRepository(MockFirestoreProxy()) league_repo.create(league) scoring = ScoringSettings.create_default() league_config_repo = LeagueConfigRepository(MockFirestoreProxy()) league_config_repo.set_scoring_config(league.id, scoring) state_repo = StateRepository(MockFirestoreProxy()) transaction_repo = LeagueTransactionRepository(MockFirestoreProxy()) locks = Locks() state = State.construct(locks=locks) state_repo.set(state) command_executor = UpdateLeagueScoringCommandExecutor(league_repo, league_config_repo, state_repo, transaction_repo) command = UpdateLeagueScoringCommand(league_id=league.id, **scoring.dict()) result = command_executor.execute(command) expected = True actual = result.success are_equal(expected, actual)
def test_position_count_is_updated(position): mock_league = League(id="league1", name="test league", commissioner_id="user1", created=datetime.now(), draft_state=DraftState.NOT_STARTED, draft_type=DraftType.SNAKE, private=False, positions=LeaguePositionsConfig().create_positions(), draft_order=[DraftOrder(roster_id="user1")]) league_repo = LeagueRepository(MockFirestoreProxy()) league_repo.create(mock_league) league_config_repo = LeagueConfigRepository(MockFirestoreProxy()) league_config_repo.set_positions_config(mock_league.id, LeaguePositionsConfig()) d = {e: 1 for e in PositionType.all()} d[position] = 0 d["league_id"] = mock_league.id command = UpdateLeaguePositionsCommand.parse_obj(d) command_executor = UpdateLeaguePositionsCommandExecutor( league_repo, league_config_repo) command_executor.execute(command) updated_config = league_config_repo.get_positions_config(mock_league.id) expected = 0 actual = updated_config.dict()[position] are_equal(expected, actual)
def test_update_by_commisssioner(): league = League.construct(id="league1", draft_state=DraftState.NOT_STARTED, name="Test League", commissioner_id="commish") roster = Roster(id="roster1", name="Mock Roster") user_league = UserLeaguePreview.create(roster, league) roster_repo = get_league_roster_repo(roster) league_repo = get_league_repo(league) user_league_repo = get_user_league_repo(user_league) command_executor = UpdateRosterNameCommandExecutor( league_config_repo=get_league_config_repo, league_repo=league_repo, league_roster_repo=roster_repo, league_week_matchup_repo=get_league_week_matchup_repo(), user_league_repo=user_league_repo, publisher=get_publisher(), league_transaction_repo=get_league_transaction_repo()) new_name = "Update Roster Name" command = UpdateRosterNameCommand(league_id=league.id, roster_id=roster.id, roster_name=new_name, current_user_id=league.commissioner_id) result = command_executor.execute(command) assert result.success expected = new_name actual = roster_repo.get(league.id, roster.id).name are_equal(expected, actual)
def test_cannot_change_while_drafting(): league = League.construct(id="league1", draft_state=DraftState.IN_PROGRESS, name="Test League", commissioner_id="commish") roster = Roster(id="roster1", name="Mock Roster") user_league = UserLeaguePreview.create(roster, league) roster_repo = get_league_roster_repo(roster) league_repo = get_league_repo(league) user_league_repo = get_user_league_repo(user_league) command_executor = UpdateRosterNameCommandExecutor( league_config_repo=get_league_config_repo, league_repo=league_repo, league_roster_repo=roster_repo, league_week_matchup_repo=get_league_week_matchup_repo(), user_league_repo=user_league_repo, publisher=get_publisher(), league_transaction_repo=get_league_transaction_repo()) new_name = "Update Roster Name" command = UpdateRosterNameCommand(league_id=league.id, roster_id=roster.id, roster_name=new_name, current_user_id=roster.id) result = command_executor.execute(command) assert not result.success
def on_execute(self, command: CreateLeagueCommand) -> CreateLeagueResult: commissioner = self.user_repo.get(command.commissioner_id) positions_config = LeaguePositionsConfig() draft_order = [DraftOrder(roster_id=commissioner.id)] league = League(name=command.name, commissioner_id=command.commissioner_id, created=datetime.now(), draft_state=DraftState.NOT_STARTED, draft_type=DraftType.SNAKE, private=command.private, positions=positions_config.create_positions(), draft_order=draft_order) roster = create_roster(commissioner.id, commissioner.display_name) private_config = PrivateConfig(password=command.password) scoring_config = ScoringSettings.create_default() command.password = None # don't publish the league transaction = self.league_repo.firestore.create_transaction() @firestore.transactional def create_in_transaction(transaction): new_league = self.league_repo.create(league, transaction) self.league_config_repo.set_private_config(new_league.id, private_config, transaction) self.league_config_repo.set_scoring_config(new_league.id, scoring_config, transaction) self.league_config_repo.set_positions_config( new_league.id, positions_config, transaction) self.league_roster_repo.set(new_league.id, roster, transaction) commissioner.commissioner_of.append(new_league.id) user_league_preview = UserLeaguePreview.create(roster, new_league) self.user_league_repo.set(command.commissioner_id, user_league_preview, transaction) return new_league league = create_in_transaction(transaction) self.publisher.publish(league, LEAGUE_CREATED_TOPIC) return CreateLeagueResult(command=command, league=league)
def test_update_roster_name_updates_schedule_config_home(): week_number = 1 league = League.construct(id="league1", draft_state=DraftState.NOT_STARTED, name="Test League", schedule_generated=True, commissioner_id="commish") roster = Roster(id="roster1", name="Mock Roster") user_league = UserLeaguePreview.create(roster, league) schedule = create_mock_schedule(week_number) roster_repo = get_league_roster_repo(roster) league_repo = get_league_repo(league) user_league_repo = get_user_league_repo(user_league) matchup_repo = get_league_week_matchup_repo() config_repo = get_league_config_repo() matchup = Matchup(id="1", home=roster, type=MatchupType.REGULAR) matchup_repo.set(league.id, week_number, matchup) schedule.weeks[0].matchups.append(matchup) config_repo.set_schedule_config(league.id, schedule) command_executor = UpdateRosterNameCommandExecutor( league_config_repo=config_repo, league_repo=league_repo, league_roster_repo=roster_repo, league_week_matchup_repo=matchup_repo, user_league_repo=user_league_repo, publisher=get_publisher(), league_transaction_repo=get_league_transaction_repo()) new_name = "Update Roster Name" command = UpdateRosterNameCommand(league_id=league.id, roster_id=roster.id, roster_name=new_name, current_user_id=roster.id) result = command_executor.execute(command) assert result.success expected = new_name updated_schedule = config_repo.get_schedule_config(league.id) actual = updated_schedule.weeks[0].matchups[0].home.name are_equal(expected, actual)
first_name="Player", last_name="Three", position=PositionType.rb, team=Team.ssk(), status_current=1) wr1 = Player(id="4", cfl_central_id=4, first_name="Player", last_name="Four", position=PositionType.wr, team=Team.ssk(), status_current=1) league_positions = LeaguePositionsConfig().create_positions() league = League.construct(id="test_league", name="Test League", waivers_active=True) state = State.default(with_current_week=2) def get_target(rosters: List[Roster]) -> ProcessWaiversCommandExecutor: state_repo = StateRepository(MockFirestoreProxy([state])) league_repo = LeagueRepository(MockFirestoreProxy([deepcopy(league)])) league_roster_repo = LeagueRosterRepository(MockFirestoreProxy(rosters)) league_owned_player_repo = LeagueOwnedPlayerRepository( MockFirestoreProxy()) transaction_repo = LeagueTransactionRepository(MockFirestoreProxy()) league_week_repo = LeagueWeekRepository(MockFirestoreProxy()) roster_player_service = RosterPlayerService(league_owned_player_repo,