def test_accept_reservation_fail(service: CreateReservation, context: Context,
                                 house, room_type):
    service._reservations_repo = Mock(accept=Mock(return_value=Nothing))
    context.house = house
    context.room_type = room_type
    context.reservation = Reservation(
        id=111,
        house_id=house.id,
        connection_id=None,
        source=ReservationSources.MANUAL,
        channel=None,
        channel_id='',
        checkin=context.request.checkin,
        checkout=context.request.checkout,
        booked_at=timezone.now(),
        status=ReservationStatuses.HOLD,
    )

    result = service.accept_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.save
    assert result.failure().error.startswith('Error accept new Reservation')
def test_accept_reservation_error(service: CreateReservation, context: Context,
                                  house, room_type):
    service._reservations_repo = Mock(accept=Mock(
        side_effect=RuntimeError('ERR')))
    context.house = house
    context.room_type = room_type
    context.reservation = Reservation(
        id=111,
        house_id=house.id,
        connection_id=None,
        source=ReservationSources.MANUAL,
        channel=None,
        channel_id='',
        checkin=context.request.checkin,
        checkout=context.request.checkout,
        booked_at=timezone.now(),
        status=ReservationStatuses.HOLD,
    )

    result = service.accept_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
def test_accept_reservation_ok(service: CreateReservation, context: Context,
                               house, room_type):
    reservation = Reservation(
        id=111,
        house_id=house.id,
        connection_id=None,
        source=ReservationSources.MANUAL,
        channel=None,
        channel_id='',
        checkin=context.request.checkin,
        checkout=context.request.checkout,
        booked_at=timezone.now(),
        status=ReservationStatuses.HOLD,
        is_verified=True,
    )
    service._reservations_repo = Mock(accept=Mock(
        return_value=Some(reservation)))
    context.house = house
    context.room_type = room_type
    context.reservation = attr.evolve(reservation, is_verified=False)

    result = service.accept_reservation(context)
    assert is_successful(result)
    assert result.unwrap().reservation == reservation