aheficent
7 years ago
committed by
Nicolas Mac Rouillon
7 changed files with 124 additions and 116 deletions
-
1bi_sql_editor/__init__.py
-
1bi_sql_editor/__openerp__.py
-
6bi_sql_editor/demo/bi_sql_view_demo.xml
-
52bi_sql_editor/hooks.py
-
15bi_sql_editor/models/bi_sql_view.py
-
5bi_sql_editor/tests/__init__.py
-
56bi_sql_editor/tests/test_bi_sql_view.py
@ -1,3 +1,4 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
|
|
||||
from . import models |
from . import models |
||||
|
from .hooks import uninstall_hook |
@ -0,0 +1,52 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2015-2017 Onestein (<http://www.onestein.eu>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
from openerp import SUPERUSER_ID |
||||
|
from openerp.api import Environment |
||||
|
|
||||
|
|
||||
|
def uninstall_hook(cr, registry): |
||||
|
env = Environment(cr, SUPERUSER_ID, {}) |
||||
|
recs = env['bi.sql.view'].search([]) |
||||
|
for rec in recs: |
||||
|
rec.button_set_draft() |
||||
|
rec.unlink() |
||||
|
|
||||
|
# delete dirty data that could cause problems |
||||
|
# while re-installing the module |
||||
|
# Drop materialized views |
||||
|
cr.execute(""" |
||||
|
select relname |
||||
|
from pg_class |
||||
|
where relname like 'x_bi_sql_view%' and relkind='m' |
||||
|
""") |
||||
|
for r in cr.fetchall(): |
||||
|
cr.execute(""" |
||||
|
DROP MATERIALIZED VIEW %s |
||||
|
""" % r) |
||||
|
|
||||
|
cr.execute(""" |
||||
|
select relname |
||||
|
from pg_class |
||||
|
where relname like 'x_bi_sql_view%' and relkind='r' |
||||
|
""") |
||||
|
for r in cr.fetchall(): |
||||
|
cr.execute(""" |
||||
|
DROP TABLE %s |
||||
|
""" % r) |
||||
|
cr.execute(""" |
||||
|
select table_name from INFORMATION_SCHEMA.views |
||||
|
where table_name like 'x_bi_sql%'""") |
||||
|
|
||||
|
# Drop not materialized views |
||||
|
for v in cr.fetchall(): |
||||
|
cr.execute(""" |
||||
|
DROP VIEW %s |
||||
|
""" % v) |
||||
|
|
||||
|
# Drop table if uninstalling went wrong |
||||
|
cr.execute(""" |
||||
|
delete from ir_model_fields where model like 'bi.sql.view%'; |
||||
|
delete from ir_model_fields where model like 'bi_sql_%'; |
||||
|
delete from ir_model where model like 'x_bi_sql_view.%'; |
||||
|
""") |
@ -1,5 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# Copyright 2017 Onestein (<http://www.onestein.eu>) |
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
||||
|
|
||||
from . import test_bi_sql_view |
|
@ -1,56 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# Copyright 2017 Onestein (<http://www.onestein.eu>) |
|
||||
# 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() |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue