You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.5 KiB

6 years ago
  1. # Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L. - Jairo Llopis.
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. """Test default values for models."""
  4. from odoo.tests.common import TransactionCase
  5. from .base import MailInstalled
  6. class PersonCase(TransactionCase):
  7. """Test ``res.partner`` when it is a person."""
  8. context = {"default_is_company": False}
  9. model = "res.partner"
  10. def setUp(self):
  11. super(PersonCase, self).setUp()
  12. self.good_values = {"firstname": "Núñez", "lastname": "Fernán"}
  13. self.good_values["name"] = "{} {}".format(
  14. self.good_values["firstname"], self.good_values["lastname"]
  15. )
  16. if "default_is_company" in self.context:
  17. self.good_values["is_company"] = self.context["default_is_company"]
  18. self.values = self.good_values.copy()
  19. def tearDown(self):
  20. self.record = (
  21. self.env[self.model].with_context(self.context).create(self.values)
  22. )
  23. for key, value in self.good_values.items():
  24. self.assertEqual(self.record[key], value, "Checking key %s" % key)
  25. super(PersonCase, self).tearDown()
  26. def test_no_name(self):
  27. """Name is calculated."""
  28. del self.values["name"]
  29. def test_wrong_name_value(self):
  30. """Wrong name value is ignored, name is calculated."""
  31. self.values["name"] = "BÄD"
  32. def test_wrong_name_context(self):
  33. """Wrong name context is ignored, name is calculated."""
  34. del self.values["name"]
  35. self.context["default_name"] = "BÄD"
  36. def test_wrong_name_value_and_context(self):
  37. """Wrong name value and context is ignored, name is calculated."""
  38. self.values["name"] = "BÄD1"
  39. self.context["default_name"] = "BÄD2"
  40. class CompanyCase(PersonCase):
  41. """Test ``res.partner`` when it is a company."""
  42. context = {"default_is_company": True}
  43. def setUp(self):
  44. super(CompanyCase, self).setUp()
  45. self.good_values.update(lastname=self.values["name"], firstname=False)
  46. self.values = self.good_values.copy()
  47. class UserCase(PersonCase, MailInstalled):
  48. """Test ``res.users``."""
  49. model = "res.users"
  50. context = {"default_login": "user@example.com"}
  51. def tearDown(self):
  52. # Cannot create users if ``mail`` is installed
  53. if self.mail_installed():
  54. # Skip tests
  55. super(PersonCase, self).tearDown()
  56. else:
  57. # Run tests
  58. super(UserCase, self).tearDown()