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.

64 lines
2.0 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.values = {"firstname": "Núñez", "lastname": "Fernán"}
  13. self.values["name"] = "{} {}".format(
  14. self.values["firstname"], self.values["lastname"]
  15. )
  16. if "default_is_company" in self.context:
  17. self.values["is_company"] = self.context["default_is_company"]
  18. def tearDown(self):
  19. for key, value in self.values.items():
  20. self.assertEqual(self.defaults.get(key), value, "Checking key %s" % key)
  21. return super(PersonCase, self).tearDown()
  22. def test_default_get(self):
  23. """Getting default values for fields includes new fields."""
  24. self.defaults = (
  25. self.env[self.model]
  26. .with_context(self.context, default_name=self.values["name"])
  27. .default_get(list(self.values.keys()))
  28. )
  29. class CompanyCase(PersonCase):
  30. """Test ``res.partner`` when it is a company."""
  31. context = {"default_is_company": True}
  32. def tearDown(self):
  33. self.values.update(lastname=self.values["name"], firstname=False)
  34. return super(CompanyCase, self).tearDown()
  35. class UserCase(PersonCase, MailInstalled):
  36. """Test ``res.users``."""
  37. model = "res.users"
  38. context = {"default_login": "user@example.com"}
  39. def tearDown(self):
  40. # Cannot create users if ``mail`` is installed
  41. if self.mail_installed():
  42. # Skip tests
  43. super(PersonCase, self).tearDown()
  44. else:
  45. # Run tests
  46. super(UserCase, self).tearDown()