Example #1
0
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)
Example #2
0
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)
Example #3
0
def get_roster_player_service() -> RosterPlayerService:
    league_owned_player_repo = LeagueOwnedPlayerRepository(
        MockFirestoreProxy())
    roster_repo = LeagueRosterRepository(MockFirestoreProxy())
    league_transaction_repo = LeagueTransactionRepository(MockFirestoreProxy())

    return RosterPlayerService(league_owned_player_repo, roster_repo,
                               league_transaction_repo)
Example #4
0
def test_returns_error_when_no_league():
    league_repo = LeagueRepository(MockFirestoreProxy())
    league_config_repo = LeagueConfigRepository(MockFirestoreProxy())
    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.construct(league_id="league1")

    result = command_executor.execute(command)

    expected = False
    actual = result.success

    are_equal(expected, actual)
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,
                                                league_roster_repo,
                                                transaction_repo)
    waiver_service = WaiverService(roster_player_service)

    return ProcessWaiversCommandExecutor(state_repo=state_repo,
                                         league_roster_repo=league_roster_repo,
                                         league_repo=league_repo,
                                         waiver_service=waiver_service,
                                         league_week_repo=league_week_repo)
Example #6
0
def get_league_config_repo() -> LeagueConfigRepository:
    proxy = MockFirestoreProxy()
    return LeagueConfigRepository(proxy)
Example #7
0
def get_league_roster_repo() -> LeagueRosterRepository:
    proxy = MockFirestoreProxy()
    return LeagueRosterRepository(proxy)
Example #8
0
def get_user_league_repo() -> UserLeagueRepository:
    proxy = MockFirestoreProxy()
    return UserLeagueRepository(proxy)
Example #9
0
def get_user_repo() -> UserRepository:
    users = [get_commissioner()]
    proxy = MockFirestoreProxy(users)
    return UserRepository(proxy)
Example #10
0
def get_user_repo(user: User) -> UserRepository:
    users = [user]
    proxy = MockFirestoreProxy(users)
    return UserRepository(proxy)
Example #11
0
def get_league_transaction_repo() -> LeagueTransactionRepository:
    proxy = MockFirestoreProxy()
    return LeagueTransactionRepository(proxy)
Example #12
0
def get_user_league_repo(user_league) -> UserLeagueRepository:
    leagues = [user_league]
    proxy = MockFirestoreProxy(leagues)
    return UserLeagueRepository(proxy)
Example #13
0
def get_league_week_matchup_repo() -> LeagueWeekMatchupRepository:
    proxy = MockFirestoreProxy()
    return LeagueWeekMatchupRepository(proxy)
Example #14
0
def get_league_roster_repo(roster) -> LeagueRosterRepository:
    rosters = [roster]
    proxy = MockFirestoreProxy(rosters)
    return LeagueRosterRepository(proxy)
Example #15
0
def get_league_repo(league) -> LeagueRepository:
    leagues = [league]
    proxy = MockFirestoreProxy(leagues)
    return LeagueRepository(proxy)