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.

96 lines
3.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Authors: Nemry Jonathan
  3. # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
  4. # All Rights Reserved
  5. #
  6. # WARNING: This program as such is intended to be used by professional
  7. # programmers who take the whole responsibility of assessing all potential
  8. # consequences resulting from its eventual inadequacies and bugs.
  9. # End users who are looking for a ready-to-use solution with commercial
  10. # guarantees and support are strongly advised to contact a Free Software
  11. # Service Company.
  12. #
  13. # This program is Free Software; you can redistribute it and/or
  14. # modify it under the terms of the GNU General Public License
  15. # as published by the Free Software Foundation; either version 2
  16. # of the License, or (at your option) any later version.
  17. #
  18. # This program is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. # GNU General Public License for more details.
  22. #
  23. # You should have received a copy of the GNU General Public License
  24. # along with this program; if not, write to the Free Software
  25. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  26. from openerp.tests.common import TransactionCase
  27. from .. import exceptions as ex
  28. class MailInstalled():
  29. def mail_installed(self):
  30. """Check if ``mail`` module is installed.``"""
  31. return (self.env["ir.module.module"]
  32. .search([("name", "=", "mail")])
  33. .state == "installed")
  34. class BaseCase(TransactionCase, MailInstalled):
  35. def setUp(self):
  36. super(BaseCase, self).setUp()
  37. self.check_fields = True
  38. self.expect(u"Núñez", u"Fernán")
  39. self.create_original()
  40. def create_original(self):
  41. self.original = self.env["res.partner"].create({
  42. "lastname": self.lastname,
  43. "firstname": self.firstname})
  44. def expect(self, lastname, firstname, name=None):
  45. """Define what is expected in each field when ending."""
  46. self.lastname = lastname
  47. self.firstname = firstname
  48. self.name = name or u"%s %s" % (lastname, firstname)
  49. def tearDown(self):
  50. if self.check_fields:
  51. if not hasattr(self, "changed"):
  52. self.changed = self.original
  53. for field in ("name", "lastname", "firstname"):
  54. self.assertEqual(
  55. getattr(self.changed, field),
  56. getattr(self, field),
  57. "Test failed with wrong %s" % field)
  58. super(BaseCase, self).tearDown()
  59. def test_copy(self):
  60. """Copy the partner and compare the result."""
  61. self.expect(self.lastname, u"%s (copy)" % self.firstname)
  62. self.changed = self.original.with_context(lang="en_US").copy()
  63. def test_one_name(self):
  64. """Test what happens when only one name is given."""
  65. name = u"Mönty"
  66. self.expect(name, False, name)
  67. self.original.name = name
  68. def test_no_names(self):
  69. """Test that you cannot set a partner/user without names."""
  70. self.check_fields = False
  71. with self.assertRaises(ex.EmptyNamesError):
  72. self.original.firstname = self.original.lastname = False
  73. class OnChangeCase(TransactionCase):
  74. is_company = False
  75. def new_partner(self):
  76. """Create an empty partner. Ensure it is (or not) a company."""
  77. new = self.env["res.partner"].new()
  78. new.is_company = self.is_company
  79. return new