[MIG] mass_mailing_custom_unsubscribe_event: Migration to 13.0

Add tests

TT26693
pull/1092/head
João Marques 2020-11-18 15:16:12 +00:00 committed by Luis Ernesto García Medina
parent 20a2c255aa
commit 4b06406868
10 changed files with 240 additions and 17 deletions

View File

@ -14,13 +14,13 @@ Allow to unsubscribe discretely from an event
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
:target: https://github.com/OCA/social/tree/12.0/mass_mailing_custom_unsubscribe_event :target: https://github.com/OCA/social/tree/13.0/mass_mailing_custom_unsubscribe_event
:alt: OCA/social :alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-12-0/social-12-0-mass_mailing_custom_unsubscribe_event :target: https://translation.odoo-community.org/projects/social-13-0/social-13-0-mass_mailing_custom_unsubscribe_event
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/205/12.0 :target: https://runbot.odoo-community.org/runbot/205/13.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -54,7 +54,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_custom_unsubscribe_event%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_custom_unsubscribe_event%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -72,6 +72,7 @@ Contributors
* `Tecnativa <https://www.tecnativa.com>`_: * `Tecnativa <https://www.tecnativa.com>`_:
* Pedro M. Baeza * Pedro M. Baeza
* João Marques
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~
@ -86,6 +87,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/social <https://github.com/OCA/social/tree/12.0/mass_mailing_custom_unsubscribe_event>`_ project on GitHub. This module is part of the `OCA/social <https://github.com/OCA/social/tree/13.0/mass_mailing_custom_unsubscribe_event>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -1,13 +1,15 @@
# Copyright 2020 Tecnativa - Pedro M. Baeza # Copyright 2020 Tecnativa - Pedro M. Baeza
# Copyright 2020 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
"name": "Allow to unsubscribe discretely from an event", "name": "Allow to unsubscribe discretely from an event",
"category": "Marketing", "category": "Marketing",
"version": "12.0.1.0.1", "version": "13.0.1.0.0",
"depends": ["event", "mass_mailing_custom_unsubscribe"], "depends": ["event", "mass_mailing_custom_unsubscribe"],
"author": "Tecnativa, Odoo Community Association (OCA)", "author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social", "website": "https://github.com/OCA/social",
"data": ["views/event_registration_views.xml"], "data": ["views/event_registration_views.xml"],
"demo": ["demo/assets.xml"],
"license": "AGPL-3", "license": "AGPL-3",
"installable": True, "installable": True,
"auto_install": True, "auto_install": True,

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2020 Tecnativa - João Marques
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<template id="assets_frontend_demo" inherit_id="web.assets_frontend">
<xpath expr=".">
<script
type="text/javascript"
src="/mass_mailing_custom_unsubscribe_event/static/src/js/tour.js"
/>
</xpath>
</template>
</odoo>

View File

@ -1,12 +1,12 @@
# Translation of Odoo Server. # Translation of Odoo Server.
# This file contains the translation of the following modules: # This file contains the translation of the following modules:
# * mass_mailing_custom_unsubscribe_event # * mass_mailing_custom_unsubscribe_event
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 12.0\n" "Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
@ -20,11 +20,12 @@ msgstr ""
#. module: mass_mailing_custom_unsubscribe_event #. module: mass_mailing_custom_unsubscribe_event
#: model:ir.model.fields,help:mass_mailing_custom_unsubscribe_event.field_event_registration__opt_out #: model:ir.model.fields,help:mass_mailing_custom_unsubscribe_event.field_event_registration__opt_out
msgid "If opt-out is checked, this registree has refused to receive emails for mass mailing and marketing campaign." msgid ""
"If opt-out is checked, this registree has refused to receive emails for mass"
" mailing and marketing campaign."
msgstr "" msgstr ""
#. module: mass_mailing_custom_unsubscribe_event #. module: mass_mailing_custom_unsubscribe_event
#: model:ir.model.fields,field_description:mass_mailing_custom_unsubscribe_event.field_event_registration__opt_out #: model:ir.model.fields,field_description:mass_mailing_custom_unsubscribe_event.field_event_registration__opt_out
msgid "Opt-Out" msgid "Opt-Out"
msgstr "" msgstr ""

View File

@ -1,3 +1,4 @@
* `Tecnativa <https://www.tecnativa.com>`_: * `Tecnativa <https://www.tecnativa.com>`_:
* Pedro M. Baeza * Pedro M. Baeza
* João Marques

View File

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/social/tree/12.0/mass_mailing_custom_unsubscribe_event"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/social-12-0/social-12-0-mass_mailing_custom_unsubscribe_event"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/205/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/social/tree/13.0/mass_mailing_custom_unsubscribe_event"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/social-13-0/social-13-0-mass_mailing_custom_unsubscribe_event"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/205/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This addon extends the unsubscription process for allowing to unsubscribe <p>This addon extends the unsubscription process for allowing to unsubscribe
only for an event.</p> only for an event.</p>
<p>Standard process includes the mail in the general blacklist instead, which <p>Standard process includes the mail in the general blacklist instead, which
@ -403,7 +403,7 @@ receive mailings.</li>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_custom_unsubscribe_event%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_custom_unsubscribe_event%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -419,6 +419,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<ul class="simple"> <ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul> <li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Pedro M. Baeza</li> <li>Pedro M. Baeza</li>
<li>João Marques</li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -430,7 +431,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/12.0/mass_mailing_custom_unsubscribe_event">OCA/social</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/13.0/mass_mailing_custom_unsubscribe_event">OCA/social</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@ -0,0 +1,45 @@
/* Copyright 2020 Tecnativa - João Marques
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define("mass_mailing_custom_unsubscribe_event.tour", function(require) {
"use strict";
var base = require("web_editor.base");
var tour = require("web_tour.tour");
// Allow to know if an element is required
$.extend($.expr[":"], {
propRequired: function(element) {
return $(element).prop("required");
},
});
tour.register(
"mass_mailing_custom_unsubscribe_event_tour",
{
test: true,
wait_for: base.ready(),
},
[
{
content: "Choose other reason",
trigger: ".radio:contains('Other reason') :radio:not(:checked)",
extra_trigger: "#reason_form #custom_div_feedback",
},
{
content: "Switch to not interested reason",
trigger: '.radio:contains("I\'m not interested") :radio:not(:checked)',
extra_trigger: "[name='details']:propRequired",
},
{
content: "Unsubscribe",
trigger: "#reason_form button:submit",
extra_trigger: "body:not(:has([name='details']:propRequired))",
},
{
content: "Successfully unsubscribed",
trigger:
"body:not(:has(#reason_form)) #subscription_info " +
":contains('successfully unsubscribed')",
},
]
);
});

View File

@ -0,0 +1,4 @@
# Copyright 2020 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_ui

View File

@ -0,0 +1,154 @@
# Copyright 2020 Tecnativa - João Marques
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import mock
from werkzeug import urls
from odoo.tests.common import HttpCase
class UICase(HttpCase):
def extract_url(self, mail, *args, **kwargs):
url = mail._get_unsubscribe_url(self.email)
self.assertTrue(urls.url_parse(url).decode_query().get("token"))
self.assertTrue(url.startswith(self.domain))
self.url = url.replace(self.domain, "", 1)
return True
def setUp(self):
super(UICase, self).setUp()
self.email = "test.contact@example.com"
self.mail_postprocess_patch = mock.patch(
"odoo.addons.mass_mailing.models.mail_mail.MailMail."
"_postprocess_sent_message",
autospec=True,
side_effect=self.extract_url,
)
self.domain = self.env["ir.config_parameter"].get_param("web.base.url")
self.partner = self.env["res.partner"].create(
{"name": "Demo Partner <%s>" % self.email, "email": self.email}
)
self.event_1 = self.env["event.event"].create(
{
"name": "test_event_2",
"event_type_id": 1,
"date_end": "2012-01-01 19:05:15",
"date_begin": "2012-01-01 18:05:15",
}
)
self.event_2 = self.env["event.event"].create(
{
"name": "test_event_2",
"event_type_id": 1,
"date_end": "2012-01-01 19:05:15",
"date_begin": "2012-01-01 18:05:15",
}
)
self.event_registration_1 = self.env["event.registration"].create(
{
"name": "test_registration_1",
"event_id": self.event_1.id,
"email": self.email,
"partner_id": self.partner.id,
}
)
self.event_registration_2 = self.env["event.registration"].create(
{
"name": "test_registration_2",
"event_id": self.event_2.id,
"email": self.email,
"partner_id": self.partner.id,
}
)
self.mailing_1 = self.env["mailing.mailing"].create(
{
"name": "test_mailing_1",
"mailing_model_id": self.env.ref("event.model_event_registration").id,
"mailing_domain": "[['id','=',%s]]" % self.event_registration_1.id,
"reply_to_mode": "email",
"subject": "Test 1",
}
)
self.mailing_1._onchange_model_and_list()
# HACK https://github.com/odoo/odoo/pull/14429
self.mailing_1.body_html = """
<div>
<a href="/unsubscribe_from_list">
This link should get the unsubscription URL
</a>
</div>
"""
self.mailing_2 = self.env["mailing.mailing"].create(
{
"name": "test_mailing_2",
"mailing_model_id": self.env.ref("event.model_event_registration").id,
"mailing_domain": "[['id','=',%s]]" % self.event_registration_2.id,
"reply_to_mode": "email",
"subject": "Test 2",
}
)
self.mailing_2._onchange_model_and_list()
# HACK https://github.com/odoo/odoo/pull/14429
self.mailing_2.body_html = """
<div>
<a href="/unsubscribe_from_list">
This link should get the unsubscription URL
</a>
</div>
"""
def tearDown(self):
del (
self.email,
self.event_1,
self.event_2,
self.event_registration_1,
self.event_registration_2,
self.mailing_1,
self.mailing_2,
self.partner,
self.url,
)
super(UICase, self).tearDown()
def test_unsubscription_event_1(self):
"""Test a mass mailing contact that wants to unsubscribe."""
# Extract the unsubscription link from the message body
with self.mail_postprocess_patch:
self.mailing_1.action_send_mail()
tour = "mass_mailing_custom_unsubscribe_event_tour"
self.start_tour(url_path=self.url, tour_name=tour, login="demo")
# Check results from running tour
# User should be opted out from event 1 mailing list
self.assertTrue(self.event_registration_1.opt_out)
# User should not be opted out from event 2 mailing list
self.assertFalse(self.event_registration_2.opt_out)
reason_xid = "mass_mailing_custom_unsubscribe.reason_not_interested"
unsubscriptions = self.env["mail.unsubscription"].search(
[
("action", "=", "unsubscription"),
("mass_mailing_id", "=", self.mailing_1.id),
("email", "=", self.email),
(
"unsubscriber_id",
"=",
"event.registration,%d" % self.event_registration_1.id,
),
("details", "=", False),
("reason_id", "=", self.env.ref(reason_xid).id),
]
)
# Unsubscription record must exist
self.assertEqual(1, len(unsubscriptions))
self.mailing_2.action_send_mail()
# Mail to user must have been sent
self.assertEqual(1, self.mailing_2.sent)

View File

@ -1,13 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2020 Tecnativa - Pedro M. Baeza <!-- Copyright 2020 Tecnativa - Pedro M. Baeza
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo> <odoo>
<record id="view_event_registration_form" model="ir.ui.view"> <record id="view_event_registration_form" model="ir.ui.view">
<field name="name">event.registration.form - Add opt_out</field> <field name="name">event.registration.form - Add opt_out</field>
<field name="model">event.registration</field> <field name="model">event.registration</field>
<field name="inherit_id" ref="event.view_event_registration_form"/> <field name="inherit_id" ref="event.view_event_registration_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="email" position="after"> <field name="email" position="after">
<field name="opt_out" /> <field name="opt_out" />