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.

64 lines
2.5 KiB

  1. # Copyright 2016 Yannick Vaucher (Camptocamp SA)
  2. # Copyright 2020 Therp BV - https://therp.nl.
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  4. from odoo.tests.common import Form, 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. login = "Zoë"
  9. firstname = "Zoë"
  10. with self.get_clean_user_form() as user_form:
  11. user_form.login = login
  12. # Changes firstname, which triggers onchanges
  13. user_form.firstname = firstname
  14. self.assertEqual(user_form.lastname, False)
  15. self.assertEqual(user_form.firstname, firstname)
  16. self.assertEqual(user_form.name, firstname)
  17. def test_create_from_form_only_lastname(self):
  18. """In a new user form, a user set only the lastname."""
  19. login = "Żywioł"
  20. lastname = "Żywioł"
  21. with self.get_clean_user_form() as user_form:
  22. user_form.login = login
  23. # Changes lastname, which triggers onchanges
  24. user_form.lastname = lastname
  25. self.assertEqual(user_form.firstname, False)
  26. self.assertEqual(user_form.lastname, lastname)
  27. self.assertEqual(user_form.name, lastname)
  28. def test_create_from_form_all(self):
  29. """In a new user form, a user set all names."""
  30. login = "Zoë.Żywioł"
  31. firstname = "Zoë"
  32. lastname = "Żywioł"
  33. with self.get_clean_user_form() as user_form:
  34. user_form.login = login
  35. # Changes firstname, which triggers onchanges
  36. user_form.firstname = firstname
  37. # Changes lastname, which triggers onchanges
  38. user_form.lastname = lastname
  39. self.assertEqual(user_form.lastname, lastname)
  40. self.assertEqual(user_form.firstname, firstname)
  41. self.assertEqual(user_form.name, " ".join((firstname, lastname)))
  42. def get_clean_user_form(self):
  43. """Get form without pseudo_fields.
  44. This will be needed until Odoo Form does weed out these fields by itself.
  45. """
  46. form = Form(self.env["res.users"], view="partner_firstname.view_users_form")
  47. pseudo_fields = [
  48. fieldname
  49. for fieldname in form._view["fields"].keys()
  50. if fieldname[:11] == "sel_groups_" or fieldname[:9] == "in_group_"
  51. ]
  52. for fieldname in pseudo_fields:
  53. del form._view["fields"][fieldname]
  54. del form._values[fieldname]
  55. return form