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.

154 lines
5.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 PartnerFirstnameCase(TransactionCase):
  29. def setUp(self):
  30. super(PartnerFirstnameCase, self).setUp()
  31. self.original = self.env["res.partner"].create({
  32. "lastname": "lastname",
  33. "firstname": "firstname"})
  34. def test_copy_partner(self):
  35. """Copy the partner and compare the result."""
  36. copy = self.original.with_context(lang="en_US").copy()
  37. self.assertEqual(
  38. copy.name,
  39. "lastname firstname (copy)",
  40. "Copy of the partner failed with wrong name")
  41. self.assertEqual(
  42. copy.lastname,
  43. "lastname",
  44. "Copy of the partner failed with wrong lastname")
  45. self.assertEqual(
  46. copy.firstname,
  47. "firstname (copy)",
  48. "Copy of the partner failed with wrong firstname")
  49. def test_update_user_lastname(self):
  50. """Change lastname."""
  51. self.original.name = "changed firstname"
  52. self.assertEqual(
  53. self.original.name,
  54. "changed firstname",
  55. "Update of the partner lastname failed with wrong name")
  56. self.assertEqual(
  57. self.original.lastname,
  58. "changed",
  59. "Update of the partner lastname failed with wrong lastname")
  60. self.assertEqual(
  61. self.original.firstname,
  62. "firstname",
  63. "Update of the partner lastname failed with wrong firstname")
  64. def test_update_user_firstname(self):
  65. """Change firstname."""
  66. self.original.name = "lastname changed"
  67. self.assertEqual(
  68. self.original.name,
  69. "lastname changed",
  70. "Update of the partner lastname failed with wrong name")
  71. self.assertEqual(
  72. self.original.lastname,
  73. "lastname",
  74. "Update of the partner lastname failed with wrong lastname")
  75. self.assertEqual(
  76. self.original.firstname,
  77. "changed",
  78. "Update of the partner lastname failed with wrong firstname")
  79. def test_no_names(self):
  80. """Test that you cannot set a partner without names."""
  81. with self.assertRaises(ex.EmptyNames):
  82. self.original.firstname = self.original.lastname = False
  83. class UserFirstnameCase(TransactionCase):
  84. def setUp(self):
  85. super(UserFirstnameCase, self).setUp()
  86. self.original = self.env["res.users"].create({
  87. "name": "lastname firstname",
  88. "login": "firstnametest@example.com"})
  89. def test_copy_user(self):
  90. """Copy the user and compare result."""
  91. copy = self.original.with_context(lang="en_US").copy()
  92. self.assertEqual(
  93. copy.name,
  94. "lastname firstname (copy)",
  95. "Copy of the partner failed with wrong name")
  96. self.assertEqual(
  97. copy.lastname,
  98. "lastname",
  99. "Copy of the partner failed with wrong lastname")
  100. self.assertEqual(
  101. copy.firstname,
  102. "firstname (copy)",
  103. "Copy of the partner failed with wrong firstname")
  104. def test_update_user_lastname(self):
  105. """Change lastname."""
  106. self.original.name = "changed firstname"
  107. self.assertEqual(
  108. self.original.name,
  109. "changed firstname",
  110. "Update of the user lastname failed with wrong name")
  111. self.assertEqual(
  112. self.original.lastname,
  113. "changed",
  114. "Update of the user lastname failed with wrong lastname")
  115. self.assertEqual(
  116. self.original.firstname,
  117. "firstname",
  118. "Update of the user lastname failed with wrong firstname")
  119. def test_update_user_firstname(self):
  120. """Change firstname."""
  121. self.original.name = "lastname changed"
  122. self.assertEqual(
  123. self.original.name,
  124. "lastname changed",
  125. "Update of the user lastname failed with wrong name")
  126. self.assertEqual(
  127. self.original.lastname,
  128. "lastname",
  129. "Update of the user lastname failed with wrong lastname")
  130. self.assertEqual(
  131. self.original.firstname,
  132. "changed",
  133. "Update of the user lastname failed with wrong firstname")