From 22a3ba7d66926b9d1fcef07b4a8322da88b28002 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 23 Aug 2013 13:58:51 +0200 Subject: [PATCH] [IMP] stock: convert yml test to python bzr revid: mat@openerp.com-20130823115851-36tcrj17n5bme3uu --- addons/stock/__openerp__.py | 1 - addons/stock/test/multicompany.yml | 68 ------------------ addons/stock/tests/__init__.py | 28 ++++++++ addons/stock/tests/test_multicompany.py | 92 +++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 69 deletions(-) delete mode 100644 addons/stock/test/multicompany.yml create mode 100644 addons/stock/tests/__init__.py create mode 100644 addons/stock/tests/test_multicompany.py diff --git a/addons/stock/__openerp__.py b/addons/stock/__openerp__.py index db7117ce2b3..b3d7e30f1ce 100644 --- a/addons/stock/__openerp__.py +++ b/addons/stock/__openerp__.py @@ -94,7 +94,6 @@ Dashboard / Reports for Warehouse Management will include: # 'test/opening_stock.yml', # 'test/shipment.yml', # 'test/stock_report.yml', - 'test/multicompany.yml' ], 'installable': True, 'application': True, diff --git a/addons/stock/test/multicompany.yml b/addons/stock/test/multicompany.yml deleted file mode 100644 index 2c0353aa71d..00000000000 --- a/addons/stock/test/multicompany.yml +++ /dev/null @@ -1,68 +0,0 @@ - -- - Set the current user as multicompany user -- - !context - uid: 'stock.multicompany_user' - -- - check no error on getting default stock.move values in multicompany setting -- - !python {model: stock.move}: | - location_obj = self.pool.get('stock.location') - fields = ['location_id', 'location_dest_id'] - for type in ('in', 'internal', 'out'): - context['picking_type'] = type - defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context) - log('type: %s got defaults: %s', type, defaults) - for field in fields: - if defaults.get(field): - try: - location_obj.check_access_rule(cr, uid, [defaults[field]], 'read', context) - except Exception, exc: - assert False, "unreadable location %s: %s" % (field, exc) - assert defaults['type'] == type, "wrong move type" - -- - check onchange_move_type does not return unreadable in multicompany setting -- - !python {model: stock.move}: | - location_obj = self.pool.get('stock.location') - fields = ['location_id', 'location_dest_id'] - for type in ('in', 'internal', 'out'): - result = self.onchange_move_type(cr, uid, [], type, context)['value'] - log('type: %s got: %s', type, result) - for field in fields: - if result.get(field): - try: - location_obj.check_access_rule(cr, uid, [result[field]], 'read', context) - except Exception, exc: - assert False, "unreadable location %s: %s" % (field, exc) - -- - check default location readability for stock_fill_inventory in multicompany setting -- - !python {model: stock.fill.inventory}: | - location_obj = self.pool.get('stock.location') - defaults = self.default_get(cr, uid, ['location_id'], context) - log('got defaults: %s', defaults) - if defaults.get('location_id'): - try: - location_obj.check_access_rule(cr, uid, [defaults['location_id']], 'read', context) - except Exception, exc: - assert False, "unreadable source location: %s" % exc - -- - check default locations for warehouse in multicompany setting -- - !python {model: stock.warehouse}: | - location_obj = self.pool.get('stock.location') - fields = ['lot_input_id', 'lot_stock_id', 'lot_output_id'] - defaults = self.default_get(cr, uid, fields, context) - log('got defaults: %s', defaults) - for field in fields: - if defaults.get(field): - try: - location_obj.check_access_rule(cr, uid, [defaults[field]], 'read', context) - except Exception, exc: - assert False, "unreadable default %s: %s" % (field, exc) diff --git a/addons/stock/tests/__init__.py b/addons/stock/tests/__init__.py new file mode 100644 index 00000000000..39ebd5e451f --- /dev/null +++ b/addons/stock/tests/__init__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import test_multicompany + +checks = [ + test_multicompany, +] + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/tests/test_multicompany.py b/addons/stock/tests/test_multicompany.py new file mode 100644 index 00000000000..d30e7d0ef2b --- /dev/null +++ b/addons/stock/tests/test_multicompany.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2012-TODAY OpenERP S.A. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.tests import common + + +class TestStockMulticompany(common.TransactionCase): + + def setUp(self): + super(TestStockMulticompany, self).setUp() + cr, uid = self.cr, self.uid + + # Usefull models + self.ir_model_data = self.registry('ir.model.data') + self.res_users = self.registry('res.users') + self.stock_location = self.registry('stock.location') + self.stock_move = self.registry('stock.move') + self.stock_fill_inventory = self.registry('stock.fill.inventory') + self.stock_warehouse = self.registry('stock.warehouse') + + model, self.multicompany_user_id = self.ir_model_data.get_object_reference(cr, uid, 'stock', 'multicompany_user') + + def test_00_multicompany_default_stock_move(self): + """check no error on getting default stock.move values in multicompany setting""" + cr, uid, context = self.cr, self.multicompany_user_id, {} + fields = ['location_id', 'location_dest_id'] + for type in ('in', 'internal', 'out'): + context['picking_type'] = type + defaults = self.stock_move.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context) + for field in fields: + if defaults.get(field): + try: + self.stock_location.check_access_rule(cr, uid, [defaults[field]], 'read', context) + except Exception, exc: + assert False, "unreadable location %s: %s" % (field, exc) + self.assertEqual(defaults['type'], type, "wrong move type") + + + def test_10_multicompany_onchange_move_type(self): + """check onchange_move_type does not return unreadable in multicompany setting""" + cr, uid, context = self.cr, self.multicompany_user_id, {} + fields = ['location_id', 'location_dest_id'] + for type in ('in', 'internal', 'out'): + result = self.stock_move.onchange_move_type(cr, uid, [], type, context)['value'] + for field in fields: + if result.get(field): + try: + self.stock_location.check_access_rule(cr, uid, [result[field]], 'read', context) + except Exception, exc: + assert False, "unreadable location %s: %s" % (field, exc) + + + def test_20_multicompany_default_stock_fill_inventory(self): + """check default location readability for stock_fill_inventory in multicompany setting""" + cr, uid, context = self.cr, self.multicompany_user_id, {} + defaults = self.stock_fill_inventory.default_get(cr, uid, ['location_id'], context) + if defaults.get('location_id'): + try: + self.stock_location.check_access_rule(cr, uid, [defaults['location_id']], 'read', context) + except Exception, exc: + assert False, "unreadable source location: %s" % exc + + + def test_30_multicompany_default_warehouse_location(self): + """check default locations for warehouse in multicompany setting""" + cr, uid, context = self.cr, self.multicompany_user_id, {} + fields = ['lot_input_id', 'lot_stock_id', 'lot_output_id'] + defaults = self.stock_warehouse.default_get(cr, uid, fields, context) + for field in fields: + if defaults.get(field): + try: + self.stock_location.check_access_rule(cr, uid, [defaults[field]], 'read', context) + except Exception, exc: + assert False, "unreadable default %s: %s" % (field, exc)