Exemple #1
0
def test_check_reservation_ok(service: CancelReservation, context: Context,
                              house, reservation):
    context.house = house
    context.source = reservation

    result = service.check_reservation(context)
    assert is_successful(result), result.failure()
Exemple #2
0
def test_select_reservation_missed_pk(service: CancelReservation,
                                      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
Exemple #3
0
def test_check_reservation_canceled(service: CancelReservation,
                                    context: Context, house, reservation):
    context.house = house
    context.source = attr.evolve(reservation,
                                 status=ReservationStatuses.CANCEL)

    result = service.check_reservation(context)
    assert is_successful(result), result.failure()
Exemple #4
0
def test_check_reservation_room_close(service: CancelReservation,
                                      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
Exemple #5
0
def test_check_reservation_ota(service: CancelReservation, context: Context,
                               house, reservation):
    context.house = house
    context.source = attr.evolve(reservation,
                                 source=ReservationSources.BOOKING)

    result = service.check_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
Exemple #6
0
def test_cancel_reservation_ok(service: CancelReservation, 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.source = reservation

    result = service.cancel_reservation(context)
    assert is_successful(result)
    assert result.unwrap().reservation == _reservation
Exemple #7
0
def test_cancel_reservation_fail(service: CancelReservation, context: Context,
                                 house, reservation):
    service._reservations_repo = Mock(save=Mock(return_value=(Nothing, False)))
    context.house = house
    context.source = reservation

    result = service.cancel_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert result.failure().error.startswith(
        'Error save canceled Reservation ID=')
Exemple #8
0
def test_cancel_reservation_error(service: CancelReservation, context: Context,
                                  house, reservation):
    service._reservations_repo = Mock(save=Mock(
        side_effect=RuntimeError('ERR')))
    context.house = house
    context.source = reservation

    result = service.cancel_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
Exemple #9
0
def test_cancel_reservation_canceled(service: CancelReservation,
                                     context: Context, house, reservation):
    _reservation = attr.evolve(reservation, status=ReservationStatuses.CANCEL)
    service._reservations_repo = Mock(save=Mock(
        side_effect=RuntimeError('ERR')))
    context.house = house
    context.source = _reservation

    result = service.cancel_reservation(context)
    assert is_successful(result)
    assert result.unwrap().reservation == _reservation
Exemple #10
0
def test_select_reservation_ok(service: CancelReservation, 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
Exemple #11
0
def test_select_reservation_fail(service: CancelReservation, 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
Exemple #12
0
def test_select_reservation_error(service: CancelReservation, 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'
Exemple #13
0
def test_missed_house_id(service: CancelReservation, context: Context):
    context.house_id = None

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_house
Exemple #14
0
def context(house, reservation, user) -> Context:
    return Context(house_id=house.id, pk=reservation.id, user=user)