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.

53 lines
2.0 KiB

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