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.

72 lines
2.7 KiB

  1. # Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
  2. # License MIT (https://opensource.org/licenses/MIT).
  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.flush()
  35. self.env.user.invalidate_cache()
  36. self.assertEqual(
  37. self.env.user.email,
  38. self.email,
  39. "Write methods doesn't work (Field is not in registry?)",
  40. )
  41. # changing company will automatically update website value to empty value
  42. self.env.user.company_id = self.original_company
  43. self.env.user.invalidate_cache()
  44. self.assertEqual(
  45. self.env.user.email,
  46. self.original_email,
  47. "Multi-email doesn't work on switching websites",
  48. )
  49. def test_multi_email_partner(self):
  50. """Partner doesn't have email addresses per website"""
  51. original_email = "original@email1"
  52. new_email = "new@email2"
  53. partner = self.env["res.partner"].create(
  54. {"name": "test", "email": original_email}
  55. )
  56. self.switch_user_website()
  57. # update partner's email
  58. partner.email = new_email
  59. self.assertEqual(partner.email, new_email)
  60. # changing company will automatically update website value to empty value
  61. self.env.user.company_id = self.original_company
  62. self.env.user.invalidate_cache()
  63. self.assertEqual(
  64. partner.email, new_email, "Partner's email must not be Multi-website"
  65. )