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.

177 lines
5.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. # © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U.
  4. from openerp.tests.common import TransactionCase
  5. from openerp.addons.partner_firstname.tests.base import MailInstalled
  6. class CompanyCase(TransactionCase):
  7. """Test ``res.partner`` when it is a company."""
  8. def tearDown(self):
  9. try:
  10. new = self.env["res.partner"].create({
  11. "is_company": True,
  12. "name": self.name,
  13. })
  14. # Name should be cleaned of unneeded whitespace
  15. clean_name = u" ".join(self.name.split(None))
  16. # Check it's saved OK
  17. self.assertEqual(
  18. new.name,
  19. clean_name,
  20. "Saved company name is wrong.")
  21. # Check it's saved in the lastname
  22. self.assertEqual(
  23. new.lastname,
  24. clean_name,
  25. "Company name should be saved in the lastname field.")
  26. # Check that other fields are empty
  27. self.assertEqual(
  28. new.firstname,
  29. False,
  30. "Company first name must always be empty.")
  31. self.assertEqual(
  32. new.lastname2,
  33. False,
  34. "Company last name 2 must always be empty.")
  35. finally:
  36. super(CompanyCase, self).tearDown()
  37. def test_long_name(self):
  38. """Create a company with a long name."""
  39. self.name = u"Söme very lóng nâme"
  40. def test_short_name(self):
  41. """Create a company with a short name."""
  42. self.name = u"Shoŕt"
  43. def test_whitespace_before(self):
  44. """Create a company with name prefixed with whitespace."""
  45. self.name = u" Wĥitespace befòre"
  46. def test_whitespace_after(self):
  47. """Create a company with name suffixed with whitespace."""
  48. self.name = u"Whitespâce aftér "
  49. def test_whitespace_inside(self):
  50. """Create a company with whitespace inside the name."""
  51. self.name = u"Whitespacé ïnside"
  52. def test_whitespace_everywhere(self):
  53. """Create a company with whitespace everywhere in the name."""
  54. self.name = u" A lot öf whitespace "
  55. class PersonCase(TransactionCase):
  56. """Test ``res.partner`` when it is a person."""
  57. model = "res.partner"
  58. context = dict()
  59. def setUp(self):
  60. super(PersonCase, self).setUp()
  61. self.firstname = u"Fírstname"
  62. self.lastname = u"Làstname1"
  63. self.lastname2 = u"Lâstname2"
  64. self.template = u"%(last1)s %(last2)s, %(first)s"
  65. def tearDown(self):
  66. try:
  67. new = (self.env[self.model].with_context(self.context)
  68. .create(self.params))
  69. # Check that each individual field matches
  70. self.assertEqual(
  71. self.firstname,
  72. new.firstname,
  73. "First name saved badly.")
  74. self.assertEqual(
  75. self.lastname,
  76. new.lastname,
  77. "Last name 1 saved badly.")
  78. self.assertEqual(
  79. self.lastname2,
  80. new.lastname2,
  81. "Last name 2 saved badly.")
  82. # Check that name gets saved fine
  83. self.assertEqual(
  84. self.template % ({"last1": self.lastname,
  85. "last2": self.lastname2,
  86. "first": self.firstname}),
  87. new.name,
  88. "Name saved badly.")
  89. finally:
  90. super(PersonCase, self).tearDown()
  91. def test_firstname_first(self):
  92. """Create a person setting his first name first."""
  93. self.params = {
  94. "is_company": False,
  95. "name": "%s %s %s" % (self.firstname,
  96. self.lastname,
  97. self.lastname2),
  98. }
  99. def test_firstname_last(self):
  100. """Create a persong setting his first name last."""
  101. self.params = {
  102. "is_company": False,
  103. "name": "%s %s, %s" % (self.lastname,
  104. self.lastname2,
  105. self.firstname),
  106. }
  107. def test_firstname_only(self):
  108. """Create a persong setting his first name only."""
  109. self.lastname = self.lastname2 = False
  110. self.template = "%(first)s"
  111. self.params = {
  112. "is_company": False,
  113. "name": self.firstname,
  114. }
  115. def test_firstname_lastname_only(self):
  116. """Create a persong setting his first name and last name 1 only."""
  117. self.lastname2 = False
  118. self.template = "%(last1)s, %(first)s"
  119. self.params = {
  120. "is_company": False,
  121. "name": "%s %s" % (self.firstname, self.lastname),
  122. }
  123. def test_lastname_firstname_only(self):
  124. """Create a persong setting his last name 1 and first name only."""
  125. self.lastname2 = False
  126. self.template = "%(last1)s, %(first)s"
  127. self.params = {
  128. "is_company": False,
  129. "name": "%s, %s" % (self.lastname, self.firstname),
  130. }
  131. def test_separately(self):
  132. """Create a person setting separately all fields."""
  133. self.params = {
  134. "is_company": False,
  135. "firstname": self.firstname,
  136. "lastname": self.lastname,
  137. "lastname2": self.lastname2,
  138. }
  139. class UserCase(PersonCase, MailInstalled):
  140. """Test ``res.users``."""
  141. model = "res.users"
  142. context = {"default_login": "user@example.com"}
  143. def tearDown(self):
  144. # Skip if ``mail`` is installed
  145. if not self.mail_installed():
  146. super(UserCase, self).tearDown()