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.

71 lines
2.6 KiB

  1. # Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  3. from odoo.tests.common import TransactionCase
  4. class TestSendMail(TransactionCase):
  5. at_install = True
  6. post_install = True
  7. def setUp(self):
  8. super(TestSendMail, self).setUp()
  9. self.website = self.env.ref("website.website2")
  10. self.company = self.env["res.company"].create({"name": "New Test Website"})
  11. self.original_email = self.env.user.email
  12. self.original_company = self.env.user.company_id
  13. self.email = "superadmin@second-website.example"
  14. # Check that current email is set and differs
  15. self.assertTrue(self.email)
  16. self.assertNotEqual(self.original_email, self.email)
  17. self.website.company_id = self.company
  18. def switch_user_website(self):
  19. # add website to allowed
  20. self.env.user.write(
  21. dict(
  22. backend_website_ids=[(4, self.website.id)],
  23. backend_website_id=self.website.id,
  24. company_id=self.company.id,
  25. company_ids=[(4, self.company.id)],
  26. )
  27. )
  28. def test_multi_email(self):
  29. """User has email addresses per website"""
  30. self.switch_user_website()
  31. # update user's email
  32. self.env.user.email = self.email
  33. # Check that writing works
  34. self.env.user.invalidate_cache()
  35. self.assertEqual(
  36. self.env.user.email,
  37. self.email,
  38. "Write methods doesn't work (Field is not in registry?)",
  39. )
  40. # changing company will automatically update website value to empty value
  41. self.env.user.company_id = self.original_company
  42. self.env.user.invalidate_cache()
  43. self.assertEqual(
  44. self.env.user.email,
  45. self.original_email,
  46. "Multi-email doesn't work on switching websites",
  47. )
  48. def test_multi_email_partner(self):
  49. """Partner doesn't have email addresses per website"""
  50. original_email = "original@email1"
  51. new_email = "new@email2"
  52. partner = self.env["res.partner"].create(
  53. {"name": "test", "email": original_email}
  54. )
  55. self.switch_user_website()
  56. # update partner's email
  57. partner.email = new_email
  58. self.assertEqual(partner.email, new_email)
  59. # changing company will automatically update website value to empty value
  60. self.env.user.company_id = self.original_company
  61. self.env.user.invalidate_cache()
  62. self.assertEqual(
  63. partner.email, new_email, "Partner's email must not be Multi-website"
  64. )