Exemple #1
0
def test_select_house_ok(service: CancelReservationInOdoo, 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
Exemple #2
0
def test_select_user_fail(service: CancelReservationInOdoo, context: Context,
                          house):
    service._members_repo = Mock(get_user_by_id=Mock(return_value=Nothing))
    context.house = house

    result = service.select_user(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_user
Exemple #3
0
def test_select_house_error(service: CancelReservationInOdoo,
                            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'
Exemple #4
0
def test_select_user_ok(service: CancelReservationInOdoo, context: Context,
                        house, user):
    service._members_repo = Mock(get_user_by_id=Mock(return_value=Some(user)))
    context.house = house

    result = service.select_user(context)
    assert is_successful(result)
    assert result.unwrap().user == user
Exemple #5
0
def test_select_reservation_ok(service: CancelReservationInOdoo,
                               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
Exemple #6
0
def test_select_user_error(service: CancelReservationInOdoo, context: Context,
                           house):
    service._members_repo = Mock(get_user_by_id=Mock(
        side_effect=RuntimeError('ERR')))
    context.house = house

    result = service.select_user(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_user
    assert str(result.failure().exc) == 'ERR'
Exemple #7
0
def test_success(service: CancelReservationInOdoo, house, reservation, user):
    service._houses_repo = Mock(get=Mock(return_value=Some(house)))
    service._reservations_repo = Mock(get=Mock(return_value=Some(reservation)))
    service._members_repo = Mock(get_user_by_id=Mock(return_value=Some(user)))
    service.get_rpc_api = Mock(
        return_value=Mock(cancel_opportunity=Mock(return_value=None),
                          cancel_quotation=Mock(return_value=None)))

    result = service.execute(house.id, reservation.id, user_id=user.id)
    assert is_successful(result)
    assert result.unwrap()
Exemple #8
0
def test_select_reservation_missed_pk(service: CancelReservationInOdoo,
                                      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 #9
0
def test_check_reservation_wrong_house(service: CancelReservationInOdoo,
                                       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
Exemple #10
0
def test_check_reservation_room_close(service: CancelReservationInOdoo,
                                      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.room_close_reservation
Exemple #11
0
def test_check_reservation_not_cancelled(service: CancelReservationInOdoo,
                                         context: Context, house, reservation):
    context.house = house
    context.reservation = attr.evolve(reservation,
                                      status=ReservationStatuses.MODIFY)

    result = service.check_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
Exemple #12
0
def test_cancel_quotation_error(service: CancelReservationInOdoo,
                                context: Context, house, reservation):
    context.house = house
    context.reservation = reservation
    context.api = Mock(cancel_quotation=Mock(side_effect=RuntimeError('ERR')))

    result = service.cancel_quotation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
Exemple #13
0
def test_cancel_opportunity_ok(service: CancelReservationInOdoo,
                               context: Context, house, reservation):
    context.house = house
    context.reservation = reservation
    context.api = Mock(cancel_opportunity=Mock(return_value=None))

    result = service.cancel_opportunity(context)
    assert is_successful(result)

    context.api.cancel_opportunity.assert_called_once_with(
        reservation.opportunity_id, CrmLostReasons.EXPENSIVE)
Exemple #14
0
def test_cancel_quotation_ok(service: CancelReservationInOdoo,
                             context: Context, house, reservation):
    context.house = house
    context.reservation = reservation
    context.api = Mock(cancel_quotation=Mock(return_value=None))

    result = service.cancel_quotation(context)
    assert is_successful(result)

    context.api.cancel_quotation.assert_called_once_with(
        reservation.quotation_id)
Exemple #15
0
def test_cancel_quotation_for_missed_quotation_id(
        service: CancelReservationInOdoo, context: Context, house,
        reservation):
    context.house = house
    context.reservation = attr.evolve(reservation, quotation_id=None)
    context.api = Mock(cancel_quotation=Mock(side_effect=RuntimeError('ERR')))

    result = service.cancel_quotation(context)
    assert is_successful(result)

    context.api.cancel_quotation.assert_not_called()
Exemple #16
0
def test_select_house_fail(service: CancelReservationInOdoo, context: Context):
    service._houses_repo = Mock(get=Mock(return_value=Nothing))

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_house
Exemple #17
0
def test_missed_house_id(service: CancelReservationInOdoo, context: Context):
    context.house_id = None

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_house
Exemple #18
0
def service() -> CancelReservationInOdoo:
    return CancelReservationInOdoo()