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.

78 lines
2.9 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 BaseCase(TransactionCase):
  29. def setUp(self):
  30. super(BaseCase, self).setUp()
  31. self.check_fields = True
  32. self.expect(u"Núñez", u"Fernán")
  33. self.create_original()
  34. def create_original(self):
  35. self.original = self.env["res.partner"].create({
  36. "lastname": self.lastname,
  37. "firstname": self.firstname})
  38. def expect(self, lastname, firstname, name=None):
  39. """Define what is expected in each field when ending."""
  40. self.lastname = lastname
  41. self.firstname = firstname
  42. self.name = name or u"%s %s" % (lastname, firstname)
  43. def tearDown(self):
  44. if self.check_fields:
  45. if not hasattr(self, "changed"):
  46. self.changed = self.original
  47. for field in ("name", "lastname", "firstname"):
  48. self.assertEqual(
  49. getattr(self.changed, field),
  50. getattr(self, field),
  51. "Test failed with wrong %s" % field)
  52. super(BaseCase, self).tearDown()
  53. def test_copy(self):
  54. """Copy the partner and compare the result."""
  55. self.expect(self.lastname, u"%s (copy)" % self.firstname)
  56. self.changed = self.original.with_context(lang="en_US").copy()
  57. def test_one_name(self):
  58. """Test what happens when only one name is given."""
  59. name = u"Mönty"
  60. self.expect(name, False, name)
  61. self.original.name = name
  62. def test_no_names(self):
  63. """Test that you cannot set a partner/user without names."""
  64. self.check_fields = False
  65. with self.assertRaises(ex.EmptyNamesError):
  66. self.original.firstname = self.original.lastname = False