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