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

  1. # -*- coding: utf-8 -*-
  2. # © 2014 Nemry Jonathan (Acsone SA/NV) (http://www.acsone.eu)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests.common import TransactionCase
  5. from .. import exceptions as ex
  6. class MailInstalled():
  7. def mail_installed(self):
  8. """Check if ``mail`` module is installed.``"""
  9. return (self.env["ir.module.module"]
  10. .search([("name", "=", "mail")])
  11. .state == "installed")
  12. class BaseCase(TransactionCase, MailInstalled):
  13. def setUp(self):
  14. super(BaseCase, self).setUp()
  15. self.check_fields = True
  16. self.expect(u"Núñez", u"Fernán")
  17. self.create_original()
  18. def create_original(self):
  19. self.original = self.env["res.partner"].create({
  20. "lastname": self.lastname,
  21. "firstname": self.firstname})
  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 u"%s %s" % (lastname, firstname)
  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. getattr(self.changed, field),
  34. getattr(self, field),
  35. "Test failed with wrong %s" % field)
  36. super(BaseCase, self).tearDown()
  37. def test_copy(self):
  38. """Copy the partner and compare the result."""
  39. self.expect(self.lastname, u"%s (copy)" % self.firstname)
  40. self.changed = (self.original.with_context(copy=True, lang="en_US")
  41. .copy())
  42. def test_one_name(self):
  43. """Test what happens when only one name is given."""
  44. name = u"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
  52. class OnChangeCase(TransactionCase):
  53. is_company = False
  54. def new_partner(self):
  55. """Create an empty partner. Ensure it is (or not) a company."""
  56. new = self.env["res.partner"].new()
  57. new.is_company = self.is_company
  58. return new