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.

73 lines
2.2 KiB

6 years ago
  1. # Copyright 2014-2015 Grupo ESOC <www.grupoesoc.es>
  2. # Copyright 2016 Yannick Vaucher (Camptocamp)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. """Test situations where names are empty.
  5. To have more accurate results, remove the ``mail`` module before testing.
  6. """
  7. from odoo.tests.common import TransactionCase
  8. from .. import exceptions as ex
  9. from .base import MailInstalled
  10. class CompanyCase(TransactionCase):
  11. """Test ``res.partner`` when it is a company."""
  12. model = "res.partner"
  13. context = {"default_is_company": True}
  14. def tearDown(self):
  15. try:
  16. data = {"name": self.name}
  17. model = self.env[self.model].with_context(**self.context)
  18. with self.assertRaises(ex.EmptyNamesError):
  19. model.create(data)
  20. finally:
  21. super(CompanyCase, self).tearDown()
  22. def test_name_empty_string(self):
  23. """Test what happens when the name is an empty string."""
  24. self.name = ""
  25. def test_name_false(self):
  26. """Test what happens when the name is ``False``."""
  27. self.name = False
  28. class PersonCase(CompanyCase):
  29. """Test ``res.partner`` when it is a person."""
  30. context = {"default_is_company": False, "default_type": "contact"}
  31. class UserCase(CompanyCase, MailInstalled):
  32. """Test ``res.users``."""
  33. model = "res.users"
  34. context = {"default_login": "user@example.com"}
  35. def tearDown(self):
  36. # Cannot create users if ``mail`` is installed
  37. if self.mail_installed():
  38. # Skip tests
  39. super(CompanyCase, self).tearDown()
  40. else:
  41. # Run tests
  42. super(UserCase, self).tearDown()
  43. class AddressCase(TransactionCase):
  44. """Test ``res.partner`` when it is a address."""
  45. def test_new_empty_invoice_address(self):
  46. """Create an invoice patner without name."""
  47. self.original = self.env["res.partner"].create(
  48. {"is_company": False, "type": "invoice", "lastname": "", "firstname": ""}
  49. )
  50. def test_new_empty_shipping_address(self):
  51. """Create an shipping patner without name."""
  52. self.original = self.env["res.partner"].create(
  53. {"is_company": False, "type": "delivery", "lastname": "", "firstname": ""}
  54. )