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.

62 lines
2.5 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({
  11. 'name': 'New Test Website'
  12. })
  13. self.original_email = self.env.user.email
  14. self.original_company = self.env.user.company_id
  15. self.email = 'superadmin@second-website.example'
  16. # Check that current email is set and differs
  17. self.assertTrue(self.email)
  18. self.assertNotEqual(self.original_email, self.email)
  19. self.website.company_id = self.company
  20. def switch_user_website(self):
  21. # add website to allowed
  22. self.env.user.write(dict(
  23. backend_website_ids=[(4, self.website.id)],
  24. backend_website_id=self.website.id,
  25. company_id=self.company.id,
  26. company_ids=[(4, self.company.id)]
  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(self.env.user.email, self.email, 'Write methods doesn\'t work (Field is not in registry?)')
  36. # changing company will automatically update website value to empty value
  37. self.env.user.company_id = self.original_company
  38. self.env.user.invalidate_cache()
  39. self.assertEqual(self.env.user.email, self.original_email, 'Multi-email doesn\'t work on switching websites')
  40. def test_multi_email_partner(self):
  41. """Partner doesn't have email addresses per website"""
  42. original_email = 'original@email1'
  43. new_email = 'new@email2'
  44. partner = self.env['res.partner'].create({
  45. 'name': 'test',
  46. 'email': original_email,
  47. })
  48. self.switch_user_website()
  49. # update partner's email
  50. partner.email = new_email
  51. self.assertEqual(partner.email, new_email)
  52. # changing company will automatically update website value to empty value
  53. self.env.user.company_id = self.original_company
  54. self.env.user.invalidate_cache()
  55. self.assertEqual(partner.email, new_email, 'Partner\'s email must not be Multi-website')