summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Kersten <jke@odoo.com>2020-03-06 16:10:23 +0000
committerJeremy Kersten <jke@odoo.com>2020-03-06 21:39:14 +0000
commit614c9baae412020ac9d23c81a2650c9e86046e32 (patch)
tree1ebce847e2b74655b212c181cabc209a9d2a967d
parent121c73246dfe455cfd0a86af7515d28bc0a79661 (diff)
[REF] website: refactor reset_password tour
Previous implementation crashes randomly in chrome headless due to timeout. Avoid to do web action, while we just want to check reset_password feature. + add one test that reset password on partner from website 2 to check that link match the domauin from website 2. closes odoo/odoo#47136 X-original-commit: d8019f25a5cd6ed611295e9b93111402f4cad04a Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
-rw-r--r--addons/website/static/tests/tours/reset_password.js132
-rw-r--r--addons/website/tests/test_website_reset_password.py30
2 files changed, 31 insertions, 131 deletions
diff --git a/addons/website/static/tests/tours/reset_password.js b/addons/website/static/tests/tours/reset_password.js
index a0e04ccae90..ef9fc1d0586 100644
--- a/addons/website/static/tests/tours/reset_password.js
+++ b/addons/website/static/tests/tours/reset_password.js
@@ -6,137 +6,9 @@ var rpc = require('web.rpc');
var tour = require('web_tour.tour');
require('web.dom_ready');
-var currentDomain = window.location.protocol + '//' + window.location.hostname;
-var emailsUrl = '/web#action=mail.action_view_mail_mail&view_type=list';
-var usersUrl = '/web#action=base.action_res_users&view_type=list';
-var resetLinkKey = 'website.tour_reset_password.resetLink';
-
tour.register('website_reset_password', {
test: true,
- url: '/web',
-},
-[
- {
- content: "Change the domain of the websites and go to users page",
- trigger: '.oe_topbar_name:contains("Admin")',
- run: function () {
- // We could do it with the UI but this is not the goal of this test,
- // so we just make an RPC to be faster.
-
- // We change the domain of the website to test that the email that
- // will be sent uses the correct domain for its links.
- var def1 = rpc.query({
- 'model': 'website',
- 'method': 'write',
- 'args': [[1], {
- 'domain': "my-test-domain.com",
- }],
- });
- // We need to change the domain of all the websites otherwise the
- // website selector will return the website 2 since the domain we
- // set on website 1 doesn't actually match our test server.
- var def2 = rpc.query({
- 'model': 'website',
- 'method': 'write',
- 'args': [[2], {
- 'domain': "https://domain-not-used.fr",
- }],
- });
- // Set a website on "Admin" partner to test the URL of the website.
- var def3 = rpc.query({
- model: 'ir.model.data',
- method: 'xmlid_to_res_id',
- args: ['base.partner_admin'],
- }).then(function (res_id) {
- return rpc.query({
- 'model': 'res.partner',
- 'method': 'write',
- 'args': [[res_id], {
- 'website_id': 1,
- }],
- });
- });
-
- return Promise.all([def1, def2, def3]).then(function () {
- window.location.href = usersUrl;
- });
- },
- },
- {
- content: "click on Admin",
- trigger: '.o_data_cell:contains("Admin")',
- },
- {
- content: "click on reset password",
- trigger: '.btn[name="action_reset_password"]',
- },
- {
- content: "wait mail to be sent, and go see it",
- trigger: 'a[name="signup_url"][href^="http://my-test-domain.com"]',
- run: function () {
- window.location.href = emailsUrl;
- },
- },
- {
- content: "click on the first email",
- trigger: '.o_data_cell:contains("Password reset"):eq(0)',
- },
- {
- content: "check email has the button",
- trigger: 'div.oe_form_field_html[name="body_html"] a:contains("Change password")',
- run: function () {},
- },
- {
- content: "check the URL is correct too",
- trigger: 'div.oe_form_field_html[name="body_html"] a:contains("Change password")[href^="http://my-test-domain.com"]',
- run: function () {
- // reset the domain of the websites, go to users page
- return rpc.query({
- 'model': 'website',
- 'method': 'write',
- 'args': [[1, 2], {
- 'domain': "",
- }],
- }).then(function () {
- window.location.href = usersUrl;
- });
- },
- },
- {
- content: "click on Admin",
- trigger: '.o_data_cell:contains("Admin")',
- },
- {
- content: "click on reset password",
- trigger: '.btn[name="action_reset_password"]',
- },
- {
- content: "wait mail to be sent, and go see it",
- trigger: 'a[name="signup_url"][href^="' + currentDomain + '"]',
- run: function () {
- window.location.href = emailsUrl;
- },
- },
- {
- content: "click on the first email",
- trigger: '.o_data_cell:contains("Password reset"):eq(0)',
- },
- {
- content: "check the link has the current host, save the link, logout",
- trigger: 'div.oe_form_field_html[name="body_html"] a:contains("Change password")[href^="' + currentDomain + '"]',
- run: function () {
- var link = $('div.oe_form_field_html[name="body_html"] a:contains("Change password")').attr('href');
- localStorage.setItem(resetLinkKey, link);
- window.location.href = "/web/session/logout?redirect=/";
- },
- },
- {
- content: "go to the reset link",
- trigger: 'a[href="/web/login"]',
- run: function () {
- window.location.href = localStorage.getItem(resetLinkKey);
- },
- },
+}, [
{
content: "fill new password",
trigger: '.oe_reset_password_form input[name="password"]',
@@ -153,7 +25,7 @@ tour.register('website_reset_password', {
},
{
content: "check that we're logged in",
- trigger: '.oe_topbar_name:contains("Admin")',
+ trigger: '.oe_topbar_name:contains("The King")',
run: function () {}
},
{
diff --git a/addons/website/tests/test_website_reset_password.py b/addons/website/tests/test_website_reset_password.py
index 40928732dad..a8ec713cc8a 100644
--- a/addons/website/tests/test_website_reset_password.py
+++ b/addons/website/tests/test_website_reset_password.py
@@ -31,4 +31,32 @@ class TestWebsiteResetPassword(HttpCase):
return original_send_mail(*args, **kwargs)
with patch.object(MailMail, 'unlink', lambda self: None), patch.object(MailTemplate, 'send_mail', my_send_mail):
- self.start_tour("/", 'website_reset_password', login="admin")
+ user = self.env['res.users'].create({
+ 'login': 'test',
+ 'name': 'The King',
+ 'email': 'noop@example.com',
+ })
+ website_1 = self.env['website'].browse(1)
+ website_2 = self.env['website'].browse(2)
+
+ website_1.domain = "my-test-domain.com"
+ website_2.domain = "https://domain-not-used.fr"
+
+ user.partner_id.website_id = 2
+ user.invalidate_cache() # invalidate get_base_url
+
+ user.action_reset_password()
+ self.assertIn(website_2.domain, user.signup_url)
+
+ user.invalidate_cache()
+
+ user.partner_id.website_id = 1
+ user.action_reset_password()
+ self.assertIn(website_1.domain, user.signup_url)
+
+ (website_1 + website_2).domain = ""
+
+ user.action_reset_password()
+ user.invalidate_cache()
+
+ self.start_tour(user.signup_url, 'website_reset_password', login=None)