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.

102 lines
3.5 KiB

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