[REF] account: centralize user creation in tests

X-original-commit: 84ffefed6deed59abb4df8627d5e3ebf970974b6
Part-of: odoo/odoo#125950
This commit is contained in:
Brice bib Bartoletti
2023-06-21 20:10:29 +02:00
parent b8a00bf9d4
commit 4e644746e9
2 changed files with 25 additions and 34 deletions
+22 -21
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, Command
from odoo.tests.common import TransactionCase, HttpCase, tagged, Form
from odoo.tests.common import TransactionCase, HttpCase, Form
import json
import time
@@ -10,6 +10,24 @@ from lxml import etree
from unittest import SkipTest
def instantiate_accountman(cls):
cls.user = cls.env['res.users'].create({
'name': 'Because I am accountman!',
'login': 'accountman',
'password': 'accountman',
'groups_id': [
Command.set(cls.env.user.groups_id.ids),
Command.link(cls.env.ref('account.group_account_manager').id),
Command.link(cls.env.ref('account.group_account_user').id),
],
})
cls.user.partner_id.email = 'accountman@test.com'
# Shadow the current environment/cursor with one having the report user.
# This is mandatory to test access rights.
cls.env = cls.env(user=cls.user)
cls.cr = cls.env.cr
class AccountTestInvoicingCommon(TransactionCase):
@classmethod
@@ -28,7 +46,8 @@ class AccountTestInvoicingCommon(TransactionCase):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super(AccountTestInvoicingCommon, cls).setUpClass()
super().setUpClass()
instantiate_accountman(cls)
assert 'post_install' in cls.test_tags, 'This test requires a CoA to be installed, it should be tagged "post_install"'
@@ -38,28 +57,10 @@ class AccountTestInvoicingCommon(TransactionCase):
if template_module.state != 'installed':
raise SkipTest(f"Module required for the test is not installed ({template_module.name})")
# Create user.
user = cls.env['res.users'].create({
'name': 'Because I am accountman!',
'login': 'accountman',
'password': 'accountman',
'groups_id': [
(6, 0, cls.env.user.groups_id.ids),
(4, cls.env.ref('account.group_account_manager').id),
(4, cls.env.ref('account.group_account_user').id),
],
})
user.partner_id.email = 'accountman@test.com'
# Shadow the current environment/cursor with one having the report user.
# This is mandatory to test access rights.
cls.env = cls.env(user=user)
cls.cr = cls.env.cr
cls.company_data_2 = cls.setup_company_data('company_2_data', chart_template=chart_template_ref)
cls.company_data = cls.setup_company_data('company_1_data', chart_template=chart_template_ref)
user.write({
cls.user.write({
'company_ids': [Command.set((cls.company_data['company'] + cls.company_data_2['company']).ids)],
'company_id': cls.company_data['company'].id,
})
+3 -13
View File
@@ -2,6 +2,7 @@ from unittest.mock import patch
from odoo import Command
from odoo.addons.account.models.chart_template import AccountChartTemplate
from odoo.addons.account.tests.common import instantiate_accountman
from odoo.tests import tagged
from odoo.tests.common import TransactionCase
@@ -104,25 +105,14 @@ class TestChartTemplate(TransactionCase):
We need to add xml_ids to the templates because they are loaded from their xml_ids
"""
super().setUpClass()
# Create user.
user = cls.env['res.users'].create({
'name': 'Because I am accountman!',
'login': 'accountman',
'password': 'accountman',
'groups_id': [Command.set(cls.env.user.groups_id.ids), Command.link(cls.env.ref('account.group_account_user').id)],
})
user.partner_id.email = 'accountman@test.com'
instantiate_accountman(cls)
cls.company_1 = cls.env['res.company'].create({
'name': 'TestCompany1',
'country_id': cls.env.ref('base.be').id,
})
cls.env = cls.env(user=user)
cls.cr = cls.env.cr
user.write({
cls.user.write({
'company_ids': [Command.set(cls.company_1.ids)],
'company_id': cls.company_1.id,
})