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.

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