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.

105 lines
3.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Grupo ESOC <www.grupoesoc.es>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. """These tests try to mimic the behavior of the UI form.
  5. The form operates in onchange mode, with its limitations.
  6. """
  7. from .base import OnChangeCase
  8. class PartnerCompanyCase(OnChangeCase):
  9. is_company = True
  10. def test_create_from_form(self):
  11. """A user creates a company from the form."""
  12. name = "Sôme company"
  13. with self.env.do_in_onchange():
  14. # User presses ``new``
  15. partner = self.new_partner()
  16. # User sets a name, which triggers onchanges
  17. partner.name = name
  18. partner._onchange_name()
  19. self.assertEqual(partner.name, name)
  20. self.assertEqual(partner.firstname, False)
  21. self.assertEqual(partner.lastname, name)
  22. def test_empty_name_and_subnames(self):
  23. """If the user empties ``name``, subnames must be ``False``.
  24. Otherwise, the ``required`` attr will not work as expected.
  25. """
  26. with self.env.do_in_onchange():
  27. # User presses ``new``
  28. partner = self.new_partner()
  29. # User sets a name, which triggers onchanges
  30. partner.name = "Foó"
  31. partner._onchange_name()
  32. # User unsets name, which triggers onchanges
  33. partner.name = ""
  34. partner._onchange_name()
  35. self.assertEqual(partner.firstname, False)
  36. self.assertEqual(partner.lastname, False)
  37. class PartnerContactCase(OnChangeCase):
  38. def test_create_from_form_only_firstname(self):
  39. """A user creates a contact with only the firstname from the form."""
  40. firstname = "Fïrst"
  41. with self.env.do_in_onchange():
  42. # User presses ``new``
  43. partner = self.new_partner()
  44. # Changes firstname, which triggers onchanges
  45. partner.firstname = firstname
  46. partner._onchange_subnames()
  47. partner._onchange_name()
  48. self.assertEqual(partner.lastname, False)
  49. self.assertEqual(partner.firstname, firstname)
  50. self.assertEqual(partner.name, firstname)
  51. def test_create_from_form_only_lastname(self):
  52. """A user creates a contact with only the lastname from the form."""
  53. lastname = "Läst"
  54. with self.env.do_in_onchange():
  55. # User presses ``new``
  56. partner = self.new_partner()
  57. # Changes lastname, which triggers onchanges
  58. partner.lastname = lastname
  59. partner._onchange_subnames()
  60. partner._onchange_name()
  61. self.assertEqual(partner.firstname, False)
  62. self.assertEqual(partner.lastname, lastname)
  63. self.assertEqual(partner.name, lastname)
  64. def test_create_from_form_all(self):
  65. """A user creates a contact with all names from the form."""
  66. firstname = "Fïrst"
  67. lastname = "Läst"
  68. with self.env.do_in_onchange():
  69. # User presses ``new``
  70. partner = self.new_partner()
  71. # Changes firstname, which triggers onchanges
  72. partner.firstname = firstname
  73. partner._onchange_subnames()
  74. partner._onchange_name()
  75. # Changes lastname, which triggers onchanges
  76. partner.lastname = lastname
  77. partner._onchange_subnames()
  78. partner._onchange_name()
  79. self.assertEqual(partner.lastname, lastname)
  80. self.assertEqual(partner.firstname, firstname)
  81. self.assertEqual(partner.name, " ".join((lastname, firstname)))