diff --git a/setup.py b/setup.py index 0e00b05..9b68e5c 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ from setuptools import setup, find_packages setup(name='OdooLocust', - version='1.6.6', + version='1.6.7', description='Easily load test Odoo using Locust and odoolib.', author='Nicolas Seinlet', author_email='', diff --git a/src/OdooLocust/OdooTaskSet.py b/src/OdooLocust/OdooTaskSet.py index 81e58e1..41b0574 100644 --- a/src/OdooLocust/OdooTaskSet.py +++ b/src/OdooLocust/OdooTaskSet.py @@ -26,6 +26,7 @@ # ############################################################################## import random +import names from locust import task, TaskSet @@ -37,6 +38,12 @@ class OdooTaskSet(TaskSet): list_fields = [] kanban_fields = [] filters = [] + random_id = -1 + + def on_start(self): + super().on_start() + if self.model_name: + self.model = self.client.get_model(self.model_name) def _get_user_context(self): res = self.client.get_model('res.users').read(self.client.user_id, ['lang', 'tz']) @@ -61,7 +68,6 @@ def _load_menu(self): menu = res[menu_id].get('action') if menu: menus.append(menu.split(",")) - print(menus) return menus def _action_load(self, action_id, action_type=None): @@ -75,22 +81,27 @@ def _check_fields(self, model, fields_list): return [ f for f in fields_list if f in all_fields.keys() ] def _load_fields_lists(self, form=True, list=True, kanban=False, filters=True): - if form: - self.form_fields = self._fields_view_get(self.model_name, "form") - if list: - self.list_fields = self._fields_view_get(self.model_name, "list") - if kanban: - self.kanban_fields = self._fields_view_get(self.model_name, "kanban") - if filters: - self.filters = self._filters_view_get(self.model_name) + self.form_fields = self._fields_view_get(self.model_name, "form") if form else [] + self.list_fields = self._fields_view_get(self.model_name, "list") if list else [] + self.kanban_fields = self._fields_view_get(self.model_name, "kanban") if kanban else [] + self.filters = self._filters_view_get(self.model_name) if filters else [] + + def _get_search_domain(self): + if self.filters and random.randint(0, 10) < 3: + return random.choice(self.filters) + if 'name' in self.list_fields and random.randint(0, 10) < 6: + name = names.get_first_name() + return [('name', 'ilike', name)] + return [] class OdooGenericTaskSet(OdooTaskSet): - def on_start(self): - self.menu = self._load_menu() - self.randomlyChooseMenu() + # def on_start(self): + # super().on_start() + # self.menu = self._load_menu() + # self.randomlyChooseMenu() - @task(1) + # @task(1) def randomlyChooseMenu(self): self.model_name = False self.model = False @@ -101,43 +112,58 @@ def randomlyChooseMenu(self): self.model = self.client.get_model(self.model_name) self._load_fields_lists(kanban="kanban" in self.last_action.get('view_mode', [])) + @task(10) + def test_search(self): + ids = self.model.search(self._get_search_domain(), context=self.client.get_user_context(), limit=80) + if ids: + self.random_id = random.choice(ids) + + @task(5) + def test_websearchread(self): + res = self.model.web_search_read( + specification={f: {} for f in self.list_fields}, + domain=self._get_search_domain(), + limit=80, + context=self.client.get_user_context() + ) + if res and res['records']: + self.random_id = res[0]['id'] + @task(30) def form_view(self): - domain = [] - if self.filters and random.randint(0, 10) < 3: - domain = random.choice(self.filters) + domain = self._get_search_domain() context = self.client.get_user_context() - nbr_records = self.model.search_count(domain or [], context=context) + nbr_records = self.model.search_count(domain, context=context) offset = random.randint(0, nbr_records % 80) if nbr_records > 80 else 0 - ids = self.model.search(domain or [], limit=80, offset=offset, context=context) + ids = self.model.search(domain, limit=80, offset=offset, context=context) if ids: - self.model.read(random.choice(ids), self.form_fields, context=context) + self.random_id = random.choice(ids) + if self.random_id: + self.model.read(self.random_id, self.form_fields, context=context) @task(10) def list_view(self): - domain = [] - if self.filters and random.randint(0, 10) < 3: - domain = random.choice(self.filters) + domain = self._get_search_domain() context = self.client.get_user_context() - nbr_records = self.model.search_count(domain or [], context=context) - ids = self.model.search(domain or [], limit=80) + nbr_records = self.model.search_count(domain, context=context) if nbr_records > 80: offset = random.randint(0, nbr_records % 80) - ids = self.model.search(domain or [], limit=80, offset=offset, context=context) + self.model.search(domain, limit=80) + ids = self.model.search(domain, limit=80, offset=offset, context=context) + self.model.read(ids, self.list_fields, context=context) if ids: - self.model.search_read([('id', 'in', ids)], self.list_fields, context=context) + self.model.search_read(domain, self.list_fields, context=context) @task(10) def kanban_view(self): - if "kanban" in self.last_action.get('view_mode', []): - domain = [] - if self.filters and random.randint(0, 10) < 3: - domain = random.choice(self.filters) + if self.kanban_fields: + domain = self._get_search_domain() context = self.client.get_user_context() - nbr_records = self.model.search_count(domain or [], context=context) - ids = self.model.search(domain or [], limit=80) + nbr_records = self.model.search_count(domain, context=context) if nbr_records > 80: offset = random.randint(0, nbr_records % 80) - ids = self.model.search(domain or [], limit=80, offset=offset, context=context) + self.model.search(domain, limit=80, context=context) + ids = self.model.search(domain, limit=80, offset=offset, context=context) + self.model.read(ids, self.kanban_fields, context=context) if ids: - self.model.search_read([('id', 'in', ids)], self.kanban_fields, context=context) + self.model.search_read(domain, self.kanban_fields, context=context) diff --git a/src/OdooLocust/crm/lead.py b/src/OdooLocust/crm/lead.py index d330132..b70f424 100644 --- a/src/OdooLocust/crm/lead.py +++ b/src/OdooLocust/crm/lead.py @@ -34,8 +34,8 @@ import names import random + class CrmLead(OdooTaskSet): - random_id = -1 model_name = 'crm.lead' model = False @@ -48,8 +48,10 @@ def on_start(self): def _get_search_domain(self): if self.filters and random.randint(0, 10) < 3: return random.choice(self.filters) - name = names.get_first_name() - return ['|', '|', '|', ('partner_name', 'ilike', name), ('email_from', 'ilike', name), ('contact_name', 'ilike', name), ('name', 'ilike', name)] + if random.randint(0, 10) < 6: + name = names.get_first_name() + return ['|', '|', '|', ('partner_name', 'ilike', name), ('email_from', 'ilike', name), ('contact_name', 'ilike', name), ('name', 'ilike', name)] + return super()._get_search_domain() @task(10) def test_searchread(self): diff --git a/src/OdooLocust/crm/partner.py b/src/OdooLocust/crm/partner.py index cc081ed..7267d65 100644 --- a/src/OdooLocust/crm/partner.py +++ b/src/OdooLocust/crm/partner.py @@ -26,16 +26,21 @@ # ############################################################################## -from ..OdooTaskSet import OdooTaskSet -from locust import task +import random import names +from locust import task + +from ..OdooTaskSet import OdooGenericTaskSet -class ResPartner(OdooTaskSet): +class ResPartner(OdooGenericTaskSet): + model_name = 'res.partner' - @task(10) - def test_search(self): - partner_model = self.client.get_model('res.partner') - partner_model.search([('name', 'ilike', names.get_first_name())], context=self.client.get_user_context()) + @task(2) + def random_partner_modification(self): + domain = [('user_ids', '=', False)] + prtn_cnt = self.model.search_count(domain) + self.random_id = self.model.search(domain, offset=random.randint(0, prtn_cnt), limit=1) + self.model.write(self.random_id, {'name': names.get_full_name()}) diff --git a/src/OdooLocust/crm/quotation.py b/src/OdooLocust/crm/quotation.py index 3835e02..98cedbf 100644 --- a/src/OdooLocust/crm/quotation.py +++ b/src/OdooLocust/crm/quotation.py @@ -34,7 +34,6 @@ class SaleOrder(OdooTaskSet): line_fields = [] - random_id = -1 model_name = 'sale.order' def on_start(self): @@ -47,8 +46,10 @@ def on_start(self): def _get_search_domain(self): if self.filters and random.randint(0, 10) < 3: return random.choice(self.filters) - name = names.get_first_name() - return ["|", "|", ["name", "ilike", name], ["client_order_ref", "ilike", name], ["partner_id", "child_of", name]] + if random.randint(0, 10) < 6: + name = names.get_first_name() + return ["|", "|", ["name", "ilike", name], ["client_order_ref", "ilike", name], ["partner_id", "child_of", name]] + return super()._get_search_domain() @task def test_list(self): @@ -108,11 +109,13 @@ def new_quotation(self): prod_cnt = prod_model.search_count([('sale_ok', '=', True)]) prtn_id = prtn_model.search([], offset=random.randint(0, prtn_cnt), limit=1) - prod_id = prod_model.search([('sale_ok', '=', True)], offset=random.randint(0, prod_cnt), limit=1) + + so_lines = [] + for i in range(0, random.randint(1, 10)): + prod_id = prod_model.search([('sale_ok', '=', True)], offset=random.randint(0, prod_cnt), limit=1) + so_lines.append((0, 0, {'product_id': prod_id[0], })) self.random_id = self.model.create({ 'partner_id': prtn_id[0], - 'order_line': [(0, 0, { - 'product_id': prod_id[0], - })] + 'order_line': so_lines, })