added method_test on base_module_quality

bzr revid: mra@tinyerp.com-20081219122049-heky9f41aljdf142
This commit is contained in:
Mustufa Rangwala
2008-12-19 17:50:49 +05:30
parent 732284076c
commit 045b32b7b0
3 changed files with 113 additions and 21 deletions
@@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,82 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import os
from tools import config
from base_module_quality import base_module_quality
import pooler
class quality_test(base_module_quality.abstract_quality_check):
def __init__(self):
self.result = """
Method Test:
------------
This test checks if the class method has exception or not.
"""
self.bool_installed_only = False
return None
def run_test(self, module_path, module_name=None, cr=None, uid=None):
pool = pooler.get_pool(cr.dbname)
ids2 = pool.get('ir.model.data').search(cr, uid, [('module','=', module_name), ('model','=','ir.model')])
obj_list = []
for mod in pool.get('ir.model.data').browse(cr, uid, ids2):
object_name = mod.name.split('_')
object_name.pop(0)
object_name = '.'.join(object_name)
obj_list.append(str(object_name))
result={}
self.result += "Module Name:" + module_name + '\n' + '===============\n'
for obj in obj_list:
temp=[]
try:
res = pool.get(obj).search(cr, uid, [])
temp.append('Ok')
except:
temp.append('Exception')
try:
res1 = pool.get(obj).fields_view_get(cr, uid,)
temp.append('Ok')
except:
temp.append('Exception')
try:
res2 = pool.get(obj).read(cr, uid, [])
temp.append('Ok')
except:
temp.append('Exception')
result[obj] = temp
self.result+=("%-40s %-12s \t %-16s %-12s")%('Object Name'.ljust(40),'search','fields_view_get','read')
self.result+='\n'
for res in result:
self.result+=("%-40s %-12s \t %-16s \t %-12s")%(res.ljust(40),result[res][0],result[res][1],result[res][2])
self.result+="\n"
return None
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -30,29 +30,17 @@ import os
#TODO: configure pylint
#TODO: implement the speed test
#TODO: implement the simple test
#TODO: add cheks: do the class quality_check inherits the class abstract_quality_check?
#TODO: add cheks: do the class quality_check inherits the class abstract_quality_check?
#TODO: improve translability
#To keep or not? to be discussed...
#~ form_check = '''<?xml version="1.0"?>
#~ <form string="Quality check">
#~ <field name="test" />
#~ </form>'''
#~ fields_check = {
#~ 'test': {
#~ 'string':'Tests', 'type':'selection', 'required':True,
#~ 'selection': [('pylint', 'Pylint'), ('othertest','other')],
#~ 'default': lambda *args: 'pylint'
#~ },
#~ }
view_form = """<?xml version="1.0"?>
<form string="Check quality">
<notebook>
<page string="Summary">
<field name="general_info" nolabel="1" colspan="4" height="350" width="400"/>
<field name="general_info" nolabel="1" colspan="4" height="350" width="800"/>
</page>
</notebook>
</form>"""
@@ -71,8 +59,8 @@ class wiz_quality_check(wizard.interface):
from tools import config
pool = pooler.get_pool(cr.dbname)
module_data = pool.get('ir.module.module').browse(cr, uid, data['ids'])
list_folders = os.listdir(config['addons_path']+'/base_module_quality/')
module_name = module_data[0].name
for item in list_folders:
path = config['addons_path']+'/base_module_quality/'+item
if os.path.exists(path+'/'+item+'.py') and item not in ['report', 'wizard', 'security']:
@@ -83,18 +71,16 @@ class wiz_quality_check(wizard.interface):
x2 = getattr(x, item)
x3 = getattr(x2, item)
val = x3.quality_test()
if not val.bool_installed_only or module_data[0].state == "installed":
if (not val.bool_installed_only or module_data[0].state == "installed") and item == 'method_test':
val.run_test(str(module_path), module_name, cr, uid)
elif not val.bool_installed_only or module_data[0].state == "installed" :
val.run_test(str(module_path))
else:
val.result += "The module has to be installed before running this test."
string_ret += val.result
print val.result_details
return {'general_info':string_ret}
states = {
#To keep or not? to be discussed...
@@ -107,8 +93,8 @@ class wiz_quality_check(wizard.interface):
'actions': [_check],
'result': {'type':'form', 'arch':view_form, 'fields':view_field, 'state':[('end','Ok')]},
},
}
}
wiz_quality_check('base.module.quality')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: