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

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