Exemple #1
0
def test_retrieve_game__returns_game():
    game, game_repository, _ = setup_test(game_id=7)
    interactor = interactors.ObserveGameInteractor(game_repository)

    retrieved_game, _ = interactor.retrieve_game(7)

    assert retrieved_game == game
Exemple #2
0
def get_game_state(game_id):
    """ Returns the game state """
    _ = interactors.OverduePlayerInteractor(game_repository())
    interactor = interactors.ObserveGameInteractor(game_repository())
    game = _try(lambda: interactor.retrieve_game(game_id))
    game_state = mapper.game_state_to_dto(game)
    DatabaseGateway.get_instance().commit()
    return game_state
Exemple #3
0
def test_retrieve_game__with_overdue_player__returns_0_seconds():
    last_action_timestamp = datetime.now() - timedelta(seconds=40)
    _, game_repo, _ = setup_test(action_timestamp=last_action_timestamp)

    interactor = interactors.ObserveGameInteractor(
        game_repository=game_repo, action_timeout=timedelta(seconds=20))
    _, remaining_seconds = interactor.retrieve_game(7)

    assert remaining_seconds == matchers.time_close_to(timedelta(seconds=0))
Exemple #4
0
def get_game_state(game_id):
    """ Returns the game state """
    _ = interactors.OverduePlayerInteractor(game_repository(), logging.get_logger())
    _ = interactors.UpdateOnTurnChangeInteractor(game_repository())
    action_timeout = timedelta(seconds=int(current_app.config["OVERDUE_PLAYER_TIMEDELTA_S"]))
    interactor = interactors.ObserveGameInteractor(game_repository(), action_timeout=action_timeout)
    game, remaining_timedelta = _try(lambda: interactor.retrieve_game(game_id))
    game_state = mapper.game_state_to_dto(game, remaining_timedelta)
    DatabaseGateway.get_instance().commit()
    return game_state
Exemple #5
0
def test_retrieve_game__before_update_period__does_not_update_last_observed_timestamp(
):
    last_observed_timestamp = datetime.now() - timedelta(seconds=10)
    game, game_repository, data_access = setup_test(
        last_observed_timestamp=last_observed_timestamp)

    interactor = interactors.ObserveGameInteractor(
        game_repository=game_repository, update_period=timedelta(seconds=60))
    interactor.retrieve_game(7)

    data_access.update_observed_timestamp.assert_not_called()
Exemple #6
0
def test_retrieve_game__with_nonexisting_last_observed_timestamp__updates_last_observed_timestamp(
):
    game, game_repository, data_access = setup_test(
        last_observed_timestamp=None)

    interactor = interactors.ObserveGameInteractor(
        game_repository=game_repository, update_period=timedelta(seconds=60))
    interactor.retrieve_game(7)

    close_to_now = matchers.time_close_to(datetime.now())
    data_access.update_observed_timestamp.assert_called_once_with(
        game.identifier, close_to_now)
Exemple #7
0
def test_retrieve_game__with_game_not_existing__raise_exception():
    game, game_repository, _ = setup_test(game_id=7)
    interactor = interactors.ObserveGameInteractor(game_repository)

    with pytest.raises(exceptions.GameNotFoundException):
        interactor.retrieve_game(3)