[MIG] mass_mailing_custom_unsubscribe_event: Migration to 15.0

pull/1092/head
Luis Ernesto García Medina 2023-03-08 11:44:36 -06:00
parent 7b995b6dee
commit b5828437e5
5 changed files with 50 additions and 81 deletions

View File

@ -4,12 +4,16 @@
{ {
"name": "Allow to unsubscribe discretely from an event", "name": "Allow to unsubscribe discretely from an event",
"category": "Marketing", "category": "Marketing",
"version": "13.0.1.0.0", "version": "15.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"], "assets": {
"web.assets_tests": [
"/mass_mailing_custom_unsubscribe_event/static/src/js/tour.esm.js"
]
},
"license": "AGPL-3", "license": "AGPL-3",
"installable": True, "installable": True,
"auto_install": True, "auto_install": True,

View File

@ -1,15 +0,0 @@
<?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

@ -0,0 +1,36 @@
/** @odoo-module **/
/* Copyright 2020 Tecnativa - João Marques
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
import tour from "web_tour.tour";
tour.register(
"mass_mailing_custom_unsubscribe_event_tour",
{
test: true,
},
[
{
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

@ -1,45 +0,0 @@
/* 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

@ -1,21 +1,23 @@
# Copyright 2020 Tecnativa - João Marques # 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).
import mock from unittest import mock
from werkzeug import urls from werkzeug import urls
from odoo.tests.common import HttpCase from odoo.tests.common import HttpCase, tagged
@tagged("post_install", "-at_install")
class UICase(HttpCase): class UICase(HttpCase):
def extract_url(self, mail, *args, **kwargs): def extract_url(self, mail, *args, **kwargs):
url = mail._get_unsubscribe_url(self.email) url = mail.mailing_id._get_unsubscribe_url(self.email, mail.res_id)
self.assertTrue(urls.url_parse(url).decode_query().get("token")) self.assertTrue(urls.url_parse(url).decode_query().get("token"))
self.assertTrue(url.startswith(self.domain)) self.assertTrue(url.startswith(self.domain))
self.url = url.replace(self.domain, "", 1) self.url = url.replace(self.domain, "", 1)
return True return True
def setUp(self): def setUp(self):
super(UICase, self).setUp() super().setUp()
self.email = "test.contact@example.com" self.email = "test.contact@example.com"
self.mail_postprocess_patch = mock.patch( self.mail_postprocess_patch = mock.patch(
"odoo.addons.mass_mailing.models.mail_mail.MailMail." "odoo.addons.mass_mailing.models.mail_mail.MailMail."
@ -23,13 +25,11 @@ class UICase(HttpCase):
autospec=True, autospec=True,
side_effect=self.extract_url, side_effect=self.extract_url,
) )
self.domain = self.env["ir.config_parameter"].get_param("web.base.url") self.domain = self.env["ir.config_parameter"].get_param("web.base.url")
self.partner = self.env["res.partner"].create( self.partner = self.env["res.partner"].create(
{"name": "Demo Partner <%s>" % self.email, "email": self.email} {"name": "Demo Partner <%s>" % self.email, "email": self.email}
) )
self.event_1 = self.env["event.event"].create( self.event_1 = self.env["event.event"].create(
{ {
"name": "test_event_2", "name": "test_event_2",
@ -62,18 +62,15 @@ class UICase(HttpCase):
"partner_id": self.partner.id, "partner_id": self.partner.id,
} }
) )
self.mailing_1 = self.env["mailing.mailing"].create( self.mailing_1 = self.env["mailing.mailing"].create(
{ {
"name": "test_mailing_1", "name": "test_mailing_1",
"mailing_model_id": self.env.ref("event.model_event_registration").id, "mailing_model_id": self.env.ref("event.model_event_registration").id,
"mailing_domain": "[['id','=',%s]]" % self.event_registration_1.id, "mailing_domain": "[['id','=',%s]]" % self.event_registration_1.id,
"reply_to_mode": "email", "reply_to_mode": "update",
"subject": "Test 1", "subject": "Test 1",
} }
) )
self.mailing_1._onchange_model_and_list()
# HACK https://github.com/odoo/odoo/pull/14429
self.mailing_1.body_html = """ self.mailing_1.body_html = """
<div> <div>
<a href="/unsubscribe_from_list"> <a href="/unsubscribe_from_list">
@ -81,18 +78,15 @@ class UICase(HttpCase):
</a> </a>
</div> </div>
""" """
self.mailing_2 = self.env["mailing.mailing"].create( self.mailing_2 = self.env["mailing.mailing"].create(
{ {
"name": "test_mailing_2", "name": "test_mailing_2",
"mailing_model_id": self.env.ref("event.model_event_registration").id, "mailing_model_id": self.env.ref("event.model_event_registration").id,
"mailing_domain": "[['id','=',%s]]" % self.event_registration_2.id, "mailing_domain": "[['id','=',%s]]" % self.event_registration_2.id,
"reply_to_mode": "email", "reply_to_mode": "update",
"subject": "Test 2", "subject": "Test 2",
} }
) )
self.mailing_2._onchange_model_and_list()
# HACK https://github.com/odoo/odoo/pull/14429
self.mailing_2.body_html = """ self.mailing_2.body_html = """
<div> <div>
<a href="/unsubscribe_from_list"> <a href="/unsubscribe_from_list">
@ -120,16 +114,13 @@ class UICase(HttpCase):
# Extract the unsubscription link from the message body # Extract the unsubscription link from the message body
with self.mail_postprocess_patch: with self.mail_postprocess_patch:
self.mailing_1.action_send_mail() self.mailing_1.action_send_mail()
tour = "mass_mailing_custom_unsubscribe_event_tour" tour = "mass_mailing_custom_unsubscribe_event_tour"
self.start_tour(url_path=self.url, tour_name=tour, login="demo") self.start_tour(url_path=self.url, tour_name=tour, login="demo")
# Check results from running tour # Check results from running tour
# User should be opted out from event 1 mailing list # User should be opted out from event 1 mailing list
self.assertTrue(self.event_registration_1.opt_out) self.assertTrue(self.event_registration_1.opt_out)
# User should not be opted out from event 2 mailing list # User should not be opted out from event 2 mailing list
self.assertFalse(self.event_registration_2.opt_out) self.assertFalse(self.event_registration_2.opt_out)
reason_xid = "mass_mailing_custom_unsubscribe.reason_not_interested" reason_xid = "mass_mailing_custom_unsubscribe.reason_not_interested"
unsubscriptions = self.env["mail.unsubscription"].search( unsubscriptions = self.env["mail.unsubscription"].search(
[ [
@ -147,8 +138,6 @@ class UICase(HttpCase):
) )
# Unsubscription record must exist # Unsubscription record must exist
self.assertEqual(1, len(unsubscriptions)) self.assertEqual(1, len(unsubscriptions))
self.mailing_2.action_send_mail() self.mailing_2.action_send_mail()
# Mail to user must have been sent # Mail to user must have been sent
self.assertEqual(1, self.mailing_2.sent) self.assertEqual(1, self.mailing_2.sent)