From 7f0c6ca827fc4781264686828f5d4a10b966e87d Mon Sep 17 00:00:00 2001 From: aheficent Date: Mon, 17 Jul 2017 17:14:49 +0200 Subject: [PATCH] add test. FIx unlink --- bi_sql_editor/demo/bi_sql_view.xml | 4 +- bi_sql_editor/models/bi_sql_view.py | 2 +- bi_sql_editor/tests/__init__.py | 5 +++ bi_sql_editor/tests/test_bi_sql_view.py | 56 +++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 bi_sql_editor/tests/__init__.py create mode 100644 bi_sql_editor/tests/test_bi_sql_view.py diff --git a/bi_sql_editor/demo/bi_sql_view.xml b/bi_sql_editor/demo/bi_sql_view.xml index 75231916..29e1b767 100644 --- a/bi_sql_editor/demo/bi_sql_view.xml +++ b/bi_sql_editor/demo/bi_sql_view.xml @@ -5,7 +5,7 @@ Copyright (C) 2014 - Today GRAP (http://www.grap.coop) License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> - + Draft Incorrect SQL View @@ -32,8 +32,6 @@ ORDER BY name - - Modules by Authors modules_view diff --git a/bi_sql_editor/models/bi_sql_view.py b/bi_sql_editor/models/bi_sql_view.py index 685276a5..066f1bb9 100644 --- a/bi_sql_editor/models/bi_sql_view.py +++ b/bi_sql_editor/models/bi_sql_view.py @@ -148,7 +148,7 @@ class BiSQLView(models.Model): ('state', 'not in', ('draft', 'sql_valid'))]) if non_draft_views: raise UserError(_("You can only unlink draft views")) - return self.unlink() + return super(BiSQLView, self).unlink() @api.multi def copy(self, default=None): diff --git a/bi_sql_editor/tests/__init__.py b/bi_sql_editor/tests/__init__.py new file mode 100644 index 00000000..7b4cf478 --- /dev/null +++ b/bi_sql_editor/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Onestein () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_bi_sql_view diff --git a/bi_sql_editor/tests/test_bi_sql_view.py b/bi_sql_editor/tests/test_bi_sql_view.py new file mode 100644 index 00000000..c555e635 --- /dev/null +++ b/bi_sql_editor/tests/test_bi_sql_view.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Onestein () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase, at_install, post_install +from openerp.exceptions import Warning as UserError + + +@at_install(False) +@post_install(True) +class TestBiSqlViewEditor(TransactionCase): + + def setUp(self): + super(TestBiSqlViewEditor, self).setUp() + self.res_partner = self.env['res.partner'] + self.res_users = self.env['res.users'] + self.bi_sql_view = self.env['bi.sql.view'] + self.view = self.env.ref( + 'bi_sql_editor.partner_sql_view') + # deleting the existing views otherwise it fails + self.view.state = 'model_valid' + self.view.button_set_draft() + self.group_bi_user = self.env.ref( + 'sql_request_abstract.group_sql_request_user') + self.group_user = self.env.ref( + 'base.group_user') + self.company = self.env.ref('base.main_company') + + def test_process_view(self): + self.assertEqual(self.view.state, 'draft', 'state not draft') + self.view.button_validate_sql_expression() + self.assertEqual(self.view.state, 'sql_valid', 'state not sql_valid') + self.view._check_execution() + for field in self.view.bi_sql_view_field_ids: + field.graph_type = 'row' + self.view.button_create_sql_view_and_model() + self.assertEqual(self.view.state, 'model_valid', + 'state not model_valid') + self.view.button_create_ui() + self.assertEqual(self.view.state, 'ui_valid', 'state not ui_valid') + self.view.button_open_view() + self.view.button_set_draft() + + def test_copy(self): + self.assertEqual(self.view.mod, 'draft', 'state not draft') + copy_view = self.view.copy() + self.assertEqual(copy_view.name, 'Partners View (Copy)', 'Wrong name') + + def test_unlink(self): + self.assertEqual(self.view.state, 'draft', 'state not draft') + self.view.button_validate_sql_expression() + self.view.button_create_sql_view_and_model() + with self.assertRaises(UserError): + self.view.unlink() + self.view.button_set_draft() + self.view.unlink()