def test_success(
    service: UpdateReservationPrices,
    context: Context,
    house,
    reservation,
    rate_plan,
    room_type,
    room,
    user,
    cancellation_policy,
):
    _reservation = attr.evolve(reservation, price_accepted=Decimal(3600))

    service._houses_repo = Mock(get=Mock(return_value=Some(house)))
    service._roomtypes_repo = Mock(select=Mock(return_value=[room_type]))
    service._rooms_repo = Mock(select=Mock(return_value=[room]))
    service._prices_repo = Mock(get_plan=Mock(return_value=Some(rate_plan)))
    service._reservations_repo = Mock(
        get=Mock(return_value=Some(reservation)),
        save=Mock(return_value=(Some(_reservation), True)))
    service._policies_repo = Mock(get=Mock(
        return_value=Some(cancellation_policy)))

    result = service.execute(house.id,
                             reservation.id,
                             reservation.rooms[0].id,
                             rate_plan.id,
                             user,
                             prices=context.prices)
    assert is_successful(result)
    assert result.unwrap() == _reservation
def test_select_reservation_ok(service: UpdateReservationPrices,
                               context: Context, house, reservation):
    service._reservations_repo = Mock(get=Mock(return_value=Some(reservation)))
    context.house = house

    result = service.select_reservation(context)
    assert is_successful(result)
    assert result.unwrap().source == reservation
def test_select_reservation_fail(service: UpdateReservationPrices,
                                 context: Context, house):
    service._reservations_repo = Mock(get=Mock(return_value=Nothing))
    context.house = house

    result = service.select_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
def test_select_reservation_error(service: UpdateReservationPrices,
                                  context: Context, house):
    service._reservations_repo = Mock(get=Mock(
        side_effect=RuntimeError('ERR')))
    context.house = house

    result = service.select_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
def test_save_reservation_ok(service: UpdateReservationPrices,
                             context: Context, house, reservation):
    _reservation = attr.evolve(reservation, price_accepted=Decimal(3600))
    service._reservations_repo = Mock(save=Mock(
        return_value=(Some(_reservation), True)))
    context.house = house
    context.reservation = reservation

    result = service.save_reservation(context)
    assert is_successful(result)
    assert result.unwrap().reservation == _reservation
def test_save_reservation_fail(service: UpdateReservationPrices,
                               context: Context, house, reservation):
    service._reservations_repo = Mock(save=Mock(return_value=(Nothing, False)))
    context.house = house
    context.reservation = reservation

    result = service.save_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert result.failure().error.startswith(
        'Error save prices for Reservation ID=')