def test_select_bot_user_fail(service: UpdateReservationCache,
                              context: Context, house, reservation):
    service._members_repo = Mock(get_bot_user=Mock(return_value=Nothing))
    context.house = house
    context.reservations = [reservation]

    result = service.select_bot_user(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_user
def test_select_bot_user_ok(service: UpdateReservationCache, context: Context,
                            house, reservation, user):
    service._members_repo = Mock(get_bot_user=Mock(return_value=Some(user)))
    context.house = house
    context.reservations = [reservation]

    result = service.select_bot_user(context)
    assert is_successful(result), result.failure()
    assert result.unwrap().user == user
def test_select_bot_user_error(service: UpdateReservationCache,
                               context: Context, house, reservation):
    service._members_repo = Mock(get_bot_user=Mock(
        side_effect=RuntimeError('ERR')))
    context.house = house
    context.reservations = [reservation]

    result = service.select_bot_user(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'