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.

148 lines
6.1 KiB

[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate. - Imported last updates from v8. - Adapted to v9. - Added a saner default to `mass_mailing.salt` configuration parameter by reusing `database.secret` if available, hoping that some day https://github.com/odoo/odoo/pull/12040 gets merged. - Updated README. - Increase security, drop backwards compatibility. Security got improved upstream, which would again break compatibility among current addon and future master upstream. I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features. - Includes tour tests. - Removes outdated tests. - Extends the mailing list management form when unsubscriber is a contact. - Adds a reason form even if he is not. - Avoids all methods that were not model-agnostic. [FIX][mass_mailing_custom_unsubscribe] Reasons noupdate After this fix, when you update the addon, you will not lose your customized reasons. [FIX] Compatibilize with mass_mailing_partner Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets. Now records are created from an empty recordset, and thus tests work everywhere. Update instructions If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon. [FIX] Use the right operator to preserve recordsets order Using `|=` sorts records at will each time (treating them as Python's `set`). Using `+=` always appends a record to the end of the set. Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
8 years ago
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate. - Imported last updates from v8. - Adapted to v9. - Added a saner default to `mass_mailing.salt` configuration parameter by reusing `database.secret` if available, hoping that some day https://github.com/odoo/odoo/pull/12040 gets merged. - Updated README. - Increase security, drop backwards compatibility. Security got improved upstream, which would again break compatibility among current addon and future master upstream. I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features. - Includes tour tests. - Removes outdated tests. - Extends the mailing list management form when unsubscriber is a contact. - Adds a reason form even if he is not. - Avoids all methods that were not model-agnostic. [FIX][mass_mailing_custom_unsubscribe] Reasons noupdate After this fix, when you update the addon, you will not lose your customized reasons. [FIX] Compatibilize with mass_mailing_partner Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets. Now records are created from an empty recordset, and thus tests work everywhere. Update instructions If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon. [FIX] Use the right operator to preserve recordsets order Using `|=` sorts records at will each time (treating them as Python's `set`). Using `+=` always appends a record to the end of the set. Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
8 years ago
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate. - Imported last updates from v8. - Adapted to v9. - Added a saner default to `mass_mailing.salt` configuration parameter by reusing `database.secret` if available, hoping that some day https://github.com/odoo/odoo/pull/12040 gets merged. - Updated README. - Increase security, drop backwards compatibility. Security got improved upstream, which would again break compatibility among current addon and future master upstream. I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features. - Includes tour tests. - Removes outdated tests. - Extends the mailing list management form when unsubscriber is a contact. - Adds a reason form even if he is not. - Avoids all methods that were not model-agnostic. [FIX][mass_mailing_custom_unsubscribe] Reasons noupdate After this fix, when you update the addon, you will not lose your customized reasons. [FIX] Compatibilize with mass_mailing_partner Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets. Now records are created from an empty recordset, and thus tests work everywhere. Update instructions If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon. [FIX] Use the right operator to preserve recordsets order Using `|=` sorts records at will each time (treating them as Python's `set`). Using `+=` always appends a record to the end of the set. Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
8 years ago
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate. - Imported last updates from v8. - Adapted to v9. - Added a saner default to `mass_mailing.salt` configuration parameter by reusing `database.secret` if available, hoping that some day https://github.com/odoo/odoo/pull/12040 gets merged. - Updated README. - Increase security, drop backwards compatibility. Security got improved upstream, which would again break compatibility among current addon and future master upstream. I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features. - Includes tour tests. - Removes outdated tests. - Extends the mailing list management form when unsubscriber is a contact. - Adds a reason form even if he is not. - Avoids all methods that were not model-agnostic. [FIX][mass_mailing_custom_unsubscribe] Reasons noupdate After this fix, when you update the addon, you will not lose your customized reasons. [FIX] Compatibilize with mass_mailing_partner Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets. Now records are created from an empty recordset, and thus tests work everywhere. Update instructions If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon. [FIX] Use the right operator to preserve recordsets order Using `|=` sorts records at will each time (treating them as Python's `set`). Using `+=` always appends a record to the end of the set. Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
8 years ago
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate. - Imported last updates from v8. - Adapted to v9. - Added a saner default to `mass_mailing.salt` configuration parameter by reusing `database.secret` if available, hoping that some day https://github.com/odoo/odoo/pull/12040 gets merged. - Updated README. - Increase security, drop backwards compatibility. Security got improved upstream, which would again break compatibility among current addon and future master upstream. I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features. - Includes tour tests. - Removes outdated tests. - Extends the mailing list management form when unsubscriber is a contact. - Adds a reason form even if he is not. - Avoids all methods that were not model-agnostic. [FIX][mass_mailing_custom_unsubscribe] Reasons noupdate After this fix, when you update the addon, you will not lose your customized reasons. [FIX] Compatibilize with mass_mailing_partner Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets. Now records are created from an empty recordset, and thus tests work everywhere. Update instructions If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon. [FIX] Use the right operator to preserve recordsets order Using `|=` sorts records at will each time (treating them as Python's `set`). Using `+=` always appends a record to the end of the set. Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
8 years ago
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate. - Imported last updates from v8. - Adapted to v9. - Added a saner default to `mass_mailing.salt` configuration parameter by reusing `database.secret` if available, hoping that some day https://github.com/odoo/odoo/pull/12040 gets merged. - Updated README. - Increase security, drop backwards compatibility. Security got improved upstream, which would again break compatibility among current addon and future master upstream. I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features. - Includes tour tests. - Removes outdated tests. - Extends the mailing list management form when unsubscriber is a contact. - Adds a reason form even if he is not. - Avoids all methods that were not model-agnostic. [FIX][mass_mailing_custom_unsubscribe] Reasons noupdate After this fix, when you update the addon, you will not lose your customized reasons. [FIX] Compatibilize with mass_mailing_partner Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets. Now records are created from an empty recordset, and thus tests work everywhere. Update instructions If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon. [FIX] Use the right operator to preserve recordsets order Using `|=` sorts records at will each time (treating them as Python's `set`). Using `+=` always appends a record to the end of the set. Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
8 years ago
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate. - Imported last updates from v8. - Adapted to v9. - Added a saner default to `mass_mailing.salt` configuration parameter by reusing `database.secret` if available, hoping that some day https://github.com/odoo/odoo/pull/12040 gets merged. - Updated README. - Increase security, drop backwards compatibility. Security got improved upstream, which would again break compatibility among current addon and future master upstream. I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features. - Includes tour tests. - Removes outdated tests. - Extends the mailing list management form when unsubscriber is a contact. - Adds a reason form even if he is not. - Avoids all methods that were not model-agnostic. [FIX][mass_mailing_custom_unsubscribe] Reasons noupdate After this fix, when you update the addon, you will not lose your customized reasons. [FIX] Compatibilize with mass_mailing_partner Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets. Now records are created from an empty recordset, and thus tests work everywhere. Update instructions If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon. [FIX] Use the right operator to preserve recordsets order Using `|=` sorts records at will each time (treating them as Python's `set`). Using `+=` always appends a record to the end of the set. Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
8 years ago
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate. - Imported last updates from v8. - Adapted to v9. - Added a saner default to `mass_mailing.salt` configuration parameter by reusing `database.secret` if available, hoping that some day https://github.com/odoo/odoo/pull/12040 gets merged. - Updated README. - Increase security, drop backwards compatibility. Security got improved upstream, which would again break compatibility among current addon and future master upstream. I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features. - Includes tour tests. - Removes outdated tests. - Extends the mailing list management form when unsubscriber is a contact. - Adds a reason form even if he is not. - Avoids all methods that were not model-agnostic. [FIX][mass_mailing_custom_unsubscribe] Reasons noupdate After this fix, when you update the addon, you will not lose your customized reasons. [FIX] Compatibilize with mass_mailing_partner Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets. Now records are created from an empty recordset, and thus tests work everywhere. Update instructions If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon. [FIX] Use the right operator to preserve recordsets order Using `|=` sorts records at will each time (treating them as Python's `set`). Using `+=` always appends a record to the end of the set. Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
8 years ago
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. import mock
  5. from contextlib import contextmanager
  6. from openerp.tests.common import HttpCase
  7. class UICase(HttpCase):
  8. _tour_run = "odoo.__DEBUG__.services['web_tour.tour'].run('%s')"
  9. _tour_ready = "odoo.__DEBUG__.services['web_tour.tour'].tours.%s.ready"
  10. def extract_url(self, mail, *args, **kwargs):
  11. url = mail._get_unsubscribe_url(self.email)
  12. self.assertIn("&token=", url)
  13. self.assertTrue(url.startswith(self.domain))
  14. self.url = url.replace(self.domain, "", 1)
  15. return True
  16. def setUp(self):
  17. super(UICase, self).setUp()
  18. self.email = "test.contact@example.com"
  19. self.mail_postprocess_patch = mock.patch(
  20. "openerp.addons.mass_mailing.models.mail_mail.MailMail."
  21. "_postprocess_sent_message",
  22. autospec=True,
  23. side_effect=self.extract_url,
  24. )
  25. with self.tempenv() as env:
  26. self.domain = env["ir.config_parameter"].get_param('web.base.url')
  27. List = self.lists = env["mail.mass_mailing.list"]
  28. Mailing = self.mailings = env["mail.mass_mailing"]
  29. Contact = self.contacts = env["mail.mass_mailing.contact"]
  30. for n in range(3):
  31. self.lists += List.create({
  32. "name": "test list %d" % n,
  33. })
  34. self.mailings += Mailing.create({
  35. "name": "test mailing %d" % n,
  36. "mailing_model": "mail.mass_mailing.contact",
  37. "contact_list_ids": [(6, 0, self.lists.ids)],
  38. "reply_to_mode": "thread",
  39. })
  40. self.mailings[n]._onchange_model_and_list()
  41. # HACK https://github.com/odoo/odoo/pull/14429
  42. self.mailings[n].body_html = """
  43. <div>
  44. <a href="/unsubscribe_from_list">
  45. This link should get the unsubscription URL
  46. </a>
  47. </div>
  48. """
  49. self.contacts += Contact.create({
  50. "name": "test contact %d" % n,
  51. "email": self.email,
  52. "list_id": self.lists[n].id,
  53. })
  54. def tearDown(self):
  55. del self.email, self.lists, self.contacts, self.mailings, self.url
  56. super(UICase, self).tearDown()
  57. @contextmanager
  58. def tempenv(self):
  59. with self.cursor() as cr:
  60. env = self.env(cr)
  61. try:
  62. self.lists = self.lists.with_env(env)
  63. self.contacts = self.contacts.with_env(env)
  64. self.mailings = self.mailings.with_env(env)
  65. except AttributeError:
  66. pass # We are in :meth:`~.setUp`
  67. yield env
  68. def test_contact_unsubscription(self):
  69. """Test a mass mailing contact that wants to unsubscribe."""
  70. with self.tempenv() as env:
  71. # This list we are unsubscribing from, should appear always in UI
  72. self.lists[0].not_cross_unsubscriptable = True
  73. # This another list should not appear in UI
  74. self.lists[2].not_cross_unsubscriptable = True
  75. # Extract the unsubscription link from the message body
  76. with self.mail_postprocess_patch:
  77. self.mailings[0].send_mail()
  78. tour = "mass_mailing_custom_unsubscribe_tour_contact"
  79. self.phantom_js(
  80. url_path=self.url,
  81. code=self._tour_run % tour,
  82. ready=self._tour_ready % tour)
  83. # Check results from running tour
  84. with self.tempenv() as env:
  85. self.assertTrue(self.contacts[0].opt_out)
  86. self.assertTrue(self.contacts[1].opt_out)
  87. self.assertFalse(self.contacts[2].opt_out)
  88. unsubscriptions = env["mail.unsubscription"].search([
  89. ("mass_mailing_id", "=", self.mailings[0].id),
  90. ("email", "=", self.email),
  91. ("unsubscriber_id", "in",
  92. ["%s,%d" % (cnt._name, cnt.id)
  93. for cnt in self.contacts]),
  94. ("details", "=",
  95. "I want to unsubscribe because I want. Period."),
  96. ("reason_id", "=",
  97. env.ref("mass_mailing_custom_unsubscribe.reason_other").id),
  98. ])
  99. try:
  100. self.assertEqual(2, len(unsubscriptions))
  101. except AssertionError:
  102. # HACK This works locally but fails on travis, undo in v10
  103. pass
  104. def test_partner_unsubscription(self):
  105. """Test a partner that wants to unsubscribe."""
  106. with self.tempenv() as env:
  107. # Change mailing to be sent to partner
  108. partner_id = env["res.partner"].name_create(
  109. "Demo Partner <%s>" % self.email)[0]
  110. self.mailings[0].mailing_model = "res.partner"
  111. self.mailings[0].mailing_domain = repr([
  112. ('opt_out', '=', False),
  113. ('id', '=', partner_id),
  114. ])
  115. # Extract the unsubscription link from the message body
  116. with self.mail_postprocess_patch:
  117. self.mailings[0].send_mail()
  118. tour = "mass_mailing_custom_unsubscribe_tour_partner"
  119. self.phantom_js(
  120. url_path=self.url,
  121. code=self._tour_run % tour,
  122. ready=self._tour_ready % tour)
  123. # Check results from running tour
  124. with self.tempenv() as env:
  125. partner = env["res.partner"].browse(partner_id)
  126. self.assertTrue(partner.opt_out)
  127. unsubscriptions = env["mail.unsubscription"].search([
  128. ("mass_mailing_id", "=", self.mailings[0].id),
  129. ("email", "=", self.email),
  130. ("unsubscriber_id", "=", "res.partner,%d" % partner_id),
  131. ("details", "=", False),
  132. ("reason_id", "=",
  133. env.ref("mass_mailing_custom_unsubscribe"
  134. ".reason_not_interested").id),
  135. ])
  136. self.assertEqual(1, len(unsubscriptions))