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.

53 lines
1.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2014-2015 Grupo ESOC <www.grupoesoc.es>
  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 openerp.tests.common import TransactionCase
  8. from .base import MailInstalled
  9. from .. import exceptions as ex
  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. with self.assertRaises(ex.EmptyNamesError):
  18. self.env[self.model].with_context(**self.context).create(data)
  19. finally:
  20. super(CompanyCase, self).tearDown()
  21. def test_name_empty_string(self):
  22. """Test what happens when the name is an empty string."""
  23. self.name = ""
  24. def test_name_false(self):
  25. """Test what happens when the name is ``False``."""
  26. self.name = False
  27. class PersonCase(CompanyCase):
  28. """Test ``res.partner`` when it is a person."""
  29. context = {"default_is_company": False}
  30. class UserCase(CompanyCase, MailInstalled):
  31. """Test ``res.users``."""
  32. model = "res.users"
  33. context = {"default_login": "user@example.com"}
  34. def tearDown(self):
  35. # Cannot create users if ``mail`` is installed
  36. if self.mail_installed():
  37. # Skip tests
  38. super(CompanyCase, self).tearDown()
  39. else:
  40. # Run tests
  41. super(UserCase, self).tearDown()