Skip to content
Permalink
Browse files

[IMP] test_website: add test tour for the website errors

The purpose of these tests is to verify that errors informations
are displayed correctly on the website.

Related to task-1894820
  • Loading branch information...
fja-odoo committed Apr 4, 2019
1 parent 17102a0 commit d775aebab2369388d6a219cf90787d32e6ec90dc
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import http
import werkzeug

from odoo import http, exceptions
from odoo.http import request
from odoo.addons.portal.controllers.web import Home

@@ -11,3 +13,55 @@ class WebsiteTest(Home):
@http.route('/test_view', type='http', auth="public", website=True)
def test_view(self, **kw):
return request.render('test_website.test_view')

@http.route('/test_error_view', type='http', auth="public", website=True)
def test_error_view(self, **kw):
return request.render('test_website.test_error_view')

@http.route('/test_user_error_http', type='http', auth="public", website=True)
def test_user_error_http(self, **kw):
raise exceptions.UserError('This is a user http test')

@http.route('/test_user_error_json', type='json', auth="public", website=True)
def test_user_error_json(self, **kw):
raise exceptions.UserError('This is a user rpc test')

@http.route('/test_validation_error_http', type='http', auth="public", website=True)
def test_validation_error_http(self, **kw):
raise exceptions.ValidationError('This is a validation http test')

@http.route('/test_validation_error_json', type='json', auth="public", website=True)
def test_validation_error_json(self, **kw):
raise exceptions.ValidationError('This is a validation rpc test')

@http.route('/test_access_error_json', type='json', auth="public", website=True)
def test_access_error_json(self, **kw):
raise exceptions.AccessError('This is an access rpc test')

@http.route('/test_access_error_http', type='http', auth="public", website=True)
def test_access_error_http(self, **kw):
raise exceptions.AccessError('This is an access http test')

@http.route('/test_missing_error_json', type='json', auth="public", website=True)
def test_missing_error_json(self, **kw):
raise exceptions.MissingError('This is a missing rpc test')

@http.route('/test_missing_error_http', type='http', auth="public", website=True)
def test_missing_error_http(self, **kw):
raise exceptions.MissingError('This is a missing http test')

@http.route('/test_internal_error_json', type='json', auth="public", website=True)
def test_internal_error_json(self, **kw):
raise werkzeug.exceptions.InternalServerError()

@http.route('/test_internal_error_http', type='http', auth="public", website=True)
def test_internal_error_http(self, **kw):
raise werkzeug.exceptions.InternalServerError()

@http.route('/test_access_denied_json', type='json', auth="public", website=True)
def test_denied_error_json(self, **kw):
raise exceptions.AccessDenied('This is an access denied rpc test')

@http.route('/test_access_denied_http', type='http', auth="public", website=True)
def test_denied_error_http(self, **kw):
raise exceptions.AccessDenied('This is an access denied rpc test')
@@ -30,6 +30,37 @@
</t>
</field>
</record>
<record id="test_error_view" model="ir.ui.view">
<field name="name">Test Error View</field>
<field name="type">qweb</field>
<field name="key">test_website.test_error_view</field>
<field name="arch" type="xml">
<t name="Test Error View" priority="29" t-name="test_website.test_error_view">
<t t-call="website.layout">
<xpath expr="link[last()]" position="inside">
<script type="text/javascript" src="/test_website/static/src/js/test_error.js"/>
</xpath>
<div id="oe_structure_test_website_page" class="oe_structure oe_empty"/>
<h1>Test Error View</h1>
<a href="/test_user_error_http">Http UserError</a><br/>
<a href="/test_validation_error_http">Http ValidationError</a><br/>
<a href="/test_access_error_http">Http AccessError</a><br/>
<a href="/test_missing_error_http">Http MissingError</a><br/>
<a href="/test_internal_error_http">Http InternalServerError</a><br/>
<a href="/test_access_denied_http">Http AccessDenied</a><br/>
<br/>
<div class="test_error">
<a href="/test_user_error_json" class="rpc_error">Rpc UserError</a><br/>
<a href="/test_validation_error_json" class="rpc_error">Rpc ValidationError</a><br/>
<a href="/test_access_error_json" class="rpc_error">Rpc AccessError</a><br/>
<a href="/test_missing_error_json" class="rpc_error">Rpc MissingError</a><br/>
<a href="/test_internal_error_json" class="rpc_error">Rpc InternalServerError</a><br/>
<a href="/test_access_denied_json" class="rpc_error">Rpc AccessDenied</a><br/>
</div>
</t>
</t>
</field>
</record>
<record id="test_page" model="website.page">
<field name="website_published">True</field>
<field name="url">/test_page_view</field>
@@ -0,0 +1,253 @@
odoo.define('test_website.error_views', function (require) {
'use strict';

var tour = require("web_tour.tour");

tour.register('test_error_website', {
test: true,
},
[
// RPC ERROR
{
content: "trigger rpc user error",
trigger: "body",
run: function () {
this._rpc({
route: "/test_user_error_json",
});
}
},
{
content: "rpc user error modal has message",
extra_trigger: "div.o_dialog_warning.modal-body:contains('This is a user rpc test')",
trigger: "button.btn.btn-primary"
},
{
content: "trigger rpc access error",
trigger: "body",
run: function () {
this._rpc({
route: "/test_access_error_json",
});
}
},
{
content: "rpc access error modal has message",
extra_trigger: "div.o_dialog_warning.modal-body:contains('This is an access rpc test')",
trigger: "button.btn.btn-primary"
},
{
content: "trigger validation rpc error",
trigger: "body",
run: function () {
this._rpc({
route: "/test_validation_error_json",
});
}
},
{
content: "rpc validation error modal has message",
extra_trigger: "div.o_dialog_warning.modal-body:contains('This is a validation rpc test')",
trigger: "button.btn.btn-primary"
},
{
content: "trigger rpc missing error",
trigger: "body",
run: function () {
this._rpc({
route: "/test_missing_error_json",
});
}
},
{
content: "rpc missing error modal has message",
extra_trigger: "div.o_dialog_warning.modal-body:contains('This is a missing rpc test')",
trigger: "button.btn.btn-primary"
},
{
content: "trigger rpc error 403",
trigger: "body",
run: function () {
this._rpc({
route: "/test_access_denied_json",
});
}
},
{
content: "rpc error 403 modal has message",
extra_trigger: "div.o_dialog_warning.modal-body:contains('This is an access denied rpc test')",
trigger: "button.btn.btn-primary"
},
{
content: "trigger rpc error 500",
trigger: "body",
run: function () {
this._rpc({
route: "/test_internal_error_json",
});
}
},
{
content: "rpc error 500 modal is an ErrorDialog",
extra_trigger: "div.o_dialog_error.modal-body div.alert.alert-warning",
trigger: "button.btn.btn-primary[type='button']"
},
// HTTP ERROR
{
content: "trigger http user error",
trigger: "body",
run: function () {
window.location.href = window.location.origin + '/test_user_error_http';
}
},
{
content: "http user error page has title and message",
extra_trigger: "h1.mt32:contains('Oops! Something went wrong.')",
trigger: "div.container pre:contains('This is a user http test')",
run: function () {}
},
{
content: "trigger http user error debug",
trigger: "body",
run: function () {
window.location.href = window.location.origin + '/test_user_error_http?debug';
}
},
{
content: "http user error page debug has title and message open",
extra_trigger: "h1.mt32:contains('Oops! Something went wrong.')",
trigger: "div#error_main.collapse.show pre:contains('This is a user http test')",
run: function () {}
},
{
content: "http user error page debug has traceback closed",
trigger: "body:has(div#error_traceback.collapse:not(.show) pre#exception_traceback)",
run: function () {}
},
{
content: "trigger http validation error",
trigger: "body",
run: function () {
window.location.href = window.location.origin + '/test_validation_error_http';
}
},
{
content: "http validation error page has title and message",
extra_trigger: "h1.mt32:contains('Oops! Something went wrong.')",
trigger: "div.container pre:contains('This is a validation http test')",
run: function () {}
},
{
content: "trigger http validation error debug",
trigger: "body",
run: function () {
window.location.href = window.location.origin + '/test_validation_error_http?debug';
}
},
{
content: "http validation error page debug has title and message open",
extra_trigger: "h1.mt32:contains('Oops! Something went wrong.')",
trigger: "div#error_main.collapse.show pre:contains('This is a validation http test')",
run: function () {}
},
{
content: "http validation error page debug has traceback closed",
trigger: "body:has(div#error_traceback.collapse:not(.show) pre#exception_traceback)",
run: function () {}
},
{
content: "trigger http access error",
trigger: "body",
run: function () {
window.location.href = window.location.origin + '/test_access_error_http';
}
},
{
content: "http access error page has title and message",
extra_trigger: "h1.mt32:contains('403: Forbidden')",
trigger: "div.container pre:contains('This is an access http test')",
run: function () {}
},
{
content: "trigger http access error debug",
trigger: "body",
run: function () {
window.location.href = window.location.origin + '/test_access_error_http?debug';
}
},
{
content: "http access error page debug has title and message open",
extra_trigger: "h1.mt32:contains('403: Forbidden')",
trigger: "div#error_main.collapse.show pre:contains('This is an access http test')",
run: function () {}
},
{
content: "http access error page debug has traceback closed",
trigger: "body:has(div#error_traceback.collapse:not(.show) pre#exception_traceback)",
run: function () {}
},
{
content: "trigger http missing error",
trigger: "body",
run: function () {
window.location.href = window.location.origin + '/test_missing_error_http';
}
},
{
content: "http missing error page has title and message",
extra_trigger: "h1.mt32:contains('Oops! Something went wrong.')",
trigger: "div.container pre:contains('This is a missing http test')",
run: function () {}
},
{
content: "trigger http missing error debug",
trigger: "body",
run: function () {
window.location.href = window.location.origin + '/test_missing_error_http?debug';
}
},
{
content: "http missing error page debug has title and message open",
extra_trigger: "h1.mt32:contains('Oops! Something went wrong.')",
trigger: "div#error_main.collapse.show pre:contains('This is a missing http test')",
run: function () {}
},
{
content: "http missing error page debug has traceback closed",
trigger: "body:has(div#error_traceback.collapse:not(.show) pre#exception_traceback)",
run: function () {}
},
{
content: "trigger http error 403",
trigger: "body",
run: function () {
window.location.href = window.location.origin + '/test_access_denied_http';
}
},
{
content: "http error 403 page has title but no message",
extra_trigger: "h1.mt32:contains('403: Forbidden')",
trigger: "div.container:not(pre:contains('This is an access denied http test'))", //See ir_http.py handle_exception, the exception is replaced so there is no message !
run: function () {}
},
{
content: "trigger http 403 error debug",
trigger: "body",
run: function () {
window.location.href = window.location.origin + '/test_access_denied_http?debug';
}
},
{
content: "http 403 error page debug has title but no message",
extra_trigger: "h1.mt32:contains('403: Forbidden')",
trigger: "div#debug_infos:not(:has(#error_main))",
run: function () {}
},
{
content: "http 403 error page debug has traceback open",
trigger: "body:has(div#error_traceback.collapse.show pre#exception_traceback)",
run: function () {}
},
]
);
});
@@ -0,0 +1,24 @@
odoo.define('website_forum.test_error', function (require) {
'use strict';

var publicWidget = require('web.public.widget');

publicWidget.registry.testError = publicWidget.Widget.extend({
selector: '.test_error',
events: {
'click .rpc_error': '_onRpcErrorClick',
},

/**
* @private
* @param {Event} ev
*/
_onRpcErrorClick: function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
this._rpc({
route: $link.attr('href'),
});
}
});
});
@@ -2,4 +2,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import test_reset_views
from . import test_error
from . import test_views_during_module_operation
Oops, something went wrong.

0 comments on commit d775aeb

Please sign in to comment.
You can’t perform that action at this time.