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=')
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_error(service: UpdateReservationPrices, context: Context, house, reservation): service._reservations_repo = Mock(save=Mock( side_effect=RuntimeError('ERR'))) context.house = house context.reservation = reservation result = service.save_reservation(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert str(result.failure().exc) == 'ERR'