From 998843d53157d4c6dc2558320e4fe162a9a1bc6b Mon Sep 17 00:00:00 2001 From: tarteo Date: Fri, 24 Feb 2017 09:28:04 +0100 Subject: [PATCH] [ADD] Tests --- web_shortcut/models/__init__.py | 1 + web_shortcut/models/ir_ui_menu.py | 13 ++++++++++++ web_shortcut/models/web_shortcut.py | 11 ---------- web_shortcut/tests/__init__.py | 1 + web_shortcut/tests/test_web_shortcut.py | 27 +++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 web_shortcut/models/ir_ui_menu.py create mode 100644 web_shortcut/tests/__init__.py create mode 100644 web_shortcut/tests/test_web_shortcut.py diff --git a/web_shortcut/models/__init__.py b/web_shortcut/models/__init__.py index 0ff5f169..08a8efd7 100644 --- a/web_shortcut/models/__init__.py +++ b/web_shortcut/models/__init__.py @@ -28,3 +28,4 @@ # from . import web_shortcut +from . import ir_ui_menu diff --git a/web_shortcut/models/ir_ui_menu.py b/web_shortcut/models/ir_ui_menu.py new file mode 100644 index 00000000..74fdaef8 --- /dev/null +++ b/web_shortcut/models/ir_ui_menu.py @@ -0,0 +1,13 @@ +from openerp import models, fields, api + + +class IrUiView(models.Model): + _inherit = 'ir.ui.menu' + + @api.multi + def unlink(self): + res = super(IrUiView, self).unlink() + shortcuts = self.env['web.shortcut'].search([('menu_id', '=', False)]) + for shortcut in shortcuts: + shortcut.unlink() + return res diff --git a/web_shortcut/models/web_shortcut.py b/web_shortcut/models/web_shortcut.py index ffe6a854..10818975 100644 --- a/web_shortcut/models/web_shortcut.py +++ b/web_shortcut/models/web_shortcut.py @@ -53,14 +53,3 @@ class WebShortcut(models.Model): ) return res - -class IrUiView(models.Model): - _inherit = 'ir.ui.menu' - - @api.multi - def unlink(self): - res = super(IrUiView, self).unlink() - shortcuts = self.env['web.shortcut'].search([('menu_id', '=', False)]) - for shortcut in shortcuts: - shortcut.unlink() - return res diff --git a/web_shortcut/tests/__init__.py b/web_shortcut/tests/__init__.py new file mode 100644 index 00000000..cc77db54 --- /dev/null +++ b/web_shortcut/tests/__init__.py @@ -0,0 +1 @@ +from . import test_web_shortcut diff --git a/web_shortcut/tests/test_web_shortcut.py b/web_shortcut/tests/test_web_shortcut.py new file mode 100644 index 00000000..f4c0b222 --- /dev/null +++ b/web_shortcut/tests/test_web_shortcut.py @@ -0,0 +1,27 @@ +from openerp.tests.common import HttpCase, TransactionCase + + +class TestWebShortcut(TransactionCase): + def setUp(self, *args, **kwargs): + super(TestWebShortcut, self).setUp(*args, **kwargs) + self.shortcut_obj = self.env['web.shortcut'] + self.menu_obj = self.env['ir.ui.menu'] + + self.menu = self.env.ref('base.menu_ir_property') + self.user = self.env.ref('base.user_root') + + self.shortcut_obj.search([('user_id', '=', self.user.id)]).unlink() + + def test_web_shortcut(self): + res = self.shortcut_obj.get_user_shortcuts() + self.assertEqual(len(res), 0) + self.shortcut_obj.create({ + 'name': 'Test', + 'menu_id': self.menu.id, + 'user_id': self.env.user.id + }) + res = self.shortcut_obj.get_user_shortcuts() + self.assertEqual(len(res), 1) + self.menu.unlink() + res = self.shortcut_obj.get_user_shortcuts() + self.assertEqual(len(res), 0)