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.

65 lines
2.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Grupo ESOC Ingeniería de Servicios, S.L. - Jairo Llopis.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. """Test default values for models."""
  5. from odoo.tests.common import TransactionCase
  6. from .base import MailInstalled
  7. class PersonCase(TransactionCase):
  8. """Test ``res.partner`` when it is a person."""
  9. context = {"default_is_company": False}
  10. model = "res.partner"
  11. def setUp(self):
  12. super(PersonCase, self).setUp()
  13. self.values = {
  14. "firstname": u"Núñez",
  15. "lastname": u"Fernán",
  16. }
  17. self.values["name"] = "%s %s" % (self.values["lastname"],
  18. self.values["firstname"])
  19. if "default_is_company" in self.context:
  20. self.values["is_company"] = self.context["default_is_company"]
  21. def tearDown(self):
  22. for key, value in self.values.iteritems():
  23. self.assertEqual(
  24. self.defaults.get(key),
  25. value,
  26. "Checking key %s" % key)
  27. return super(PersonCase, self).tearDown()
  28. def test_default_get(self):
  29. """Getting default values for fields includes new fields."""
  30. self.defaults = (self.env[self.model]
  31. .with_context(self.context,
  32. default_name=self.values["name"])
  33. .default_get(self.values.keys()))
  34. class CompanyCase(PersonCase):
  35. """Test ``res.partner`` when it is a company."""
  36. context = {"default_is_company": True}
  37. def tearDown(self):
  38. self.values.update(lastname=self.values["name"], firstname=False)
  39. return super(CompanyCase, self).tearDown()
  40. class UserCase(PersonCase, MailInstalled):
  41. """Test ``res.users``."""
  42. model = "res.users"
  43. context = {"default_login": "user@example.com"}
  44. def tearDown(self):
  45. # Cannot create users if ``mail`` is installed
  46. if self.mail_installed():
  47. # Skip tests
  48. super(PersonCase, self).tearDown()
  49. else:
  50. # Run tests
  51. super(UserCase, self).tearDown()