From e763ce063157f188378b000206fc54403dc41b89 Mon Sep 17 00:00:00 2001 From: jcoux Date: Wed, 27 Jul 2016 14:37:23 +0200 Subject: [PATCH] Add tests --- .../tests/__init__.py | 7 ++ .../tests/test_aged_partner_balance.py | 47 ++++++++++++ .../tests/test_general_ledger.py | 76 +++++++++++++++++++ .../tests/test_open_items.py | 47 ++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 account_financial_report_qweb/tests/__init__.py create mode 100644 account_financial_report_qweb/tests/test_aged_partner_balance.py create mode 100644 account_financial_report_qweb/tests/test_general_ledger.py create mode 100644 account_financial_report_qweb/tests/test_open_items.py diff --git a/account_financial_report_qweb/tests/__init__.py b/account_financial_report_qweb/tests/__init__.py new file mode 100644 index 00000000..bfbb9d14 --- /dev/null +++ b/account_financial_report_qweb/tests/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2016 Julien Coux (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).- + +from . import test_aged_partner_balance +from . import test_general_ledger +from . import test_open_items diff --git a/account_financial_report_qweb/tests/test_aged_partner_balance.py b/account_financial_report_qweb/tests/test_aged_partner_balance.py new file mode 100644 index 00000000..fe2456c2 --- /dev/null +++ b/account_financial_report_qweb/tests/test_aged_partner_balance.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Author: Julien Coux +# Copyright 2016 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import time +from openerp.tests.common import TransactionCase + + +class TestAgedPartnerBalance(TransactionCase): + + def setUp(cls): + super(TestAgedPartnerBalance, cls).setUp() + env = cls.env + model = env['report_aged_partner_balance_qweb'] + main_company = env.ref('base.main_company') + + 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""" + + 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 + ) + + # 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) diff --git a/account_financial_report_qweb/tests/test_general_ledger.py b/account_financial_report_qweb/tests/test_general_ledger.py new file mode 100644 index 00000000..462a73cb --- /dev/null +++ b/account_financial_report_qweb/tests/test_general_ledger.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +# Author: Julien Coux +# Copyright 2016 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import time +from openerp.tests.common import TransactionCase + + +class TestGeneralLedger(TransactionCase): + + def setUp(cls): + super(TestGeneralLedger, cls).setUp() + env = cls.env + model = env['report_general_ledger_qweb'] + main_company = env.ref('base.main_company') + + 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""" + + 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 + ) + + # 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 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( + { + '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_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') diff --git a/account_financial_report_qweb/tests/test_open_items.py b/account_financial_report_qweb/tests/test_open_items.py new file mode 100644 index 00000000..bd37e5ab --- /dev/null +++ b/account_financial_report_qweb/tests/test_open_items.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Author: Julien Coux +# Copyright 2016 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import time +from openerp.tests.common import TransactionCase + + +class TestOpenItems(TransactionCase): + + def setUp(cls): + super(TestOpenItems, cls).setUp() + env = cls.env + model = env['report_open_items_qweb'] + main_company = env.ref('base.main_company') + + 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""" + + 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 + ) + + # 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)