Commit 411ba050 authored by Jérome Perrin's avatar Jérome Perrin

Use ERP5ReportTestCase instead of duplicating code

( testCrmReports: use afterSetUp / beforeTearDown instead of overriding setUp and tearDown )


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21492 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 14e061bd
...@@ -34,9 +34,10 @@ import unittest ...@@ -34,9 +34,10 @@ import unittest
from DateTime import DateTime from DateTime import DateTime
from Products.ERP5.tests.testAccounting import AccountingTestCase from Products.ERP5.tests.testAccounting import AccountingTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5ReportTestCase
class TestAccountingReports(AccountingTestCase): class TestAccountingReports(AccountingTestCase, ERP5ReportTestCase):
"""Test Accounting reports """Test Accounting reports
Test basic cases of gathering data to render reports, the purpose of those Test basic cases of gathering data to render reports, the purpose of those
...@@ -58,40 +59,6 @@ class TestAccountingReports(AccountingTestCase): ...@@ -58,40 +59,6 @@ class TestAccountingReports(AccountingTestCase):
self.portal.erp5_sql_connection.manage_test('TRUNCATE TABLE stock') self.portal.erp5_sql_connection.manage_test('TRUNCATE TABLE stock')
get_transaction().commit() get_transaction().commit()
# utility methods for ERP5 Report
def getReportSectionList(self, report_name):
"""Get the list of report sections in a report."""
report = getattr(self.portal, report_name)
report_method = getattr(self.portal, report.report_method)
return report_method()
def getListBoxLineList(self, report_section):
"""Render the listbox in a report section, return None if no listbox exists
in the report_section.
"""
result = None
here = report_section.getObject(self.portal)
report_section.pushReport(self.portal)
form = getattr(here, report_section.getFormId())
if form.has_field('listbox'):
result = form.listbox.get_value('default',
render_format='list',
REQUEST=self.portal.REQUEST)
report_section.popReport(self.portal)
return result
def checkLineProperties(self, line, **kw):
"""Check properties of a report line.
"""
diff_list = []
for k, v in kw.items():
if v != line.getColumnProperty(k):
diff_list.append('`%s`: expected: %r actual: %r' %
(k, v, line.getColumnProperty(k)))
if diff_list:
self.fail('Lines differs:\n' + '\n'.join(diff_list))
def testJournal(self): def testJournal(self):
# Journal report. # Journal report.
# this will be a journal for 2006/02/02, for Sale Invoice Transaction # this will be a journal for 2006/02/02, for Sale Invoice Transaction
......
...@@ -31,12 +31,12 @@ ...@@ -31,12 +31,12 @@
"""Tests Standards ERP5 Crm Reports """Tests Standards ERP5 Crm Reports
""" """
import unittest import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5ReportTestCase
from Products.ERP5Type.tests.utils import reindex from Products.ERP5Type.tests.utils import reindex
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from DateTime import DateTime from DateTime import DateTime
class CrmTestCase(ERP5TypeTestCase): class CrmTestCase(ERP5ReportTestCase):
"""Tests starts with a preference activated for self.my_organisation, logged in """Tests starts with a preference activated for self.my_organisation, logged in
as a user with Assignee, Assignor and Author role. as a user with Assignee, Assignor and Author role.
...@@ -155,11 +155,9 @@ class CrmTestCase(ERP5TypeTestCase): ...@@ -155,11 +155,9 @@ class CrmTestCase(ERP5TypeTestCase):
user = uf.getUserById('manager').__of__(uf) user = uf.getUserById('manager').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def setUp(self): def afterSetUp(self):
"""Setup the fixture. """Setup the fixture.
""" """
ERP5TypeTestCase.setUp(self)
self.portal = self.getPortal()
self.event_module = self.portal.event_module self.event_module = self.portal.event_module
self.campaign_module = self.portal.campaign_module self.campaign_module = self.portal.campaign_module
self.meeting_module = self.portal.meeting_module self.meeting_module = self.portal.meeting_module
...@@ -168,7 +166,6 @@ class CrmTestCase(ERP5TypeTestCase): ...@@ -168,7 +166,6 @@ class CrmTestCase(ERP5TypeTestCase):
self.organisation_module = self.portal.organisation_module self.organisation_module = self.portal.organisation_module
self.person_module = self.portal.person_module self.person_module = self.portal.person_module
self.portal_categories = self.portal.portal_categories self.portal_categories = self.portal.portal_categories
# create group category # create group category
if not self.portal_categories['group'].has_key('demo_group'): if not self.portal_categories['group'].has_key('demo_group'):
...@@ -233,7 +230,7 @@ class CrmTestCase(ERP5TypeTestCase): ...@@ -233,7 +230,7 @@ class CrmTestCase(ERP5TypeTestCase):
self.tic() self.tic()
def tearDown(self): def beforeTearDown(self):
"""Remove all documents. """Remove all documents.
""" """
get_transaction().abort() get_transaction().abort()
...@@ -255,7 +252,6 @@ class CrmTestCase(ERP5TypeTestCase): ...@@ -255,7 +252,6 @@ class CrmTestCase(ERP5TypeTestCase):
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
ERP5TypeTestCase.tearDown(self)
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
"""Returns list of BT to be installed.""" """Returns list of BT to be installed."""
...@@ -276,36 +272,6 @@ class TestCrmReports(CrmTestCase): ...@@ -276,36 +272,6 @@ class TestCrmReports(CrmTestCase):
def getTitle(self): def getTitle(self):
return "Crm Reports" return "Crm Reports"
# utility methods for ERP5 Report -> TODO move in framework !
def getReportSectionList(self, report_name):
"""Get the list of report sections in a report."""
report = getattr(self.portal, report_name)
report_method = getattr(self.portal, report.report_method)
return report_method()
def getListBoxLineList(self, report_section):
"""Render the listbox in a report section, return None if no listbox exists
in the report_section.
"""
result = None
here = report_section.getObject(self.portal)
report_section.pushReport(self.portal)
form = getattr(here, report_section.getFormId())
if form.has_field('listbox'):
result = form.listbox.get_value('default',
render_format='list',
REQUEST=self.portal.REQUEST)
report_section.popReport(self.portal)
return result
def checkLineProperties(self, line, **kw):
"""Check properties of a report line.
"""
for k, v in kw.items():
self.assertEquals(v, line.getColumnProperty(k),
'`%s`: expected: %r actual: %r' % (k, v, line.getColumnProperty(k)))
# /utility methods for ERP5 Report
def testCampaignStatus(self): def testCampaignStatus(self):
# Campaign Status report. # Campaign Status report.
......
...@@ -29,12 +29,12 @@ ...@@ -29,12 +29,12 @@
"""Tests Standards ERP5 Trade Reports """Tests Standards ERP5 Trade Reports
""" """
import unittest import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5ReportTestCase
from Products.ERP5Type.tests.utils import reindex from Products.ERP5Type.tests.utils import reindex
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from DateTime import DateTime from DateTime import DateTime
class TestTradeReports(ERP5TypeTestCase): class TestTradeReports(ERP5ReportTestCase):
"""Test Trade reports """Test Trade reports
""" """
def getTitle(self): def getTitle(self):
...@@ -201,15 +201,6 @@ class TestTradeReports(ERP5TypeTestCase): ...@@ -201,15 +201,6 @@ class TestTradeReports(ERP5TypeTestCase):
return sale_order return sale_order
def checkLineProperties(self, line, **kw):
"""Check properties of a report line.
"""
for k, v in kw.items():
self.assertEquals(v, line.getColumnProperty(k),
'`%s`: expected: %r actual: %r' % (k, v, line.getColumnProperty(k)))
# /utility methods for ERP5 Report
def testSaleOrderReport(self): def testSaleOrderReport(self):
""" """
Sale order report. Sale order report.
...@@ -471,30 +462,6 @@ class TestTradeReports(ERP5TypeTestCase): ...@@ -471,30 +462,6 @@ class TestTradeReports(ERP5TypeTestCase):
'total quantity': None} 'total quantity': None}
self.checkLineProperties(stat_line_list[0],**d) self.checkLineProperties(stat_line_list[0],**d)
# utility methods for ERP5 Report
def getReportSectionList(self, context, report_name):
"""Get the list of report sections in a report."""
report = getattr(context, report_name)
report_method = getattr(context, report.report_method)
return report_method()
def getListBoxLineList(self, report_section):
"""Render the listbox in a report section, return None if no listbox exists
in the report_section.
"""
result = None
here = report_section.getObject(self.portal)
report_section.pushReport(self.portal)
form = getattr(here, report_section.getFormId())
if form.has_field('listbox'):
result = form.listbox.get_value('default',
render_format='list',
REQUEST=self.portal.REQUEST)
report_section.popReport(self.portal)
return result
def testStockReport(self): def testStockReport(self):
""" """
Stock report. Stock report.
......
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