Example #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)
Example #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)