From 01077d3e3450d87652989d68c1df774e2b9d0484 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Wed, 2 Nov 2016 13:30:41 +0100 Subject: [PATCH 1/2] [FIX][web_duplicate_visibility] Run tests. Tests were not run in bots. Includes some cosmetic fixes. --- web_duplicate_visibility/README.rst | 6 +-- web_duplicate_visibility/__openerp__.py | 8 ++-- .../static/test/duplicate_visibility.js | 38 +++++++++---------- web_duplicate_visibility/tests/__init__.py | 5 +++ web_duplicate_visibility/tests/test_js.py | 14 +++++++ 5 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 web_duplicate_visibility/tests/__init__.py create mode 100644 web_duplicate_visibility/tests/test_js.py diff --git a/web_duplicate_visibility/README.rst b/web_duplicate_visibility/README.rst index 5fc4ce93..269d40bf 100644 --- a/web_duplicate_visibility/README.rst +++ b/web_duplicate_visibility/README.rst @@ -46,10 +46,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, -help us smashing it by providing a detailed and welcomed `feedback -`_. +help us smashing it by providing a detailed and welcomed feedback. Credits ======= @@ -66,6 +63,7 @@ Contributors * Pierre Verkest * Christophe Combelles * Simon André +* Jairo Llopis Maintainer ---------- diff --git a/web_duplicate_visibility/__openerp__.py b/web_duplicate_visibility/__openerp__.py index 7399f90c..cdb6c1bb 100644 --- a/web_duplicate_visibility/__openerp__.py +++ b/web_duplicate_visibility/__openerp__.py @@ -4,16 +4,16 @@ { "name": "web duplicate visibility", "summary": "Manage the duplicate button visibiliy", - "version": "9.0.1.0.0", + "version": "9.0.1.0.1", "category": "web", "website": "https://odoo-community.org/", - "author": "Pierre Verkest ," - " Odoo Community Association (OCA)", + "author": "Pierre Verkest , " + "Tecnativa, " + "Odoo Community Association (OCA)", "license": "AGPL-3", "application": False, "installable": True, "depends": [ - "base", "web", ], "data": [ diff --git a/web_duplicate_visibility/static/test/duplicate_visibility.js b/web_duplicate_visibility/static/test/duplicate_visibility.js index 7addfc45..ada7b26f 100644 --- a/web_duplicate_visibility/static/test/duplicate_visibility.js +++ b/web_duplicate_visibility/static/test/duplicate_visibility.js @@ -1,9 +1,11 @@ -"use strict"; +/* Copyright 2016 Jairo Llopis + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ odoo.define_section('web_duplicate_visibility', ['web.data', 'web.FormView'], function(test, mock){ + "use strict"; - function assertDuplicate(data, FormView, form_tag, visible){ + function assertDuplicate(assert, data, FormView, form_tag, visible) { mock.add('test.model:read', function () { return [{ id: 1, a: 'foo', b: 'bar', c: 'baz' }]; }); @@ -45,38 +47,32 @@ odoo.define_section('web_duplicate_visibility', return obj.text.trim() == "Duplicate"; } ); - strictEqual( + assert.strictEqual( actions.length, visible, "duplicate state is not as expected" ); }; + function compare(form_tag, visible) { + return function (assert, data, FormView) { + return assertDuplicate(assert, data, FormView, form_tag, visible); + } + } + test('Duplicate button visible when nothing set', - function(assert, data, FormView){ - assertDuplicate(data, FormView, '
', 1); - }); + compare('', 1)); test('Duplicate button visible when create="1"', - function(assert, data, FormView){ - assertDuplicate(data, FormView, '', 1); - }); + compare('', 1)); test('Duplicate button visible when duplicate="1"', - function(assert, data, FormView){ - assertDuplicate(data, FormView, '', 1); - }); + compare('', 1)); test('Duplicate button not displayed when create="0"', - function(assert, data, FormView){ - assertDuplicate(data, FormView, '', 0); - }); + compare('', 0)); test('Duplicate button not displayed when create="1" duplicate="0"', - function(assert, data, FormView){ - assertDuplicate(data, FormView, '', 0); - }); + compare('', 0)); test('Duplicate button not displayed when duplicate="0"', - function(assert, data, FormView){ - assertDuplicate(data, FormView, '', 0); - }); + compare('', 0)); }); diff --git a/web_duplicate_visibility/tests/__init__.py b/web_duplicate_visibility/tests/__init__.py new file mode 100644 index 00000000..577699be --- /dev/null +++ b/web_duplicate_visibility/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_js diff --git a/web_duplicate_visibility/tests/test_js.py b/web_duplicate_visibility/tests/test_js.py new file mode 100644 index 00000000..c3f5575e --- /dev/null +++ b/web_duplicate_visibility/tests/test_js.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Jairo Llopis +# 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_duplicate_visibility", + "", + login="admin", + ) From 8a852be42a0b12cf597b9975cee95e7dbf230085 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Wed, 2 Nov 2016 13:32:26 +0100 Subject: [PATCH 2/2] [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. --- web_readonly_bypass/README.rst | 18 +- web_readonly_bypass/__openerp__.py | 6 +- .../static/src/js/readonly_bypass.js | 2 +- .../static/test/web_readonly_bypass.js | 329 +++++++++--------- web_readonly_bypass/tests/__init__.py | 5 + web_readonly_bypass/tests/test_js.py | 14 + 6 files changed, 200 insertions(+), 174 deletions(-) create mode 100644 web_readonly_bypass/tests/__init__.py create mode 100644 web_readonly_bypass/tests/test_js.py diff --git a/web_readonly_bypass/README.rst b/web_readonly_bypass/README.rst index ffd799b0..61b86857 100644 --- a/web_readonly_bypass/README.rst +++ b/web_readonly_bypass/README.rst @@ -42,17 +42,20 @@ For further information, please visit: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/162/8.0 + :target: https://runbot.odoo-community.org/runbot/162/9.0 +Known issues / Roadmap +====================== + +* Migrate to v9 JS API both normal code and QUnit tests. Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. -In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback -`here `_. - +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. Credits ======= @@ -63,6 +66,7 @@ Contributors * Jonathan Nemry * Laetitia Gangloff * Pierre Verkest +* Jairo Llopis Maintainer ---------- @@ -77,4 +81,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. diff --git a/web_readonly_bypass/__openerp__.py b/web_readonly_bypass/__openerp__.py index 39384f20..7ff2df95 100644 --- a/web_readonly_bypass/__openerp__.py +++ b/web_readonly_bypass/__openerp__.py @@ -24,8 +24,10 @@ ############################################################################## { 'name': 'Read Only ByPass', - 'version': '9.0.1.0.0', - "author": "ACSONE SA/NV, Odoo Community Association (OCA)", + 'version': '9.0.1.0.1', + "author": "ACSONE SA/NV, " + "Tecnativa, " + "Odoo Community Association (OCA)", "maintainer": "ACSONE SA/NV,Odoo Community Association (OCA)", "website": "http://www.acsone.eu", 'category': 'Technical Settings', diff --git a/web_readonly_bypass/static/src/js/readonly_bypass.js b/web_readonly_bypass/static/src/js/readonly_bypass.js index ea3f460e..cc73f58b 100644 --- a/web_readonly_bypass/static/src/js/readonly_bypass.js +++ b/web_readonly_bypass/static/src/js/readonly_bypass.js @@ -1,5 +1,5 @@ -"use strict"; (function(){ + "use strict"; var instance = openerp; var QWeb = instance.web.qweb, _t = instance.web._t; diff --git a/web_readonly_bypass/static/test/web_readonly_bypass.js b/web_readonly_bypass/static/test/web_readonly_bypass.js index fbc44f72..78ac9bf6 100644 --- a/web_readonly_bypass/static/test/web_readonly_bypass.js +++ b/web_readonly_bypass/static/test/web_readonly_bypass.js @@ -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 + * 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'}}; - 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" + ); + }); }); diff --git a/web_readonly_bypass/tests/__init__.py b/web_readonly_bypass/tests/__init__.py new file mode 100644 index 00000000..577699be --- /dev/null +++ b/web_readonly_bypass/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_js diff --git a/web_readonly_bypass/tests/test_js.py b/web_readonly_bypass/tests/test_js.py new file mode 100644 index 00000000..5f1e060f --- /dev/null +++ b/web_readonly_bypass/tests/test_js.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Jairo Llopis +# 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", + )