Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 3
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)
Exemplo n.º 4
0
async def update_roster_name(
    command: UpdateRosterNameCommand,
    current_user_id: str = Depends(get_current_user_id),
    cmd_ex: UpdateRosterNameCommandExecutor = Depends(
        create_update_roster_name_command_executor)):
    command.current_user_id = current_user_id
    return cmd_ex.execute(command)