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=')
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'
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)
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()
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)
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, }, ])