Commit 52bf2efd authored by Lucas Carvalho's avatar Lucas Carvalho

Improved the test to check all the states of each installed workflow.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40565 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 91f3c74a
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
############################################################################## ##############################################################################
# #
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Fabien Morin <fabien@nexedi.com # Fabien Morin <fabien@nexedi.com>
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential # programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs # consequences resulting from its eventual inadequacies and bugs
...@@ -27,67 +27,158 @@ ...@@ -27,67 +27,158 @@
############################################################################## ##############################################################################
import unittest import unittest
from Products.ERP5.tests.testXHTML import TestXHTML from subprocess import Popen, PIPE
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
import popen2
class aspell: # XXX (lucas): this list must be added in text file
def __init__(self): except_word_list = ('todo',
self._f = popen2.Popen3("aspell -l en_GB -a") 'journalised',)
self._f.fromchild.readline() #skip the credit line
def __call__(self, words):
words = words.split(' ') class Aspell(object):
output = []
for word in words: language_list = ('en_GB',)
self._f.tochild.write(word+'\n')
self._f.tochild.flush() def __call__(self, sentence):
s = self._f.fromchild.readline().strip() word_list = sentence.split()
self._f.fromchild.readline() #skip the blank line output_dict = {}
if s == "*": for word in word_list:
output.append(None) if word.lower() in except_word_list:
elif s[0] == '#': output_dict[word] = ['*']
output.append("No Suggestions") continue
else:
output.append(s.split(':')[1].strip().split(', ')) for language in self.language_list:
return output output_dict[word] = self.getSpellCheckResultList(word, language)
return output_dict
def getSpellCheckResultList(self, word, language):
command = 'echo %s | aspell -l %s -a' % (word, language)
subprocess = Popen(command, shell=True, stdin=PIPE,
stdout=PIPE, stderr=PIPE, close_fds=True)
return subprocess.communicate()[0].split('\n')[1:]
class TestSpellChecking(ERP5TypeTestCase): class TestSpellChecking(ERP5TypeTestCase):
run_all_test = 1 run_all_test = 1
spellChecker = aspell() spellChecker = Aspell()
def getTitle(self): def getTitle(self):
return "Spell Checking Test" return "Spell Checking Test"
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
return ( return ('erp5_base',
'erp5_base',) 'erp5_simulation',
'erp5_accounting',
def validate_spell(self, word): 'erp5_pdm',
''' 'erp5_trade',
validate the spell. Return True if the word is well spelled, False else, 'erp5_workflow',
whith an error message 'erp5_web',
'''
result = self.spellChecker(word) 'erp5_ingestion_mysql_innodb_catalog',
message = '' 'erp5_ingestion',
if result != [None] and result != ['No Suggestions']: 'erp5_invoicing',
message = '"%s" is missspelled, suggestion are : "%s"' % \
(word, '", "'.join(result[0])) 'erp5_advanced_invoicing',
if result == ['No Suggestions']: 'erp5_apparel',
message = '"%s" is missspelled, there is no suggestion.' % word 'erp5_archive',
return result == [None], message #'erp5_banking_cash',
#'erp5_banking_check',
#'erp5_banking_core',
#'erp5_banking_inventory',
'erp5_bpm',
'erp5_budget',
'erp5_calendar',
'erp5_commerce',
'erp5_consulting',
'erp5_content_translation',
'erp5_credential',
'erp5_crm',
'erp5_data_protection',
'erp5_dms',
#'erp5_egov_catalog',
#'erp5_egov',
'erp5_forge',
'erp5_hr',
'erp5_immobilisation',
'erp5_item',
'erp5_knowledge_pad',
'erp5_legacy_tax_system',
'erp5_mrp',
'erp5_open_trade',
'erp5_payroll',
'erp5_project',
'erp5_publication',
#'erp5_registry_ohada',
'erp5_simulation_performance_test',
'erp5_ui_test',
'erp5_wizard',
)
def validate_spell(self, sentence):
"""
Validate the spell. Return True if the word is well spelled, False else,
with an error message.
"""
message = '"%s" is misspelled, suggestion are : "%s"'
result_dict = {}
for word, result_list in self.spellChecker(sentence).iteritems():
filtered_result_list = filter(lambda x: x not in ('*', ''), result_list)
if filtered_result_list:
result_dict[word] = message % (word, \
filtered_result_list[0].split(':')[-1].strip())
return result_dict
def test_checkSpellChecker(self): def test_checkSpellChecker(self):
"""
Simple test for Aspell class.
"""
# check a well spelled world # check a well spelled world
self.assertEquals((self.validate_spell('cancelled')), (True, '')) self.assertEquals(self.validate_spell('cancelled'), {})
self.assertEquals(self.validate_spell('globally enabled'), {})
self.assertEquals(self.validate_spell('http://www.erp5.com'), {})
self.assertEquals(self.validate_spell('2010/11/20'), {})
# check some suggestion are given for a small mistake # check some suggestion are given for a small mistake
self.assertEquals(self.validate_spell('canceled')[0], False) self.assertNotEquals(self.validate_spell('canceled'), {})
self.assertTrue(len(self.validate_spell('canceled')[1]) > 0) self.assertTrue('is misspelled' in \
self.validate_spell('canceled').values()[0])
def test_business_template_list_with_workflow_template_item(self):
"""
Make sure that we have installed on this test all public
business template which has WorkflowTemplateItem.
"""
pass
def test_spell_check_workflow_states(self):
"""
Running spell check on each state object of all installed workflows.
It will check the attributes:
- id
- title
"""
message = 'State %s: %s, \n Workflow: %s \n Suggestions: %s'
attribute_list = ['id', 'title']
error_list = []
for workflow in self.portal.portal_workflow.objectValues():
if getattr(workflow, 'states', None) is not None:
for state in workflow.states.objectValues():
for attribute in attribute_list:
sentence = getattr(state, attribute)
result_dict = self.validate_spell(sentence)
if result_dict:
error_list.append(message % (attribute, sentence, workflow.id, \
result_dict.pop(sentence)))
if error_list:
self.fail('\n'.join(error_list))
# check no suggestion are given for a very bad spelled word
self.assertEquals(self.validate_spell('cancelefqfdsqfdsfqdsf')[0], False)
self.assertTrue('no suggestion' in self.validate_spell('cancelefqfdsqfdsfqdsf')[1])
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment