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.

68 lines
2.3 KiB

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.changed = self.original.with_context(lang="en_US").copy()
  41. if self.changed.is_company:
  42. self.expect("%s (copy)" % self.lastname, self.firstname)
  43. else:
  44. self.expect(self.lastname, "%s (copy)" % self.firstname)
  45. def test_one_name(self):
  46. """Test what happens when only one name is given."""
  47. name = "Mönty"
  48. self.expect(name, False, name)
  49. self.original.name = name
  50. def test_no_names(self):
  51. """Test that you cannot set a partner/user without names."""
  52. self.check_fields = False
  53. with self.assertRaises(ex.EmptyNamesError):
  54. self.original.firstname = self.original.lastname = False