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.

80 lines
2.6 KiB

6 years ago
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 = {
  13. "firstname": "Núñez",
  14. "lastname": "Fernán",
  15. }
  16. self.good_values["name"] = "%s %s" % (self.good_values["firstname"],
  17. self.good_values["lastname"])
  18. if "default_is_company" in self.context:
  19. self.good_values["is_company"] = self.context["default_is_company"]
  20. self.values = self.good_values.copy()
  21. def tearDown(self):
  22. self.record = (self.env[self.model]
  23. .with_context(self.context)
  24. .create(self.values))
  25. for key, value in self.good_values.items():
  26. self.assertEqual(
  27. self.record[key],
  28. value,
  29. "Checking key %s" % key)
  30. super(PersonCase, self).tearDown()
  31. def test_no_name(self):
  32. """Name is calculated."""
  33. del self.values["name"]
  34. def test_wrong_name_value(self):
  35. """Wrong name value is ignored, name is calculated."""
  36. self.values["name"] = "BÄD"
  37. def test_wrong_name_context(self):
  38. """Wrong name context is ignored, name is calculated."""
  39. del self.values["name"]
  40. self.context["default_name"] = "BÄD"
  41. def test_wrong_name_value_and_context(self):
  42. """Wrong name value and context is ignored, name is calculated."""
  43. self.values["name"] = "BÄD1"
  44. self.context["default_name"] = "BÄD2"
  45. class CompanyCase(PersonCase):
  46. """Test ``res.partner`` when it is a company."""
  47. context = {"default_is_company": True}
  48. def setUp(self):
  49. super(CompanyCase, self).setUp()
  50. self.good_values.update(lastname=self.values["name"], firstname=False)
  51. self.values = self.good_values.copy()
  52. class UserCase(PersonCase, MailInstalled):
  53. """Test ``res.users``."""
  54. model = "res.users"
  55. context = {"default_login": "user@example.com"}
  56. def tearDown(self):
  57. # Cannot create users if ``mail`` is installed
  58. if self.mail_installed():
  59. # Skip tests
  60. super(PersonCase, self).tearDown()
  61. else:
  62. # Run tests
  63. super(UserCase, self).tearDown()