Beispiel #1
0
def test_select_reservation_ok(service: UpdateReservationInOdoo,
                               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
Beispiel #2
0
def test_select_user_fail(service: UpdateReservationInOdoo, 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
Beispiel #3
0
def test_select_user_ok(service: UpdateReservationInOdoo, 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
Beispiel #4
0
def test_check_reservation_wrong_house(service: UpdateReservationInOdoo,
                                       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
Beispiel #5
0
def test_select_reservation_missed_pk(service: UpdateReservationInOdoo,
                                      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
Beispiel #6
0
def test_check_reservation_room_close(service: UpdateReservationInOdoo,
                                      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
Beispiel #7
0
def test_select_user_error(service: UpdateReservationInOdoo, 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'
Beispiel #8
0
def test_get_quotation_state_fail(service: UpdateReservationInOdoo,
                                  context: Context, house, user, reservation):
    context.house = house
    context.user = user
    context.reservation = reservation
    context.is_need_update_quotation = True
    context.api = Mock(get_quotation=Mock(return_value=Nothing))

    result = service.get_quotation_state(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert result.failure().error.startswith('Missed Quotation ID=')
Beispiel #9
0
def test_update_opportunity_error(service: UpdateReservationInOdoo,
                                  context: Context, house, user, reservation):
    context.house = house
    context.user = user
    context.reservation = reservation
    context.api = Mock(update_opportunity=Mock(
        side_effect=RuntimeError('ERR')))

    result = service.update_opportunity(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
Beispiel #10
0
def test_get_quotation_state_error(service: UpdateReservationInOdoo,
                                   context: Context, house, user, reservation):
    context.house = house
    context.user = user
    context.reservation = reservation
    context.is_need_update_quotation = True
    context.api = Mock(get_quotation=Mock(side_effect=RuntimeError('ERR')))

    result = service.get_quotation_state(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
Beispiel #11
0
def test_update_opportunity_if_no_opportunity_id(
        service: UpdateReservationInOdoo, context: Context, house, user,
        reservation):
    context.house = house
    context.user = user
    context.reservation = attr.evolve(reservation, opportunity_id=None)
    context.api = Mock(update_opportunity=Mock(
        side_effect=RuntimeError('ERR')))

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

    context.api.update_opportunity.assert_not_called()
Beispiel #12
0
def test_lock_back_quotation_ok(service: UpdateReservationInOdoo,
                                context: Context, house, user, reservation):
    context.house = house
    context.user = user
    context.reservation = reservation
    context.is_need_update_quotation = True
    context.is_locked_quotation = True
    context.api = Mock(confirm_quotation=Mock(return_value=None))

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

    context.api.confirm_quotation.assert_called_once_with(321)
Beispiel #13
0
def test_unlock_quotation_no_need_update(service: UpdateReservationInOdoo,
                                         context: Context, house, user,
                                         reservation):
    context.house = house
    context.user = user
    context.reservation = reservation
    context.is_need_update_quotation = False
    context.api = Mock(unlock_quotation=Mock(side_effect=RuntimeError('ERR')))

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

    context.api.unlock_quotation.assert_not_called()
Beispiel #14
0
def test_check_need_update_quotation_no_quotation_id(
        service: UpdateReservationInOdoo, context: Context, house, user,
        reservation):
    context.house = house
    context.user = user
    context.reservation = attr.evolve(reservation, quotation_id=None)
    context.api = Mock(get_quotation_items=Mock(
        side_effect=RuntimeError('ERR')))

    result = service.check_need_update_quotation(context)
    assert is_successful(result)
    assert not result.unwrap().is_need_update_quotation

    context.api.get_quotation_items.assert_not_called()
Beispiel #15
0
def test_update_opportunity_ok(service: UpdateReservationInOdoo,
                               context: Context, house, user, reservation):
    context.house = house
    context.user = user
    context.reservation = reservation
    context.api = Mock(update_opportunity=Mock(return_value=None))

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

    context.api.update_opportunity.assert_called_once_with(
        123, {
            'name': reservation.get_opportunity_name(),
            'planned_revenue': '3360'
        })
Beispiel #16
0
def test_get_quotation_state_ok_not_locked(service: UpdateReservationInOdoo,
                                           context: Context, house, user,
                                           reservation):
    context.house = house
    context.user = user
    context.reservation = reservation
    context.is_need_update_quotation = True
    context.api = Mock(get_quotation=Mock(
        return_value=Some(Mock(id=321, state='draft'))))

    result = service.get_quotation_state(context)
    assert is_successful(result)
    assert not result.unwrap().is_locked_quotation

    context.api.get_quotation.assert_called_once_with(321)
Beispiel #17
0
def test_update_quotation_ok(service: UpdateReservationInOdoo,
                             context: Context, house, user, reservation,
                             room_type):
    context.house = house
    context.user = user
    context.reservation = reservation
    context.is_need_update_quotation = True
    context.api = Mock(update_quotation_items=Mock(return_value=None))

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

    context.api.update_quotation_items.assert_called_once_with(
        321, [
            {
                'product_id': room_type.id,
                'item_date': datetime.date.today().strftime(DATE_FORMAT),
                'product_uom_qty': 1.0,
                'price_unit': 1120.0,
            },
            {
                'product_id':
                room_type.id,
                'item_date':
                (datetime.date.today() +
                 datetime.timedelta(days=1)).strftime(DATE_FORMAT),
                'product_uom_qty':
                1.0,
                'price_unit':
                1120.0,
            },
            {
                'product_id':
                room_type.id,
                'item_date':
                (datetime.date.today() +
                 datetime.timedelta(days=2)).strftime(DATE_FORMAT),
                'product_uom_qty':
                1.0,
                'price_unit':
                1120.0,
            },
        ])
Beispiel #18
0
def test_check_need_update_quotation_different(
        service: UpdateReservationInOdoo, context: Context, house, user,
        reservation, room_type):
    context.house = house
    context.user = user
    context.reservation = reservation
    context.api = Mock(get_quotation_items=Mock(return_value=[
        {
            'id': 1230,
            'product_id': [room_type.id, room_type.name],
            'item_date': datetime.date.today().strftime(DATE_FORMAT),
            'product_uom_qty': 1.0,
            'price_unit': 1120.0,
        },
        {
            'id':
            1231,
            'product_id': [room_type.id, room_type.name],
            'item_date': (datetime.date.today() +
                          datetime.timedelta(days=1)).strftime(DATE_FORMAT),
            'product_uom_qty':
            1.0,
            'price_unit':
            1120.0,
        },
        {
            'id':
            1232,
            'product_id': [room_type.id, room_type.name],
            'item_date': (datetime.date.today() +
                          datetime.timedelta(days=2)).strftime(DATE_FORMAT),
            'product_uom_qty':
            1.0,
            'price_unit':
            1000.0,
        },
    ]))

    result = service.check_need_update_quotation(context)
    assert is_successful(result)
    assert result.unwrap().is_need_update_quotation