示例#1
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
示例#2
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
示例#3
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=')
示例#4
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'
示例#5
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'
示例#6
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)
示例#7
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()
示例#8
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()
示例#9
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()
示例#10
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)
示例#11
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'
        })
示例#12
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,
            },
        ])
示例#13
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