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.

104 lines
3.6 KiB

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