def test_select_house_error(service: DeleteRoomClose, context: Context): service._houses_repo = Mock(get=Mock(side_effect=RuntimeError("ERR"))) result = service.select_house(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert str(result.failure().exc) == "ERR"
def test_select_reservation_ok(service: DeleteRoomClose, 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: DeleteRoomClose, 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_success(service: DeleteRoomClose, house, reservation, user): _reservation = attr.evolve(reservation, status=ReservationStatuses.CANCEL) service._houses_repo = Mock(get=Mock(return_value=Some(house))) service._reservations_repo = Mock( get=Mock(return_value=Some(reservation)), save=Mock(return_value=(Some(_reservation), True))) result = service.execute('111-222-1', house.id, user) assert is_successful(result), result.failure() assert result.unwrap() == _reservation
def test_save_reservation_fail(service: DeleteRoomClose, 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.save assert result.failure().error.startswith("Error save Reservation")
def test_select_reservation_error(service: DeleteRoomClose, 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: DeleteRoomClose, context: Context, house, reservation): _reservation = attr.evolve(reservation, status=ReservationStatuses.CANCEL) 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: DeleteRoomClose, 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"
def test_check_reservation_ok(service: DeleteRoomClose, context: Context, house, reservation): context.house = house context.reservation = reservation result = service.check_reservation(context) assert is_successful(result)
def test_select_reservation_missed_pk(service: DeleteRoomClose, 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_make_reservation_from_data(service: DeleteRoomClose, context: Context, house, reservation): context.house = house context.reservation = reservation result = service.make_reservation_from_data(context) assert is_successful(result), result.failure() assert result.unwrap().reservation == attr.evolve( reservation, status=ReservationStatuses.CANCEL)
def test_check_reservation_not_close_room(service: DeleteRoomClose, context: Context, house, reservation): context.house = house context.reservation = attr.evolve(reservation, status=ReservationStatuses.NEW) result = service.check_reservation(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.missed_reservation
def test_select_house_ok(service: DeleteRoomClose, context: Context, house): service._houses_repo = Mock(get=Mock(return_value=Some(house))) result = service.select_house(context) assert is_successful(result) assert result.unwrap().house == house
def test_missed_house_id(service: DeleteRoomClose, context: Context): context.house_id = None result = service.select_house(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.missed_house
def service() -> DeleteRoomClose: return DeleteRoomClose()