Browse Source

add test. FIx unlink

pull/162/head
aheficent 8 years ago
committed by Darshan Patel
parent
commit
7f0c6ca827
  1. 4
      bi_sql_editor/demo/bi_sql_view.xml
  2. 2
      bi_sql_editor/models/bi_sql_view.py
  3. 5
      bi_sql_editor/tests/__init__.py
  4. 56
      bi_sql_editor/tests/test_bi_sql_view.py

4
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). License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
--> -->
<openerp><data>
<openerp><data noupdate="1">
<record id="incorrect_sql_view" model="bi.sql.view"> <record id="incorrect_sql_view" model="bi.sql.view">
<field name="name">Draft Incorrect SQL View</field> <field name="name">Draft Incorrect SQL View</field>
@ -32,8 +32,6 @@ ORDER BY name
</field> </field>
</record> </record>
<function model="bi.sql.view" name="button_validate_sql_expression" eval="([ref('partner_sql_view')])"/>
<record id="module_sql_view" model="bi.sql.view"> <record id="module_sql_view" model="bi.sql.view">
<field name="name">Modules by Authors</field> <field name="name">Modules by Authors</field>
<field name="technical_name">modules_view</field> <field name="technical_name">modules_view</field>

2
bi_sql_editor/models/bi_sql_view.py

@ -148,7 +148,7 @@ class BiSQLView(models.Model):
('state', 'not in', ('draft', 'sql_valid'))]) ('state', 'not in', ('draft', 'sql_valid'))])
if non_draft_views: if non_draft_views:
raise UserError(_("You can only unlink draft views")) raise UserError(_("You can only unlink draft views"))
return self.unlink()
return super(BiSQLView, self).unlink()
@api.multi @api.multi
def copy(self, default=None): def copy(self, default=None):

5
bi_sql_editor/tests/__init__.py

@ -0,0 +1,5 @@
# -*- 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

56
bi_sql_editor/tests/test_bi_sql_view.py

@ -0,0 +1,56 @@
# -*- 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()
Loading…
Cancel
Save