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.2 KiB

6 years ago
6 years ago
  1. # Copyright 2014 Nemry Jonathan (Acsone SA/NV) (http://www.acsone.eu)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests.common import TransactionCase
  4. from .. import exceptions as ex
  5. class MailInstalled:
  6. def mail_installed(self):
  7. """Check if ``mail`` module is installed.``"""
  8. return (
  9. self.env["ir.module.module"].search([("name", "=", "mail")]).state
  10. == "installed"
  11. )
  12. class BaseCase(TransactionCase, MailInstalled):
  13. def setUp(self):
  14. super(BaseCase, self).setUp()
  15. self.check_fields = True
  16. self.expect("Núñez", "Fernán")
  17. self.create_original()
  18. def create_original(self):
  19. self.original = self.env["res.partner"].create(
  20. {"firstname": self.firstname, "lastname": self.lastname}
  21. )
  22. def expect(self, lastname, firstname, name=None):
  23. """Define what is expected in each field when ending."""
  24. self.lastname = lastname
  25. self.firstname = firstname
  26. self.name = name or "{} {}".format(firstname, lastname)
  27. def tearDown(self):
  28. if self.check_fields:
  29. if not hasattr(self, "changed"):
  30. self.changed = self.original
  31. for field in ("name", "lastname", "firstname"):
  32. self.assertEqual(
  33. self.changed[field],
  34. getattr(self, field),
  35. "Test failed with wrong %s" % field,
  36. )
  37. super(BaseCase, self).tearDown()
  38. def test_copy(self):
  39. """Copy the partner and compare the result."""
  40. self.expect("%s (copy)" % self.lastname, self.firstname)
  41. self.changed = self.original.with_context(copy=True, lang="en_US").copy()
  42. def test_one_name(self):
  43. """Test what happens when only one name is given."""
  44. name = "Mönty"
  45. self.expect(name, False, name)
  46. self.original.name = name
  47. def test_no_names(self):
  48. """Test that you cannot set a partner/user without names."""
  49. self.check_fields = False
  50. with self.assertRaises(ex.EmptyNamesError):
  51. self.original.firstname = self.original.lastname = False