def test_check_reservation_ok(service: SelectReservation, context: Context, house, reservation): context.house = house context.reservation = reservation result = service.check_reservation(context) assert is_successful(result)
def test_check_reservation_wrong_house(service: SelectReservation, context: Context, house, reservation): context.house = house context.reservation = attr.evolve(reservation, house_id=999) result = service.check_reservation(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.missed_reservation
def test_select_reservation_ok(service: SelectReservation, 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().reservation == reservation
def test_select_reservation_fail(service: SelectReservation, 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_missed_reservation_id(service: SelectReservation, context: Context, house): context.house = house context.pk = None result = service.select_reservation(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.missed_reservation
def test_select_payed_amount_not_quotation_id(service: SelectReservation, context: Context, house, reservation): context.house = house context.reservation = attr.evolve(reservation, quotation_id=None) result = service.select_payed_amount(context) assert is_successful(result) assert result.unwrap().payed_amount == Decimal(0)
def test_select_payed_amount_empty(service: SelectReservation, context: Context, house, reservation): context.house = house context.reservation = reservation context.api = Mock(select_invoices_for_order=Mock(return_value=[])) result = service.select_payed_amount(context) assert is_successful(result) assert result.unwrap().payed_amount == Decimal(0)
def test_populate_with_rate_plans_fail(service: SelectReservation, context: Context, house, reservation): service._prices_repo = Mock(select_plans=Mock(return_value=[])) context.house = house context.reservation = reservation result = service.populate_with_rate_plans(context) assert is_successful(result) assert result.unwrap().reservation.rooms[0].rate_plan is None
def test_check_reservation_room_close(service: SelectReservation, context: Context, house, reservation): context.house = house context.reservation = attr.evolve(reservation, status=ReservationStatuses.CLOSE) result = service.check_reservation(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.missed_reservation
def test_populate_with_rooms_no_assigned(service: SelectReservation, context: Context, house, reservation): service._rooms_repo = Mock(select=Mock(side_effect=RuntimeError('ERR'))) context.house = house context.reservation = reservation result = service.populate_with_rooms(context) assert is_successful(result) for price in result.unwrap().reservation.rooms[0].day_prices: assert price.room is None
def test_select_reservation_error(service: SelectReservation, 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_populate_with_rooms_fail(service: SelectReservation, context: Context, house, reservation, room): service._rooms_repo = Mock(select=Mock(return_value=[])) context.house = house context.reservation = attr.evolve(reservation) context.reservation.rooms[0].day_prices[0].room_id = room.id result = service.populate_with_rooms(context) assert is_successful(result) for price in result.unwrap().reservation.rooms[0].day_prices: assert price.room is None
def test_populate_with_rooms_error(service: SelectReservation, context: Context, house, reservation, room): service._rooms_repo = Mock(select=Mock(side_effect=RuntimeError('ERR'))) context.house = house context.reservation = attr.evolve(reservation) context.reservation.rooms[0].day_prices[0].room_id = room.id result = service.populate_with_rooms(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert str(result.failure().exc) == 'ERR'
def test_populate_with_room_types_ok(service: SelectReservation, context: Context, house, reservation, room_type): service._roomtypes_repo = Mock(select=Mock(return_value=[room_type])) context.house = house context.reservation = reservation result = service.populate_with_room_types(context) assert is_successful(result) for price in result.unwrap().reservation.rooms[0].day_prices: assert price.room_type == room_type
def test_populate_with_room_types_error(service: SelectReservation, context: Context, house, reservation): service._roomtypes_repo = Mock(select=Mock( side_effect=RuntimeError('ERR'))) context.house = house context.reservation = reservation result = service.populate_with_room_types(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert str(result.failure().exc) == 'ERR'
def test_select_payed_amount_error(service: SelectReservation, context: Context, house, reservation): context.house = house context.reservation = reservation context.api = Mock(select_invoices_for_order=Mock( side_effect=RuntimeError('ERR'))) result = service.select_payed_amount(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert str(result.failure().exc) == 'ERR'
def test_populate_with_room_types_fail(service: SelectReservation, context: Context, house, reservation): service._roomtypes_repo = Mock(select=Mock(return_value=[])) context.house = house context.reservation = reservation result = service.populate_with_room_types(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert result.failure().error.startswith( 'Empty list of Room Types in House')
def test_select_payed_amount_ok(service: SelectReservation, context: Context, house, reservation): context.house = house context.reservation = reservation context.api = Mock(select_invoices_for_order=Mock(return_value=[ Mock(id=987, amount_total=50.0, amount_residual=30.0), Mock(id=988, amount_total=50.0, amount_residual=10.0), ])) result = service.select_payed_amount(context) assert is_successful(result) assert result.unwrap().payed_amount == Decimal(60) context.api.select_invoices_for_order.assert_called_once_with(321)
def test_populate_with_rooms_ok(service: SelectReservation, context: Context, house, reservation, room): service._rooms_repo = Mock(select=Mock(return_value=[room])) context.house = house context.reservation = attr.evolve(reservation) context.reservation.rooms[0].day_prices[0].room_id = room.id result = service.populate_with_rooms(context) assert is_successful(result) ctx = result.unwrap() assert ctx.reservation.rooms[0].day_prices[0].room == room assert ctx.reservation.rooms[0].day_prices[1].room is None assert ctx.reservation.rooms[0].day_prices[2].room is None