def test_check_reservation_room_close(service: UpdateReservationGuest, context: Context, house, reservation): context.house = house context.source = 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_select_reservation_missed_pk(service: UpdateReservationGuest, 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_check_reservation_wrong_house(service: UpdateReservationGuest, context: Context, house, reservation): context.house = house context.source = 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_save_reservation_other_guest(service: UpdateReservationGuest, context: Context, house, reservation): service._reservations_repo = Mock(save=Mock( side_effect=RuntimeError('ERR'))) context.contact_id = 999 context.house = house context.source = reservation context.reservation = reservation result = service.save_reservation(context) assert is_successful(result) assert result.unwrap().reservation == reservation
def test_save_reservation_ok(service: UpdateReservationGuest, context: Context, house, reservation): _reservation = attr.evolve(reservation, guest_name='John') service._reservations_repo = Mock(save=Mock( return_value=(Some(_reservation), True))) context.house = house context.source = reservation context.reservation = reservation result = service.save_reservation(context) assert is_successful(result) assert result.unwrap().reservation == _reservation
def test_save_reservation_fail(service: UpdateReservationGuest, context: Context, house, reservation): service._reservations_repo = Mock(save=Mock(return_value=(Nothing, False))) context.house = house context.source = reservation 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 guest information for Reservation ID=')
def test_save_reservation_error(service: UpdateReservationGuest, context: Context, house, reservation): service._reservations_repo = Mock(save=Mock( side_effect=RuntimeError('ERR'))) context.house = house context.source = reservation 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'
def test_make_reservation_from_data_name(service: UpdateReservationGuest, context: Context, house, reservation): context.house = house context.source = reservation result = service.make_reservation_from_data(context) assert is_successful(result) _reservation = result.unwrap().reservation assert _reservation.guest_name == 'John' assert _reservation.guest_surname == 'Smith' assert _reservation.guest_email == '*****@*****.**' assert _reservation.guest_phone == '12345'
def test_make_reservation_from_data_phone(service: UpdateReservationGuest, context: Context, house, reservation): context.attribute = 'phone' context.value = '+123123123' context.house = house context.source = reservation result = service.make_reservation_from_data(context) assert is_successful(result) _reservation = result.unwrap().reservation assert _reservation.guest_name == 'TEST' assert _reservation.guest_surname == 'Some' assert _reservation.guest_email == '*****@*****.**' assert _reservation.guest_phone == '+123123123'
def test_select_reservation_ok(service: UpdateReservationGuest, 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: UpdateReservationGuest, 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: UpdateReservationGuest, 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_missed_house_id(service: UpdateReservationGuest, context: Context): context.house_id = None result = service.select_house(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.missed_house
def context(house, reservation) -> Context: return Context(house_id=house.id, pk=reservation.id, contact_id=11, attribute='name', value='John Smith')