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.

74 lines
2.4 KiB

6 years ago
6 years ago
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 (self.env["ir.module.module"]
  9. .search([("name", "=", "mail")])
  10. .state == "installed")
  11. class BaseCase(TransactionCase, MailInstalled):
  12. def setUp(self):
  13. super(BaseCase, self).setUp()
  14. self.check_fields = True
  15. self.expect("Núñez", "Fernán")
  16. self.create_original()
  17. def create_original(self):
  18. self.original = self.env["res.partner"].create({
  19. "firstname": self.firstname,
  20. "lastname": self.lastname})
  21. def expect(self, lastname, firstname, name=None):
  22. """Define what is expected in each field when ending."""
  23. self.lastname = lastname
  24. self.firstname = firstname
  25. self.name = name or "%s %s" % (firstname, lastname)
  26. def tearDown(self):
  27. if self.check_fields:
  28. if not hasattr(self, "changed"):
  29. self.changed = self.original
  30. for field in ("name", "lastname", "firstname"):
  31. self.assertEqual(
  32. getattr(self.changed, field),
  33. getattr(self, field),
  34. "Test failed with wrong %s" % field)
  35. super(BaseCase, self).tearDown()
  36. def test_copy(self):
  37. """Copy the partner and compare the result."""
  38. self.expect("%s (copy)" % self.lastname, self.firstname)
  39. self.changed = (self.original.with_context(copy=True, lang="en_US")
  40. .copy())
  41. def test_one_name(self):
  42. """Test what happens when only one name is given."""
  43. name = "Mönty"
  44. self.expect(name, False, name)
  45. self.original.name = name
  46. def test_no_names(self):
  47. """Test that you cannot set a partner/user without names."""
  48. self.check_fields = False
  49. with self.assertRaises(ex.EmptyNamesError):
  50. self.original.firstname = self.original.lastname = False
  51. class OnChangeCase(TransactionCase):
  52. is_company = False
  53. def new_partner(self):
  54. """Create an empty partner. Ensure it is (or not) a company."""
  55. new = self.env["res.partner"].new()
  56. new.is_company = self.is_company
  57. return new