partner-contact/partner_firstname/tests/test_copy.py

96 lines
3.1 KiB
Python
Raw Permalink Normal View History

2024-05-03 08:58:43 +00:00
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
"""Test copy function for models."""
from flectra.tests.common import TransactionCase
from .base import MailInstalled
class UserCase(TransactionCase, MailInstalled):
"""Test ``res.users``."""
def setUp(self):
super().setUp()
self.create_original()
2024-10-01 05:51:46 +00:00
self.create_original_multinames()
2024-05-03 08:58:43 +00:00
def create_original(self):
self.original = self.env["res.users"].create(
{
"firstname": "Firstname",
"lastname": "Lastname",
"name": "Firstname Lastname",
"login": "firstname.lastname",
}
)
2024-10-01 05:51:46 +00:00
def create_original_multinames(self):
self.original_multinames = (
self.env["res.users"]
.with_context(no_reset_password=True)
.create(
{
"firstname": "Firstname1 Firstname2",
"lastname": "Lastname1 Lastname2",
"name": "Firstname1 Firstname2 Lastname1 Lastname2 (copy)",
"login": "firstname.multi",
}
)
)
2024-05-03 08:58:43 +00:00
def tearDown(self):
super().tearDown()
def compare(self, copy):
self.assertEqual(copy.lastname, "Lastname2")
self.assertEqual(copy.firstname, "Firstname2")
self.assertEqual(copy.name, "Firstname2 Lastname2")
def test_copy_name(self):
"""Copy original with default name set - firstname lastname not set."""
copy = self.original.copy({"name": "Firstname2 Lastname2"})
self.compare(copy)
def test_copy_firstname_lastname(self):
"""Copy original with default firstname and lastname set"""
copy = self.original.copy({"firstname": "Firstname2", "lastname": "Lastname2"})
self.compare(copy)
def test_copy_firstname_lastname_name(self):
"""Copy original with default firstname, lastname and name set"""
copy = self.original.copy(
{
"firstname": "Firstname2",
"lastname": "Lastname2",
"name": "Firstname2 Lastname2",
}
)
self.compare(copy)
2024-10-01 05:51:46 +00:00
def test_copy_multiple_names(self):
copy = self.original_multinames.partner_id.copy()
self.assertRecordValues(
copy,
[
{
"firstname": "Firstname1 Firstname2",
"lastname": "Lastname1 Lastname2 (copy)",
"name": "Firstname1 Firstname2 Lastname1 Lastname2 (copy)",
}
],
)
def test_copy_multiple_names_company(self):
partner = self.original_multinames.partner_id
partner.is_company = True
copy = partner.copy()
self.assertRecordValues(
copy,
[
{
"firstname": False,
"lastname": "Firstname1 Firstname2 Lastname1 Lastname2 (copy)",
"name": "Firstname1 Firstname2 Lastname1 Lastname2 (copy)",
}
],
)