Пример #1
0
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)
Пример #2
0
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
Пример #3
0
        def join(transaction):
            league = self.league_repo.get(command.league_id, transaction)

            if not league:
                return JoinLeagueResult(command=command,
                                        error="League not found")

            if league.registration_closed:
                return JoinLeagueResult(command=command,
                                        error="Registration is closed")

            private_config = self.league_config_repo.get_private_config(
                command.league_id, transaction)

            if private_config.password and command.password != private_config.password:
                return JoinLeagueResult(command=command,
                                        error="Incorrect password")

            manager = self.user_repo.get(command.user_id, transaction)

            roster = create_roster(manager.id, manager.display_name)
            user_league_preview = UserLeaguePreview.create(roster, league)
            league.draft_order.append(DraftOrder(roster_id=manager.id))
            league.schedule_generated = False

            self.league_repo.update(league, transaction)
            self.league_roster_repo.set(league.id, roster, transaction)
            self.user_league_repo.set(manager.id, user_league_preview,
                                      transaction)

            return JoinLeagueResult(command=command, roster=roster)
Пример #4
0
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)
Пример #5
0
        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