test_performance.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.addons.mail.tests.common import mail_new_test_user
  4. from odoo.addons.test_mail.tests.test_performance import BaseMailPerformance
  5. from odoo.tests.common import users, warmup
  6. from odoo.tests import tagged
  7. from odoo.tools import mute_logger
  8. class TestMassMailPerformanceBase(BaseMailPerformance):
  9. @classmethod
  10. def setUpClass(cls):
  11. super(TestMassMailPerformanceBase, cls).setUpClass()
  12. cls.user_marketing = mail_new_test_user(
  13. cls.env,
  14. groups='base.group_user,mass_mailing.group_mass_mailing_user',
  15. login='marketing',
  16. name='Martial Marketing',
  17. signature='--\nMartial'
  18. )
  19. @tagged('mail_performance', 'post_install', '-at_install')
  20. class TestMassMailPerformance(TestMassMailPerformanceBase):
  21. def setUp(self):
  22. super(TestMassMailPerformance, self).setUp()
  23. values = [{
  24. 'name': 'Recipient %s' % x,
  25. 'email_from': 'Recipient <rec.%s@example.com>' % x,
  26. } for x in range(0, 50)]
  27. self.mm_recs = self.env['mailing.performance'].create(values)
  28. @users('__system__', 'marketing')
  29. @warmup
  30. @mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink', 'odoo.tests')
  31. def test_send_mailing(self):
  32. mailing = self.env['mailing.mailing'].create({
  33. 'name': 'Test',
  34. 'subject': 'Test',
  35. 'body_html': '<p>Hello <a role="button" href="https://www.example.com/foo/bar?baz=qux">quux</a><a role="button" href="/unsubscribe_from_list">Unsubscribe</a></p>',
  36. 'reply_to_mode': 'new',
  37. 'mailing_model_id': self.ref('test_mass_mailing.model_mailing_performance'),
  38. 'mailing_domain': [('id', 'in', self.mm_recs.ids)],
  39. })
  40. # runbot needs +51 compared to local
  41. with self.assertQueryCount(__system__=1473, marketing=1474):
  42. mailing.action_send_mail()
  43. self.assertEqual(mailing.sent, 50)
  44. self.assertEqual(mailing.delivered, 50)
  45. mails = self.env['mail.mail'].sudo().search([('mailing_id', '=', mailing.id)])
  46. self.assertFalse(mails, 'Should have auto-deleted the <mail.mail>')
  47. @tagged('mail_performance', 'post_install', '-at_install')
  48. class TestMassMailBlPerformance(TestMassMailPerformanceBase):
  49. def setUp(self):
  50. """ In this setup we prepare 20 blacklist entries. We therefore add
  51. 20 recipients compared to first test in order to have comparable results. """
  52. super(TestMassMailBlPerformance, self).setUp()
  53. values = [{
  54. 'name': 'Recipient %s' % x,
  55. 'email_from': 'Recipient <rec.%s@example.com>' % x,
  56. } for x in range(0, 62)]
  57. self.mm_recs = self.env['mailing.performance.blacklist'].create(values)
  58. for x in range(1, 13):
  59. self.env['mail.blacklist'].create({
  60. 'email': 'rec.%s@example.com' % (x * 5)
  61. })
  62. self.env.flush_all()
  63. @users('__system__', 'marketing')
  64. @warmup
  65. @mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink', 'odoo.tests')
  66. def test_send_mailing_w_bl(self):
  67. mailing = self.env['mailing.mailing'].create({
  68. 'name': 'Test',
  69. 'subject': 'Test',
  70. 'body_html': '<p>Hello <a role="button" href="https://www.example.com/foo/bar?baz=qux">quux</a><a role="button" href="/unsubscribe_from_list">Unsubscribe</a></p>',
  71. 'reply_to_mode': 'new',
  72. 'mailing_model_id': self.ref('test_mass_mailing.model_mailing_performance_blacklist'),
  73. 'mailing_domain': [('id', 'in', self.mm_recs.ids)],
  74. })
  75. # runbot needs +51 compared to local
  76. with self.assertQueryCount(__system__=1546, marketing=1547):
  77. mailing.action_send_mail()
  78. self.assertEqual(mailing.sent, 50)
  79. self.assertEqual(mailing.delivered, 50)
  80. cancelled_mail_count = self.env['mail.mail'].sudo().search([('mailing_id', '=', mailing.id)])
  81. self.assertEqual(len(cancelled_mail_count), 12, 'Should not have auto deleted the blacklisted emails')