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.

52 lines
1.9 KiB

6 years ago
6 years ago
  1. # Copyright 2016 Yannick Vaucher (Camptocamp SA)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.tests.common import TransactionCase
  4. class UserOnchangeCase(TransactionCase):
  5. def test_create_from_form_only_firstname(self):
  6. """In a new users form, a user set only the firstname."""
  7. firstname = "Zoë"
  8. with self.env.do_in_onchange():
  9. # Changes firstname, which triggers onchanges
  10. self.user.firstname = firstname
  11. self.user._compute_name()
  12. self.assertEqual(self.user.lastname, False)
  13. self.assertEqual(self.user.firstname, firstname)
  14. self.assertEqual(self.user.name, firstname)
  15. def test_create_from_form_only_lastname(self):
  16. """In a new user form, a user set only the lastname."""
  17. lastname = "Żywioł"
  18. with self.env.do_in_onchange():
  19. # Changes lastname, which triggers onchanges
  20. self.user.lastname = lastname
  21. self.user._compute_name()
  22. self.assertEqual(self.user.firstname, False)
  23. self.assertEqual(self.user.lastname, lastname)
  24. self.assertEqual(self.user.name, lastname)
  25. def test_create_from_form_all(self):
  26. """In a new user form, a user set all names."""
  27. firstname = "Zoë"
  28. lastname = "Żywioł"
  29. with self.env.do_in_onchange():
  30. # Changes firstname, which triggers onchanges
  31. self.user.firstname = firstname
  32. self.user._compute_name()
  33. # Changes lastname, which triggers onchanges
  34. self.user.lastname = lastname
  35. self.user._compute_name()
  36. self.assertEqual(self.user.lastname, lastname)
  37. self.assertEqual(self.user.firstname, firstname)
  38. self.assertEqual(self.user.name, " ".join((firstname, lastname)))
  39. def setUp(self):
  40. super(UserOnchangeCase, self).setUp()
  41. self.user = self.env["res.users"].new()