Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 5
0
async def get_league(
    league_id: str,
    league_repo: LeagueRepository = Depends(get_league_repository)):
    return league_repo.get(league_id)
Exemplo n.º 6
0
def get_league_repo() -> LeagueRepository:
    proxy = MockFirestoreProxy()
    return LeagueRepository(proxy)
Exemplo n.º 7
0
def get_league_repo(league) -> LeagueRepository:
    leagues = [league]
    proxy = MockFirestoreProxy(leagues)
    return LeagueRepository(proxy)