Browse Source
[FIX][web_readonly_bypass] Fix wrong test suite.
[FIX][web_readonly_bypass] Fix wrong test suite.
- Test was not migrated to v9. - It is not still 100% migrated, but it works now. - Add to known issues that it must migrate. - Cosmetic fixes. - Run tests in bots always.pull/460/head
Jairo Llopis
8 years ago
6 changed files with 200 additions and 174 deletions
-
18web_readonly_bypass/README.rst
-
6web_readonly_bypass/__openerp__.py
-
2web_readonly_bypass/static/src/js/readonly_bypass.js
-
329web_readonly_bypass/static/test/web_readonly_bypass.js
-
5web_readonly_bypass/tests/__init__.py
-
14web_readonly_bypass/tests/test_js.py
@ -1,166 +1,167 @@ |
|||||
openerp.testing.section( 'web_readonly_bypass', {}, |
|
||||
function(test){ |
|
||||
test('ignore_readonly', function(instance){ |
|
||||
var data = {}; |
|
||||
var mode_create = true; |
|
||||
var options = {}; |
|
||||
var context = {}; |
|
||||
instance.web_readonly_bypass.ignore_readonly(data, options, |
|
||||
mode_create, context); |
|
||||
deepEqual(data, |
|
||||
{}, |
|
||||
"Empty context and options mode create" |
|
||||
); |
|
||||
|
|
||||
mode_create = false; |
|
||||
data = {}; |
|
||||
instance.web_readonly_bypass.ignore_readonly(data, options, |
|
||||
mode_create, context); |
|
||||
deepEqual(data, |
|
||||
{}, |
|
||||
"Empty context and options mode write" |
|
||||
); |
|
||||
|
|
||||
mode_create = false; |
|
||||
data = {}; |
|
||||
context = {'readonly_by_pass': true}; |
|
||||
options = {'readonly_fields': {'field_1': 'va1-1', |
|
||||
'field_2': false, |
|
||||
|
/* Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com> |
||||
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
||||
|
odoo.define_section('web_readonly_bypass', [], function(test) { |
||||
|
"use strict"; |
||||
|
test('ignore_readonly', function(assert) { |
||||
|
var data = {}; |
||||
|
var mode_create = true; |
||||
|
var options = {}; |
||||
|
var context = {}; |
||||
|
openerp.web_readonly_bypass.ignore_readonly(data, options, |
||||
|
mode_create, context); |
||||
|
assert.deepEqual(data, |
||||
|
{}, |
||||
|
"Empty context and options mode create" |
||||
|
); |
||||
|
|
||||
|
mode_create = false; |
||||
|
data = {}; |
||||
|
openerp.web_readonly_bypass.ignore_readonly(data, options, |
||||
|
mode_create, context); |
||||
|
assert.deepEqual(data, |
||||
|
{}, |
||||
|
"Empty context and options mode write" |
||||
|
); |
||||
|
|
||||
|
mode_create = false; |
||||
|
data = {}; |
||||
|
context = {'readonly_by_pass': true}; |
||||
|
options = {'readonly_fields': {'field_1': 'va1-1', |
||||
|
'field_2': false, |
||||
|
'field_3': 'val-3'}}; |
||||
|
openerp.web_readonly_bypass.ignore_readonly(data, options, |
||||
|
mode_create, context); |
||||
|
assert.deepEqual(data, |
||||
|
{'field_1': 'va1-1', 'field_2': false, 'field_3': 'val-3'}, |
||||
|
"all fields mode write" |
||||
|
); |
||||
|
|
||||
|
mode_create = true; |
||||
|
data = {}; |
||||
|
context = {'readonly_by_pass': true}; |
||||
|
options = {'readonly_fields': {'field_1': 'va1-1', |
||||
|
'field_2': false, |
||||
|
'field_3': 'val-3'}}; |
||||
|
openerp.web_readonly_bypass.ignore_readonly(data, options, |
||||
|
mode_create, context); |
||||
|
assert.deepEqual(data, |
||||
|
{'field_1': 'va1-1', 'field_3': 'val-3'}, |
||||
|
"all fields mode create (false value are escaped)" |
||||
|
); |
||||
|
|
||||
|
mode_create = true; |
||||
|
data = {}; |
||||
|
context = {}; |
||||
|
options = {'readonly_fields': {'field_1': 'va1-1', |
||||
|
'field_2': false, |
||||
|
'field_3': 'val-3'}}; |
||||
|
openerp.web_readonly_bypass.ignore_readonly(data, options, |
||||
|
mode_create, context); |
||||
|
assert.deepEqual(data, |
||||
|
{}, |
||||
|
"without context, default, we won't save readonly fields" |
||||
|
); |
||||
|
}); |
||||
|
|
||||
|
test('retrieve_readonly_by_pass_fields', function(assert) { |
||||
|
var context = {'readonly_by_pass': true} |
||||
|
var options = {'readonly_fields': {'field_1': 'va1-1', |
||||
|
'field_2': 'val-2', |
||||
'field_3': 'val-3'}}; |
'field_3': 'val-3'}}; |
||||
instance.web_readonly_bypass.ignore_readonly(data, options, |
|
||||
mode_create, context); |
|
||||
deepEqual(data, |
|
||||
{'field_1': 'va1-1', 'field_2': false, 'field_3': 'val-3'}, |
|
||||
"all fields mode write" |
|
||||
); |
|
||||
|
|
||||
mode_create = true; |
|
||||
data = {}; |
|
||||
context = {'readonly_by_pass': true}; |
|
||||
options = {'readonly_fields': {'field_1': 'va1-1', |
|
||||
'field_2': false, |
|
||||
'field_3': 'val-3'}}; |
|
||||
instance.web_readonly_bypass.ignore_readonly(data, options, |
|
||||
mode_create, context); |
|
||||
deepEqual(data, |
|
||||
{'field_1': 'va1-1', 'field_3': 'val-3'}, |
|
||||
"all fields mode create (false value are escaped)" |
|
||||
); |
|
||||
|
|
||||
mode_create = true; |
|
||||
data = {}; |
|
||||
context = {}; |
|
||||
options = {'readonly_fields': {'field_1': 'va1-1', |
|
||||
'field_2': false, |
|
||||
'field_3': 'val-3'}}; |
|
||||
instance.web_readonly_bypass.ignore_readonly(data, options, |
|
||||
mode_create, context); |
|
||||
deepEqual(data, |
|
||||
{}, |
|
||||
"without context, default, we won't save readonly fields" |
|
||||
); |
|
||||
}); |
|
||||
|
|
||||
test('retrieve_readonly_by_pass_fields', function(instance){ |
|
||||
var context = {'readonly_by_pass': true} |
|
||||
var options = {'readonly_fields': {'field_1': 'va1-1', |
|
||||
'field_2': 'val-2', |
|
||||
'field_3': 'val-3'}}; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{'field_1': 'va1-1', 'field_2': 'val-2', 'field_3': 'val-3'}, |
|
||||
"All fields should be accepted!" |
|
||||
); |
|
||||
|
|
||||
context = {'readonly_by_pass': ['field_1', 'field_3']}; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{'field_1': 'va1-1','field_3': 'val-3'}, |
|
||||
"two field s1" |
|
||||
); |
|
||||
|
|
||||
context = {'readonly_by_pass': ['field_1',]}; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{'field_1': 'va1-1'}, |
|
||||
"Only field 1" |
|
||||
); |
|
||||
|
|
||||
context = {'readonly_by_pass': []}; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{}, |
|
||||
"Empty context field" |
|
||||
); |
|
||||
|
|
||||
context = null; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{}, |
|
||||
"Null context" |
|
||||
); |
|
||||
|
|
||||
context = false; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{}, |
|
||||
"false context" |
|
||||
); |
|
||||
|
|
||||
context = {'readonly_by_pass': true} |
|
||||
options = {'readonly_fields': {'field_1': 'va1-1'}}; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{'field_1': 'va1-1'}, |
|
||||
"Only one option" |
|
||||
); |
|
||||
|
|
||||
|
|
||||
options = {'readonly_fields': {}}; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{}, |
|
||||
"Empty readonly_fields option" |
|
||||
); |
|
||||
|
|
||||
options = {}; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{}, |
|
||||
"Empty option" |
|
||||
); |
|
||||
|
|
||||
options = null; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{}, |
|
||||
"null option" |
|
||||
); |
|
||||
|
|
||||
options = false; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{}, |
|
||||
"false option" |
|
||||
); |
|
||||
|
|
||||
context = false; |
|
||||
deepEqual( |
|
||||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
||||
options, context), |
|
||||
{}, |
|
||||
"false option and false context" |
|
||||
); |
|
||||
}); |
|
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{'field_1': 'va1-1', 'field_2': 'val-2', 'field_3': 'val-3'}, |
||||
|
"All fields should be accepted!" |
||||
|
); |
||||
|
|
||||
|
context = {'readonly_by_pass': ['field_1', 'field_3']}; |
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{'field_1': 'va1-1','field_3': 'val-3'}, |
||||
|
"two field s1" |
||||
|
); |
||||
|
|
||||
|
context = {'readonly_by_pass': ['field_1',]}; |
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{'field_1': 'va1-1'}, |
||||
|
"Only field 1" |
||||
|
); |
||||
|
|
||||
|
context = {'readonly_by_pass': []}; |
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{}, |
||||
|
"Empty context field" |
||||
|
); |
||||
|
|
||||
|
context = null; |
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{}, |
||||
|
"Null context" |
||||
|
); |
||||
|
|
||||
|
context = false; |
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{}, |
||||
|
"false context" |
||||
|
); |
||||
|
|
||||
|
context = {'readonly_by_pass': true} |
||||
|
options = {'readonly_fields': {'field_1': 'va1-1'}}; |
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{'field_1': 'va1-1'}, |
||||
|
"Only one option" |
||||
|
); |
||||
|
|
||||
|
options = {'readonly_fields': {}}; |
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{}, |
||||
|
"Empty readonly_fields option" |
||||
|
); |
||||
|
|
||||
|
options = {}; |
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{}, |
||||
|
"Empty option" |
||||
|
); |
||||
|
|
||||
|
options = null; |
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{}, |
||||
|
"null option" |
||||
|
); |
||||
|
|
||||
|
options = false; |
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{}, |
||||
|
"false option" |
||||
|
); |
||||
|
|
||||
|
context = false; |
||||
|
assert.deepEqual( |
||||
|
openerp.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
||||
|
options, context), |
||||
|
{}, |
||||
|
"false option and false context" |
||||
|
); |
||||
|
}); |
||||
}); |
}); |
@ -0,0 +1,5 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from . import test_js |
@ -0,0 +1,14 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from openerp.tests import HttpCase |
||||
|
|
||||
|
|
||||
|
class TestJS(HttpCase): |
||||
|
def test_js(self): |
||||
|
self.phantom_js( |
||||
|
"/web/tests?module=web_readonly_bypass", |
||||
|
"", |
||||
|
login="admin", |
||||
|
) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue