[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.

Part of https://github.com/odoo/odoo/pull/32132
task-1894820
This commit is contained in:
fja-odoo
2019-06-28 08:53:52 +00:00
parent 83c1d56d2f
commit 90818fd083
7 changed files with 297 additions and 4 deletions
+58 -3
View File
@@ -1,16 +1,19 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import json
import werkzeug
from odoo import http
from odoo.http import request
from odoo.addons.portal.controllers.web import Home
import json
from odoo.exceptions import UserError, ValidationError, AccessError, MissingError, AccessError, AccessDenied
class WebsiteTest(Home):
@http.route('/test_view', type='http', auth="public", website=True)
def test_view(self, **kw):
@http.route('/test_view', type='http', auth='public', website=True)
def test_view(self, **kwargs):
return request.render('test_website.test_view')
@http.route('/ignore_args/converteronly/<string:a>/', type='http', auth="public", website=True)
@@ -40,3 +43,55 @@ class WebsiteTest(Home):
@http.route('/multi_company_website', type='http', auth="public", website=True)
def test_company_context(self):
return request.make_response(json.dumps(request.context.get('allowed_company_ids')))
@http.route('/test_error_view', type='http', auth='public', website=True)
def test_error_view(self, **kwargs):
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, **kwargs):
raise 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, **kwargs):
raise 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, **kwargs):
raise 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, **kwargs):
raise 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, **kwargs):
raise 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, **kwargs):
raise 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, **kwargs):
raise 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, **kwargs):
raise 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, **kwargs):
raise werkzeug.exceptions.InternalServerError()
@http.route('/test_internal_error_http', type='http', auth='public', website=True)
def test_internal_error_http(self, **kwargs):
raise werkzeug.exceptions.InternalServerError()
@http.route('/test_access_denied_json', type='json', auth='public', website=True)
def test_denied_error_json(self, **kwargs):
raise 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, **kwargs):
raise AccessDenied("This is an access denied http test")
@@ -30,6 +30,44 @@
</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" t-name="test_website.test_error_view">
<t t-call="website.layout">
<div class="container">
<h1>Test Error View</h1>
<div class="row">
<ul class="list-group http_error col-6">
<li class="list-group-item list-group-item-primary"><h2>http Errors</h2></li>
<li class="list-group-item"><a href="/test_user_error_http">http UserError (400)</a></li>
<li class="list-group-item"><a href="/test_validation_error_http">http ValidationError (400)</a></li>
<li class="list-group-item"><a href="/test_missing_error_http">http MissingError (400)</a></li>
<li class="list-group-item"><a href="/test_karma_error_http">http KarmaError (400)</a></li>
<li class="list-group-item"><a href="/test_access_error_http">http AccessError (403)</a></li>
<li class="list-group-item"><a href="/test_access_denied_http">http AccessDenied (403)</a></li>
<li class="list-group-item"><a href="/test_internal_error_http">http InternalServerError (500)</a></li>
<li class="list-group-item"><a href="/test_not_found_http">http NotFound (404)</a></li>
</ul>
<ul class="list-group rpc_error col-6">
<li class="list-group-item list-group-item-primary"><h2>rpc Warnings</h2></li>
<li class="list-group-item"><a href="/test_user_error_json">rpc UserError</a></li>
<li class="list-group-item"><a href="/test_validation_error_json">rpc ValidationError</a></li>
<li class="list-group-item"><a href="/test_missing_error_json">rpc MissingError</a></li>
<li class="list-group-item"><a href="/test_karma_error_json">rpc KarmaError</a></li>
<li class="list-group-item"><a href="/test_access_error_json">rpc AccessError</a></li>
<li class="list-group-item"><a href="/test_access_denied_json">rpc AccessDenied</a></li>
<li class="list-group-item list-group-item-primary"><h2>rpc Errors</h2></li>
<li class="list-group-item"><a href="/test_internal_error_json">rpc InternalServerError</a></li>
</ul>
</div>
</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,30 @@
odoo.define('website_forum.test_error', function (require) {
'use strict';
var publicWidget = require('web.public.widget');
publicWidget.registry.testError = publicWidget.Widget.extend({
selector: '.rpc_error',
events: {
'click a': '_onRpcErrorClick',
},
//----------------------------------------------------------------------
// Handlers
//----------------------------------------------------------------------
/**
* make a rpc call with the href of the DOM element clicked
* @private
* @param {Event} ev
* @returns {Promise}
*/
_onRpcErrorClick: function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
return this._rpc({
route: $link.attr('href'),
});
}
});
});
@@ -0,0 +1,152 @@
odoo.define('test_website.error_views', function (require) {
'use strict';
var tour = require('web_tour.tour');
tour.register('test_error_website', {
test: true,
url: '/test_error_view',
},
[
// RPC ERROR
{
content: "trigger rpc user error",
trigger: 'a[href="/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: 'a[href="/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: 'a[href="/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: 'a[href="/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: 'a[href="/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: 'a[href="/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?debug=0';
},
}, {
content: "http user error page has title and message",
extra_trigger: 'h1:contains("Oops! Something went wrong.")',
trigger: 'div.container pre:contains("This is a user http test")',
run: function () {
window.location.href = window.location.origin + '/test_user_error_http?debug=1';
},
}, {
content: "http user error page debug has title and message open",
extra_trigger: 'h1: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 () {
window.location.href = window.location.origin + '/test_validation_error_http?debug=0';
},
}, {
content: "http validation error page has title and message",
extra_trigger: 'h1:contains("Oops! Something went wrong.")',
trigger: 'div.container pre:contains("This is a validation http test")',
run: function () {
window.location.href = window.location.origin + '/test_validation_error_http?debug=1';
},
}, {
content: "http validation error page debug has title and message open",
extra_trigger: 'h1: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 () {
window.location.href = window.location.origin + '/test_access_error_http?debug=0';
},
}, {
content: "http access error page has title and message",
extra_trigger: 'h1:contains("403: Forbidden")',
trigger: 'div.container pre:contains("This is an access http test")',
run: function () {
window.location.href = window.location.origin + '/test_access_error_http?debug=1';
},
}, {
content: "http access error page debug has title and message open",
extra_trigger: 'h1: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 () {
window.location.href = window.location.origin + '/test_missing_error_http?debug=0';
},
}, {
content: "http missing error page has title and message",
extra_trigger: 'h1:contains("Oops! Something went wrong.")',
trigger: 'div.container pre:contains("This is a missing http test")',
run: function () {
window.location.href = window.location.origin + '/test_missing_error_http?debug=1';
},
}, {
content: "http missing error page debug has title and message open",
extra_trigger: 'h1: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 () {
window.location.href = window.location.origin + '/test_karma_error_http?debug=0';
},
}, {
content: "http error 403 page has title but no message",
extra_trigger: 'h1:contains("403: Forbidden")',
trigger: 'div#wrap:not(:has(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 () {
window.location.href = window.location.origin + '/test_access_denied_http?debug=1';
},
}, {
content: "http 403 error page debug has title but no message",
extra_trigger: 'h1: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 () {},
},
]);
});
+1
View File
@@ -3,5 +3,6 @@
from . import test_controller_args
from . import test_reset_views
from . import test_error
from . import test_views_during_module_operation
from . import test_multi_company
+10
View File
@@ -0,0 +1,10 @@
import odoo.tests
from odoo.tools import mute_logger
@odoo.tests.common.tagged('post_install', '-at_install')
class TestWebsiteError(odoo.tests.HttpCase):
@mute_logger('odoo.addons.website.models.ir_http', 'odoo.http')
def test_01_run_test(self):
self.start_tour("/test_error_view", 'test_error_website')
+8 -1
View File
@@ -1,8 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_frontend" inherit_id="website.assets_frontend">
<xpath expr="//script[last()]" position="after">
<script type="text/javascript" src="/test_website/static/src/js/test_error.js"></script>
</xpath>
</template>
<template id="assets_tests" name="Test Website Assets Tests" inherit_id="web.assets_tests">
<xpath expr="." position="inside">
<script type="text/javascript" src="/test_website/static/tests/tours/reset_views.js"></script>
<script type="text/javascript" src="/test_website/static/tests/tours/reset_views.js"></script>
<script type="text/javascript" src="/test_website/static/tests/tours/error_views.js"></script>
</xpath>
</template>
</odoo>