|
@ -1,22 +1,22 @@ |
|
|
openerp.testing.section( 'web_readonly_bypass', {}, |
|
|
|
|
|
function(test){ |
|
|
|
|
|
test('ignore_readonly', function(instance){ |
|
|
|
|
|
|
|
|
odoo.define_section('web_readonly_bypass', ['web_readonly_bypass'], function(test) { |
|
|
|
|
|
"use strict"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('ignore_readonly', function(assert, ro_bypass){ |
|
|
var data = {}; |
|
|
var data = {}; |
|
|
var mode_create = true; |
|
|
var mode_create = true; |
|
|
var options = {}; |
|
|
var options = {}; |
|
|
var context = {}; |
|
|
var context = {}; |
|
|
instance.web_readonly_bypass.ignore_readonly(data, options, |
|
|
|
|
|
mode_create, context); |
|
|
|
|
|
deepEqual(data, |
|
|
|
|
|
|
|
|
ro_bypass.ignore_readonly(data, options, mode_create, context); |
|
|
|
|
|
assert.deepEqual(data, |
|
|
{}, |
|
|
{}, |
|
|
"Empty context and options mode create" |
|
|
"Empty context and options mode create" |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
mode_create = false; |
|
|
mode_create = false; |
|
|
data = {}; |
|
|
data = {}; |
|
|
instance.web_readonly_bypass.ignore_readonly(data, options, |
|
|
|
|
|
mode_create, context); |
|
|
|
|
|
deepEqual(data, |
|
|
|
|
|
|
|
|
ro_bypass.ignore_readonly(data, options, mode_create, context); |
|
|
|
|
|
assert.deepEqual(data, |
|
|
{}, |
|
|
{}, |
|
|
"Empty context and options mode write" |
|
|
"Empty context and options mode write" |
|
|
); |
|
|
); |
|
@ -27,9 +27,9 @@ function(test){ |
|
|
options = {'readonly_fields': {'field_1': 'va1-1', |
|
|
options = {'readonly_fields': {'field_1': 'va1-1', |
|
|
'field_2': false, |
|
|
'field_2': false, |
|
|
'field_3': 'val-3'}}; |
|
|
'field_3': 'val-3'}}; |
|
|
instance.web_readonly_bypass.ignore_readonly(data, options, |
|
|
|
|
|
mode_create, context); |
|
|
|
|
|
deepEqual(data, |
|
|
|
|
|
|
|
|
ro_bypass.ignore_readonly(data, options, mode_create, context); |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(data, |
|
|
{'field_1': 'va1-1', 'field_2': false, 'field_3': 'val-3'}, |
|
|
{'field_1': 'va1-1', 'field_2': false, 'field_3': 'val-3'}, |
|
|
"all fields mode write" |
|
|
"all fields mode write" |
|
|
); |
|
|
); |
|
@ -40,9 +40,9 @@ function(test){ |
|
|
options = {'readonly_fields': {'field_1': 'va1-1', |
|
|
options = {'readonly_fields': {'field_1': 'va1-1', |
|
|
'field_2': false, |
|
|
'field_2': false, |
|
|
'field_3': 'val-3'}}; |
|
|
'field_3': 'val-3'}}; |
|
|
instance.web_readonly_bypass.ignore_readonly(data, options, |
|
|
|
|
|
mode_create, context); |
|
|
|
|
|
deepEqual(data, |
|
|
|
|
|
|
|
|
ro_bypass.ignore_readonly(data, options, mode_create, context); |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(data, |
|
|
{'field_1': 'va1-1', 'field_3': 'val-3'}, |
|
|
{'field_1': 'va1-1', 'field_3': 'val-3'}, |
|
|
"all fields mode create (false value are escaped)" |
|
|
"all fields mode create (false value are escaped)" |
|
|
); |
|
|
); |
|
@ -53,61 +53,61 @@ function(test){ |
|
|
options = {'readonly_fields': {'field_1': 'va1-1', |
|
|
options = {'readonly_fields': {'field_1': 'va1-1', |
|
|
'field_2': false, |
|
|
'field_2': false, |
|
|
'field_3': 'val-3'}}; |
|
|
'field_3': 'val-3'}}; |
|
|
instance.web_readonly_bypass.ignore_readonly(data, options, |
|
|
|
|
|
mode_create, context); |
|
|
|
|
|
deepEqual(data, |
|
|
|
|
|
|
|
|
ro_bypass.ignore_readonly(data, options, mode_create, context); |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(data, |
|
|
{}, |
|
|
{}, |
|
|
"without context, default, we won't save readonly fields" |
|
|
"without context, default, we won't save readonly fields" |
|
|
); |
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
test('retrieve_readonly_by_pass_fields', function(instance){ |
|
|
|
|
|
|
|
|
test('retrieve_readonly_by_pass_fields', ['web_readonly_bypass'], function(assert, ro_bypass){ |
|
|
var context = {'readonly_by_pass': true} |
|
|
var context = {'readonly_by_pass': true} |
|
|
var options = {'readonly_fields': {'field_1': 'va1-1', |
|
|
var options = {'readonly_fields': {'field_1': 'va1-1', |
|
|
'field_2': 'val-2', |
|
|
'field_2': 'val-2', |
|
|
'field_3': 'val-3'}}; |
|
|
'field_3': 'val-3'}}; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{'field_1': 'va1-1', 'field_2': 'val-2', 'field_3': 'val-3'}, |
|
|
{'field_1': 'va1-1', 'field_2': 'val-2', 'field_3': 'val-3'}, |
|
|
"All fields should be accepted!" |
|
|
"All fields should be accepted!" |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
context = {'readonly_by_pass': ['field_1', 'field_3']}; |
|
|
context = {'readonly_by_pass': ['field_1', 'field_3']}; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{'field_1': 'va1-1','field_3': 'val-3'}, |
|
|
{'field_1': 'va1-1','field_3': 'val-3'}, |
|
|
"two field s1" |
|
|
"two field s1" |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
context = {'readonly_by_pass': ['field_1',]}; |
|
|
context = {'readonly_by_pass': ['field_1',]}; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{'field_1': 'va1-1'}, |
|
|
{'field_1': 'va1-1'}, |
|
|
"Only field 1" |
|
|
"Only field 1" |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
context = {'readonly_by_pass': []}; |
|
|
context = {'readonly_by_pass': []}; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{}, |
|
|
{}, |
|
|
"Empty context field" |
|
|
"Empty context field" |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
context = null; |
|
|
context = null; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{}, |
|
|
{}, |
|
|
"Null context" |
|
|
"Null context" |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
context = false; |
|
|
context = false; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{}, |
|
|
{}, |
|
|
"false context" |
|
|
"false context" |
|
@ -115,8 +115,8 @@ function(test){ |
|
|
|
|
|
|
|
|
context = {'readonly_by_pass': true} |
|
|
context = {'readonly_by_pass': true} |
|
|
options = {'readonly_fields': {'field_1': 'va1-1'}}; |
|
|
options = {'readonly_fields': {'field_1': 'va1-1'}}; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{'field_1': 'va1-1'}, |
|
|
{'field_1': 'va1-1'}, |
|
|
"Only one option" |
|
|
"Only one option" |
|
@ -124,40 +124,40 @@ function(test){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
options = {'readonly_fields': {}}; |
|
|
options = {'readonly_fields': {}}; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{}, |
|
|
{}, |
|
|
"Empty readonly_fields option" |
|
|
"Empty readonly_fields option" |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
options = {}; |
|
|
options = {}; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{}, |
|
|
{}, |
|
|
"Empty option" |
|
|
"Empty option" |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
options = null; |
|
|
options = null; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{}, |
|
|
{}, |
|
|
"null option" |
|
|
"null option" |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
options = false; |
|
|
options = false; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{}, |
|
|
{}, |
|
|
"false option" |
|
|
"false option" |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
context = false; |
|
|
context = false; |
|
|
deepEqual( |
|
|
|
|
|
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
|
|
ro_bypass.retrieve_readonly_by_pass_fields( |
|
|
options, context), |
|
|
options, context), |
|
|
{}, |
|
|
{}, |
|
|
"false option and false context" |
|
|
"false option and false context" |
|
|