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.

88 lines
3.3 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 PartnerFirstnameCase(TransactionCase):
  29. def setUp(self):
  30. super(PartnerFirstnameCase, self).setUp()
  31. self.check_fields = True
  32. self.create_original()
  33. def create_original(self):
  34. self.original = self.env["res.partner"].create({
  35. "lastname": "lastname",
  36. "firstname": "firstname"})
  37. def expect(self, lastname, firstname, name=None):
  38. """Define what is expected in each field when ending."""
  39. self.lastname = lastname
  40. self.firstname = firstname
  41. self.name = name or "%s %s" % (lastname, firstname)
  42. def tearDown(self):
  43. if self.check_fields:
  44. if not hasattr(self, "changed"):
  45. self.changed = self.original
  46. for field in ("name", "lastname", "firstname"):
  47. self.assertEqual(
  48. getattr(self.changed, field),
  49. getattr(self, field),
  50. "Test failed with wrong %s" % field)
  51. super(PartnerFirstnameCase, self).tearDown()
  52. def test_copy(self):
  53. """Copy the partner and compare the result."""
  54. self.expect("lastname", "firstname (copy)")
  55. self.changed = self.original.with_context(lang="en_US").copy()
  56. def test_update_lastname(self):
  57. """Change lastname."""
  58. self.expect("newlastname", "firstname")
  59. self.original.name = self.name
  60. def test_update_firstname(self):
  61. """Change firstname."""
  62. self.expect("lastname", "newfirstname")
  63. self.original.name = self.name
  64. def test_no_names(self):
  65. """Test that you cannot set a partner/user without names."""
  66. self.check_fields = False
  67. with self.assertRaises(ex.EmptyNamesError):
  68. self.original.firstname = self.original.lastname = False
  69. class UserFirstnameCase(PartnerFirstnameCase):
  70. def create_original(self):
  71. self.original = self.env["res.users"].create({
  72. "name": "lastname firstname",
  73. "login": "firstnametest@example.com"})