Browse Source

Refactoring and add new tests

pull/211/head
jcoux 8 years ago
parent
commit
50b3b4577d
  1. 1
      account_financial_report_qweb/tests/__init__.py
  2. 202
      account_financial_report_qweb/tests/abstract_test.py
  3. 88
      account_financial_report_qweb/tests/test_aged_partner_balance.py
  4. 96
      account_financial_report_qweb/tests/test_general_ledger.py
  5. 87
      account_financial_report_qweb/tests/test_open_items.py
  6. 96
      account_financial_report_qweb/tests/test_trial_balance.py

1
account_financial_report_qweb/tests/__init__.py

@ -2,6 +2,7 @@
# © 2016 Julien Coux (Camptocamp)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).-
from . import abstract_test
from . import test_aged_partner_balance
from . import test_general_ledger
from . import test_open_items

202
account_financial_report_qweb/tests/abstract_test.py

@ -0,0 +1,202 @@
# -*- coding: utf-8 -*-
# Author: Julien Coux
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
class AbstractTest(TransactionCase):
"""Common technical tests for all reports."""
def setUp(cls):
super(AbstractTest, cls).setUp()
cls.model = cls._getReportModel()
cls.qweb_report_name = cls._getQwebReportName()
cls.xlsx_report_name = cls._getXlsxReportName()
cls.xlsx_action_name = cls._getXlsxReportActionName()
cls.report_title = cls._getReportTitle()
cls.base_filters = cls._getBaseFilters()
cls.additional_filters = cls._getAdditionalFiltersToBeTested()
cls.report = cls.model.create(cls.base_filters)
def test_01_generation_report_qweb(self):
"""Check if report PDF/HTML is correctly generated"""
# Check if returned report action is correct
report_action = self.report.print_report()
self.assertDictContainsSubset(
{
'type': 'ir.actions.report.xml',
'report_name': self.qweb_report_name,
'report_type': 'qweb-pdf',
},
report_action
)
# Check if report template is correct
report_html = self.env['report'].get_html(
self.report, self.qweb_report_name
)
self.assertRegexpMatches(report_html, self.report_title)
self.assertRegexpMatches(report_html, self.report.account_ids[0].name)
def test_02_generation_report_xlsx(self):
"""Check if report XLSX is correctly generated"""
# Check if returned report action is correct
report_action = self.report.print_report(xlsx_report=True)
self.assertDictContainsSubset(
{
'type': 'ir.actions.report.xml',
'report_name': self.xlsx_report_name,
'report_type': 'xlsx',
},
report_action
)
# Check if report template is correct
report_xlsx = self.env.ref(self.xlsx_action_name).render_report(
self.report.ids,
self.xlsx_report_name,
{'report_type': 'xlsx'}
)
self.assertGreaterEqual(len(report_xlsx[0]), 1)
self.assertEqual(report_xlsx[1], 'xlsx')
def test_03_compute_data(self):
"""Check that the SQL queries work with all filters options"""
for filters in [{}] + self.additional_filters:
current_filter = self.base_filters.copy()
current_filter.update(filters)
report = self.model.create(current_filter)
report.compute_data_for_report()
self.assertGreaterEqual(len(report.account_ids), 1)
# Same filters with only one account
current_filter = self.base_filters.copy()
current_filter.update(filters)
current_filter.update({
'filter_account_ids':
[(6, 0, report.account_ids[0].account_id.ids)],
})
report2 = self.model.create(current_filter)
report2.compute_data_for_report()
self.assertEqual(len(report2.account_ids), 1)
self.assertEqual(report2.account_ids.name,
report.account_ids[0].name)
if self._partner_test_is_possible(filters):
# Same filters with only one partner
report_partner_ids = report.account_ids.mapped('partner_ids')
partner_ids = report_partner_ids.mapped('partner_id')
current_filter = self.base_filters.copy()
current_filter.update(filters)
current_filter.update({
'filter_partner_ids': [(6, 0, partner_ids[0].ids)],
})
report3 = self.model.create(current_filter)
report3.compute_data_for_report()
self.assertGreaterEqual(len(report3.account_ids), 1)
report_partner_ids3 = report3.account_ids.mapped('partner_ids')
partner_ids3 = report_partner_ids3.mapped('partner_id')
self.assertEqual(len(partner_ids3), 1)
self.assertEqual(
partner_ids3.name,
partner_ids[0].name
)
# Same filters with only one partner and one account
report_partner_ids = report3.account_ids.mapped('partner_ids')
report_account_id = report_partner_ids.filtered(
lambda p: p.partner_id
)[0].report_account_id
current_filter = self.base_filters.copy()
current_filter.update(filters)
current_filter.update({
'filter_account_ids':
[(6, 0, report_account_id.account_id.ids)],
'filter_partner_ids': [(6, 0, partner_ids[0].ids)],
})
report4 = self.model.create(current_filter)
report4.compute_data_for_report()
self.assertEqual(len(report4.account_ids), 1)
self.assertEqual(report4.account_ids.name,
report_account_id.account_id.name)
report_partner_ids4 = report4.account_ids.mapped('partner_ids')
partner_ids4 = report_partner_ids4.mapped('partner_id')
self.assertEqual(len(partner_ids4), 1)
self.assertEqual(
partner_ids4.name,
partner_ids[0].name
)
def _partner_test_is_possible(self, filters):
"""
:return:
a boolean to indicate if partner test is possible
with current filters
"""
return True
def _getReportModel(self):
"""
:return: the report model name
"""
raise NotImplementedError()
def _getQwebReportName(self):
"""
:return: the qweb report name
"""
raise NotImplementedError()
def _getXlsxReportName(self):
"""
:return: the xlsx report name
"""
raise NotImplementedError()
def _getXlsxReportActionName(self):
"""
:return: the xlsx report action name
"""
raise NotImplementedError()
def _getReportTitle(self):
"""
:return: the report title displayed into the report
"""
raise NotImplementedError()
def _getBaseFilters(self):
"""
:return: the minimum required filters to generate report
"""
raise NotImplementedError()
def _getAdditionalFiltersToBeTested(self):
"""
:return: the additional filters to generate report variants
"""
raise NotImplementedError()

88
account_financial_report_qweb/tests/test_aged_partner_balance.py

@ -4,71 +4,39 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import time
from openerp.tests.common import TransactionCase
from . import abstract_test
class TestAgedPartnerBalance(TransactionCase):
class TestAgedPartnerBalance(abstract_test.AbstractTest):
"""
Technical tests for Aged Partner Balance Report.
"""
def setUp(cls):
super(TestAgedPartnerBalance, cls).setUp()
env = cls.env
model = env['report_aged_partner_balance_qweb']
main_company = env.ref('base.main_company')
def _getReportModel(self):
return self.env['report_aged_partner_balance_qweb']
cls.report = model.create({
'date_at': time.strftime('%Y-12-31'),
'company_id': main_company.id,
})
def test_01_compute_data(self):
"""Check if data are computed"""
self.report.compute_data_for_report()
self.assertGreaterEqual(len(self.report.account_ids), 1)
def test_02_generation_report_qweb(self):
"""Check if report PDF/HTML is correctly generated"""
def _getQwebReportName(self):
return 'account_financial_report_qweb.report_aged_partner_balance_qweb'
report_name = 'account_financial_report_qweb.' \
'report_aged_partner_balance_qweb'
# Check if returned report action is correct
report_action = self.report.print_report()
self.assertDictContainsSubset(
{
'type': 'ir.actions.report.xml',
'report_name': report_name,
'report_type': 'qweb-pdf',
},
report_action
)
def _getXlsxReportName(self):
return 'account_financial_report_qweb.report_aged_partner_balance_xlsx'
# Check if report template is correct
report_html = self.env['report'].get_html(self.report, report_name)
self.assertRegexpMatches(report_html, 'Aged Partner Balance')
self.assertRegexpMatches(report_html, self.report.account_ids[0].name)
def _getXlsxReportActionName(self):
return 'account_financial_report_qweb.' \
'action_report_aged_partner_balance_xlsx'
def test_03_generation_report_xlsx(self):
"""Check if report XLSX is correctly generated"""
def _getReportTitle(self):
return 'Aged Partner Balance'
report_name = 'account_financial_report_qweb.' \
'report_aged_partner_balance_xlsx'
# Check if returned report action is correct
report_action = self.report.print_report(xlsx_report=True)
self.assertDictContainsSubset(
{
'type': 'ir.actions.report.xml',
'report_name': report_name,
'report_type': 'xlsx',
},
report_action
)
# Check if report template is correct
action_name = 'account_financial_report_qweb.' \
'action_report_aged_partner_balance_xlsx'
report_xlsx = self.env.ref(action_name).render_report(
self.report.ids,
report_name,
{'report_type': u'xlsx'}
)
self.assertGreaterEqual(len(report_xlsx[0]), 1)
self.assertEqual(report_xlsx[1], 'xlsx')
def _getBaseFilters(self):
return {
'date_at': time.strftime('%Y-12-31'),
'company_id': self.env.ref('base.main_company').id,
}
def _getAdditionalFiltersToBeTested(self):
return [
{'only_posted_moves': True},
{'show_move_line_details': True},
{'only_posted_moves': True, 'show_move_line_details': True},
]

96
account_financial_report_qweb/tests/test_general_ledger.py

@ -4,73 +4,49 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import time
from openerp.tests.common import TransactionCase
from . import abstract_test
class TestGeneralLedger(TransactionCase):
class TestGeneralLedger(abstract_test.AbstractTest):
"""
Technical tests for General Ledger Report.
"""
def setUp(cls):
super(TestGeneralLedger, cls).setUp()
env = cls.env
model = env['report_general_ledger_qweb']
main_company = env.ref('base.main_company')
def _getReportModel(self):
return self.env['report_general_ledger_qweb']
cls.report = model.create({
'date_from': time.strftime('%Y-01-01'),
'date_to': time.strftime('%Y-12-31'),
'company_id': main_company.id,
'fy_start_date': time.strftime('%Y-01-01'),
})
def _getQwebReportName(self):
return 'account_financial_report_qweb.report_general_ledger_qweb'
def test_01_compute_data(self):
"""Check if data are computed"""
self.report.compute_data_for_report()
self.assertGreaterEqual(len(self.report.account_ids), 1)
def _getXlsxReportName(self):
return 'account_financial_report_qweb.report_general_ledger_xlsx'
def test_02_generation_report_qweb(self):
"""Check if report PDF/HTML is correctly generated"""
report_name = 'account_financial_report_qweb.' \
'report_general_ledger_qweb'
# Check if returned report action is correct
report_action = self.report.print_report(xlsx_report=False)
self.assertDictContainsSubset(
{
'type': 'ir.actions.report.xml',
'report_name': report_name,
'report_type': 'qweb-pdf',
},
report_action
)
def _getXlsxReportActionName(self):
return 'account_financial_report_qweb.' \
'action_report_general_ledger_xlsx'
# Check if report template is correct
report_html = self.env['report'].get_html(self.report, report_name)
self.assertRegexpMatches(report_html, 'General Ledger')
self.assertRegexpMatches(report_html, self.report.account_ids[0].name)
def _getReportTitle(self):
return 'General Ledger'
def test_03_generation_report_xlsx(self):
"""Check if report XLSX is correctly generated"""
report_name = 'account_financial_report_qweb.' \
'report_general_ledger_xlsx'
# Check if returned report action is correct
report_action = self.report.print_report(xlsx_report=True)
self.assertDictContainsSubset(
def _getBaseFilters(self):
return {
'date_from': time.strftime('%Y-01-01'),
'date_to': time.strftime('%Y-12-31'),
'company_id': self.env.ref('base.main_company').id,
'fy_start_date': time.strftime('%Y-01-01'),
}
def _getAdditionalFiltersToBeTested(self):
return [
{'only_posted_moves': True},
{'hide_account_balance_at_0': True},
{'centralize': True},
{'only_posted_moves': True, 'hide_account_balance_at_0': True},
{'only_posted_moves': True, 'centralize': True},
{'hide_account_balance_at_0': True, 'centralize': True},
{
'type': 'ir.actions.report.xml',
'report_name': report_name,
'report_type': 'xlsx',
'only_posted_moves': True,
'hide_account_balance_at_0': True,
'centralize': True
},
report_action
)
# Check if report template is correct
action_name = 'account_financial_report_qweb.' \
'action_report_general_ledger_xlsx'
report_xlsx = self.env.ref(action_name).render_report(
self.report.ids,
report_name,
{'report_type': u'xlsx'}
)
self.assertGreaterEqual(len(report_xlsx[0]), 1)
self.assertEqual(report_xlsx[1], 'xlsx')
]

87
account_financial_report_qweb/tests/test_open_items.py

@ -4,71 +4,38 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import time
from openerp.tests.common import TransactionCase
from . import abstract_test
class TestOpenItems(TransactionCase):
class TestOpenItems(abstract_test.AbstractTest):
"""
Technical tests for Open Items Report.
"""
def setUp(cls):
super(TestOpenItems, cls).setUp()
env = cls.env
model = env['report_open_items_qweb']
main_company = env.ref('base.main_company')
def _getReportModel(self):
return self.env['report_open_items_qweb']
cls.report = model.create({
'date_at': time.strftime('%Y-12-31'),
'company_id': main_company.id,
})
def test_01_compute_data(self):
"""Check if data are computed"""
self.report.compute_data_for_report()
self.assertGreaterEqual(len(self.report.account_ids), 1)
def test_02_generation_report_qweb(self):
"""Check if report PDF/HTML is correctly generated"""
def _getQwebReportName(self):
return 'account_financial_report_qweb.report_open_items_qweb'
report_name = 'account_financial_report_qweb.' \
'report_open_items_qweb'
# Check if returned report action is correct
report_action = self.report.print_report()
self.assertDictContainsSubset(
{
'type': 'ir.actions.report.xml',
'report_name': report_name,
'report_type': 'qweb-pdf',
},
report_action
)
def _getXlsxReportName(self):
return 'account_financial_report_qweb.report_open_items_xlsx'
# Check if report template is correct
report_html = self.env['report'].get_html(self.report, report_name)
self.assertRegexpMatches(report_html, 'Open Items')
self.assertRegexpMatches(report_html, self.report.account_ids[0].name)
def _getXlsxReportActionName(self):
return 'account_financial_report_qweb.action_report_open_items_xlsx'
def test_03_generation_report_xlsx(self):
"""Check if report XLSX is correctly generated"""
def _getReportTitle(self):
return 'Open Items'
report_name = 'account_financial_report_qweb.' \
'report_open_items_xlsx'
# Check if returned report action is correct
report_action = self.report.print_report(xlsx_report=True)
self.assertDictContainsSubset(
{
'type': 'ir.actions.report.xml',
'report_name': report_name,
'report_type': 'xlsx',
},
report_action
)
# Check if report template is correct
action_name = 'account_financial_report_qweb.' \
'action_report_open_items_xlsx'
report_xlsx = self.env.ref(action_name).render_report(
self.report.ids,
report_name,
{'report_type': u'xlsx'}
)
self.assertGreaterEqual(len(report_xlsx[0]), 1)
self.assertEqual(report_xlsx[1], 'xlsx')
def _getBaseFilters(self):
return {
'date_at': time.strftime('%Y-12-31'),
'company_id': self.env.ref('base.main_company').id,
}
def _getAdditionalFiltersToBeTested(self):
return [
{'only_posted_moves': True},
{'hide_account_balance_at_0': True},
{'only_posted_moves': True, 'hide_account_balance_at_0': True},
]

96
account_financial_report_qweb/tests/test_trial_balance.py

@ -4,73 +4,51 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import time
from openerp.tests.common import TransactionCase
from . import abstract_test
class TestTrialBalance(TransactionCase):
class TestTrialBalance(abstract_test.AbstractTest):
"""
Technical tests for Trial Balance Report.
"""
def setUp(cls):
super(TestTrialBalance, cls).setUp()
env = cls.env
model = env['report_trial_balance_qweb']
main_company = env.ref('base.main_company')
def _getReportModel(self):
return self.env['report_trial_balance_qweb']
cls.report = model.create({
'date_from': time.strftime('%Y-01-01'),
'date_to': time.strftime('%Y-12-31'),
'company_id': main_company.id,
'fy_start_date': time.strftime('%Y-01-01'),
})
def test_01_compute_data(self):
"""Check if data are computed"""
self.report.compute_data_for_report()
self.assertGreaterEqual(len(self.report.account_ids), 1)
def test_02_generation_report_qweb(self):
"""Check if report PDF/HTML is correctly generated"""
def _getQwebReportName(self):
return 'account_financial_report_qweb.report_trial_balance_qweb'
report_name = 'account_financial_report_qweb.' \
'report_trial_balance_qweb'
# Check if returned report action is correct
report_action = self.report.print_report(xlsx_report=False)
self.assertDictContainsSubset(
{
'type': 'ir.actions.report.xml',
'report_name': report_name,
'report_type': 'qweb-pdf',
},
report_action
)
def _getXlsxReportName(self):
return 'account_financial_report_qweb.report_trial_balance_xlsx'
# Check if report template is correct
report_html = self.env['report'].get_html(self.report, report_name)
self.assertRegexpMatches(report_html, 'Trial Balance')
self.assertRegexpMatches(report_html, self.report.account_ids[0].name)
def _getXlsxReportActionName(self):
return 'account_financial_report_qweb.action_report_trial_balance_xlsx'
def test_03_generation_report_xlsx(self):
"""Check if report XLSX is correctly generated"""
def _getReportTitle(self):
return 'Trial Balance'
report_name = 'account_financial_report_qweb.' \
'report_trial_balance_xlsx'
# Check if returned report action is correct
report_action = self.report.print_report(xlsx_report=True)
self.assertDictContainsSubset(
def _getBaseFilters(self):
return {
'date_from': time.strftime('%Y-01-01'),
'date_to': time.strftime('%Y-12-31'),
'company_id': self.env.ref('base.main_company').id,
'fy_start_date': time.strftime('%Y-01-01'),
}
def _getAdditionalFiltersToBeTested(self):
return [
{'only_posted_moves': True},
{'hide_account_balance_at_0': True},
{'show_partner_details': True},
{'only_posted_moves': True, 'hide_account_balance_at_0': True},
{'only_posted_moves': True, 'show_partner_details': True},
{'hide_account_balance_at_0': True, 'show_partner_details': True},
{
'type': 'ir.actions.report.xml',
'report_name': report_name,
'report_type': 'xlsx',
'only_posted_moves': True,
'hide_account_balance_at_0': True,
'show_partner_details': True
},
report_action
)
]
# Check if report template is correct
action_name = 'account_financial_report_qweb.' \
'action_report_trial_balance_xlsx'
report_xlsx = self.env.ref(action_name).render_report(
self.report.ids,
report_name,
{'report_type': u'xlsx'}
)
self.assertGreaterEqual(len(report_xlsx[0]), 1)
self.assertEqual(report_xlsx[1], 'xlsx')
def _partner_test_is_possible(self, filters):
return 'show_partner_details' in filters
Loading…
Cancel
Save