Permalink
Browse files

wip more test

  • Loading branch information...
seb-odoo committed Jan 11, 2019
1 parent 38ecbaf commit db1363f2ea280a7a7c61cf8163bd4b412125b7bb
@@ -0,0 +1,190 @@
odoo.define('website.tour_reset_password', function (require) {
'use strict';

var base = require('web_editor.base');
var localStorage = require('web.local_storage');
var rpc = require('web.rpc');
var tour = require('web_tour.tour');

var currentDomain = window.location.protocol + '//' + window.location.hostname;
var usersUrl = '/web?debug#action=base.action_res_users&view_type=list';
var resetLinkKey = 'website.tour_reset_password.resetLink';

tour.register('website_reset_password', {
test: true,
url: '/web',
wait_for: base.ready(),
},
[
{
content: "Change the domain of the websites and go to users page",
trigger: 'body',
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",
}],
});
$.when(def1, def2).then(function (data) {
window.location.href = usersUrl;
});
},
},
{
content: "click on Admin",
trigger: '.o_data_cell:contains("Admin")',
},
{
content: "click on partner",
trigger: '.o_field_widget[name="partner_id"]',
},
{
content: "click on Sales & Purchases",
trigger: 'a:contains("Sales & Purchases")',
},
{
content: "click on Edit",
trigger: '.o_form_button_edit',
},
{
content: "click on website",
trigger: '.o_field_widget[name="website_id"] input',
},
{
content: "type My on website",
trigger: '.o_field_widget[name="website_id"] input',
run: 'text My',
},
{
content: "click on My website",
trigger: '.ui-autocomplete a:contains("My Website")',
},
{
content: "wait website to be set",
trigger: '.o_field_widget.o_with_button[name="website_id"]',
run: function () {},
},
{
content: "click save",
trigger: '.o_form_button_save',
},
{
content: "wait save done",
trigger: '.o_form_button_edit',
run: function () {},
},
{
content: "go back to user",
trigger: '.o_back_button a',
},
{
content: "click on reset password",
trigger: '.btn[name="action_reset_password"]',
},
{
content: "wait mail to be sent, and go see it",
trigger: '.btn[name="action_reset_password"]',
run: function () {
window.location.href = "/web#action=mail.action_view_mail_mail&view_type=list";
},
},
{
content: "click on the first email",
trigger: '.o_data_cell:contains("Password reset")',
},
{
content: "check it's the correct email, and the URL is correct too",
trigger: 'iframe a:contains("Change password")[href^="http://my-test-domain.com"]',
},
{
content: "reset the domain of the websites, go to users page",
trigger: 'body',
run: function () {
rpc.query({
'model': 'website',
'method': 'write',
'args': [[1, 2], {
'domain': "",
}],
}).then(function (data) {
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: '.btn[name="action_reset_password"]',
run: function () {
window.location.href = "/web#action=mail.action_view_mail_mail&view_type=list";
},
},
{
content: "click on the first email",
trigger: '.o_data_cell:contains("Password reset")',
},
{
content: "check the link has the current host, save the link, logout",
trigger: 'iframe a:contains("Change password")[href^="' + currentDomain + '"]',
run: function () {
var link = $('iframe').contents().find('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 and submit",
trigger: '.oe_reset_password_form',
run: function () {
var $form = $('.oe_reset_password_form');
$form.find('input[name="password"]').val('admin');
$form.find('input[name="confirm_password"]').val('admin');
$form.find('button[type="submit"]').click();
},
},
{
content: "check logged in, and reset admin website",
trigger: '.oe_topbar_name:contains("Admin")',
run: function () {
rpc.query({
'model': 'res.partner',
'method': 'write',
'args': [[3], {
'website_id': false,
}],
});
},
},
]);
});
@@ -8,3 +8,4 @@
from . import test_views
from . import test_menu
from . import test_page
from . import test_website_reset_password
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

try:
from unittest.mock import patch
except ImportError:
from mock import patch

from odoo import api
from odoo.tests import tagged
from odoo.tests.common import HttpCase


@tagged('post_install', '-at_install')
class TestWebsiteResetPassword(HttpCase):

def test_01_website_reset_password_tour(self):
"""The goal of this test is to make sure the reset password works."""

@api.multi
def unlink(self):
print('no unlink', self)

# we override unlink because we don't want the email to be auto deleted
patcher = patch('odoo.addons.mail.models.mail_mail.MailMail.unlink', wraps=unlink)
patcher.start()
self.browser_js("/", "odoo.__DEBUG__.services['web_tour.tour'].run('website_reset_password')", "odoo.__DEBUG__.services['web_tour.tour'].tours.website_reset_password.ready", login="admin")
patcher.stop()
@@ -14,6 +14,12 @@
</xpath>
</template>

<template id="assets_common" name="Website Assets Common" inherit_id="web.assets_common">
<xpath expr="." position="inside">
<script type="text/javascript" src="/website/static/src/js/tours/website_tour_reset_password.js"></script>
</xpath>
</template>

<template id="assets_backend" inherit_id="web.assets_backend" name="Website Backend Assets (used in backend interface)">
<xpath expr="//link[last()]" position="after">
<link rel="stylesheet" type="text/scss" href="/website/static/src/scss/website.backend.scss"/>
@@ -5,6 +5,8 @@
from unittest.mock import patch
except ImportError:
from mock import patch

from odoo import api
from odoo.tests import tagged
from odoo.tests.common import HttpCase

@@ -15,8 +17,12 @@ class TestWebsiteSaleMail(HttpCase):
def test_01_shop_mail_tour(self):
"""The goal of this test is to make sure sending SO by email works."""

@api.multi
def unlink(self):
print('no unlink', self)

# we override unlink because we don't want the email to be auto deleted
patcher = patch('odoo.addons.mail.models.mail_mail.MailMail.unlink', wraps=lambda self: print('no unlink'))
patcher = patch('odoo.addons.mail.models.mail_mail.MailMail.unlink', wraps=unlink)
patcher.start()
self.browser_js("/", "odoo.__DEBUG__.services['web_tour.tour'].run('shop_mail')", "odoo.__DEBUG__.services['web_tour.tour'].tours.shop_mail.ready", login="admin")
patcher.stop()

0 comments on commit db1363f

Please sign in to comment.