Browse Source

[WIP] mis_builder refactoring: fix and clean the test

pull/189/head
Stéphane Bidoul 9 years ago
parent
commit
272427006b
  1. 18
      mis_builder/models/mis_report.py
  2. 3
      mis_builder/tests/__init__.py
  3. 39
      mis_builder/tests/test_fetch_query.py
  4. 72
      mis_builder/tests/test_mis_builder.py
  5. 25
      mis_builder/tests/test_utc_midnight.py

18
mis_builder/models/mis_report.py

@ -55,6 +55,13 @@ class KpiMatrixRow(object):
else: else:
return None # TODO style for expanded accounts return None # TODO style for expanded accounts
@property
def row_id(self):
if not self.account_id:
return self.kpi.name
else:
return '{}:{}'.format(self.kpi.name, self.account_id)
def iter_cell_tuples(self, cols=None): def iter_cell_tuples(self, cols=None):
if cols is None: if cols is None:
cols = self._matrix.iter_cols() cols = self._matrix.iter_cols()
@ -215,12 +222,12 @@ class KpiMatrix(object):
else: else:
val_rendered = kpi.render(self.lang, val) val_rendered = kpi.render(self.lang, val)
if subcol.subkpi: if subcol.subkpi:
val_comment = "{}.{} = {}".format(
val_comment = u'{}.{} = {}'.format(
row.kpi.name, row.kpi.name,
subcol.subkpi.name, subcol.subkpi.name,
row.kpi.get_expression_for_subkpi(subcol.subkpi)) row.kpi.get_expression_for_subkpi(subcol.subkpi))
else: else:
val_comment = "{} = {}".format(
val_comment = u'{} = {}'.format(
row.kpi.name, row.kpi.name,
row.kpi.expression) row.kpi.expression)
# TODO style # TODO style
@ -339,8 +346,9 @@ class KpiMatrix(object):
content = [] content = []
for row in self.iter_rows(): for row in self.iter_rows():
row_data = { row_data = {
'row_id': id(row),
'parent_row_id': row.parent_row and id(row.parent_row) or None,
'row_id': row.row_id,
'parent_row_id': (row.parent_row and
row.parent_row.row_id or None),
'description': row.description, 'description': row.description,
'comment': row.comment, 'comment': row.comment,
'style': row.style and row.style.to_css_style() or None, 'style': row.style and row.style.to_css_style() or None,
@ -472,7 +480,7 @@ class MisReportKpi(models.Model):
l = [] l = []
for expression in kpi.expression_ids: for expression in kpi.expression_ids:
if expression.subkpi_id: if expression.subkpi_id:
l.append('{}={}'.format(
l.append(u'{} = {}'.format(
expression.subkpi_id.name, expression.name)) expression.subkpi_id.name, expression.name))
else: else:
l.append( l.append(

3
mis_builder/tests/__init__.py

@ -5,6 +5,7 @@
from . import test_accounting_none from . import test_accounting_none
from . import test_aep from . import test_aep
from . import test_aggregate from . import test_aggregate
from . import test_mis_builder
from . import test_fetch_query
from . import test_mis_safe_eval from . import test_mis_safe_eval
from . import test_simple_array from . import test_simple_array
from . import test_utc_midnight

39
mis_builder/tests/test_fetch_query.py

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# © 2014-2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import openerp.tests.common as common
class TestFetchQuery(common.TransactionCase):
def test_fetch_query(self):
# create a report on account.analytic.line
data = self.registry('mis.report.instance').compute(
self.cr, self.uid,
self.ref('mis_builder.mis_report_instance_test'))
self.assertEquals(
{'content':
[{'description': u'total test',
'comment': '',
'style': None,
'parent_row_id': None,
'row_id': u'total_test',
'cols': [{'val': 0,
'val_r': u'\xa00\xa0',
'val_c': u'total_test = len(test)',
}]
}],
'header':
[{'cols': [{'comment': '07/31/2014',
'colspan': 1,
'description': u'today',
}],
},
{'cols': [{'colspan': 1,
'description': '',
'comment': '',
}],
},
],
}, data)

72
mis_builder/tests/test_mis_builder.py

@ -1,72 +0,0 @@
# -*- coding: utf-8 -*-
# © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import openerp.tests.common as common
from ..models import mis_builder
class TestMisBuilder(common.TransactionCase):
def setUp(self):
super(TestMisBuilder, self).setUp()
def test_datetime_conversion(self):
date_to_convert = '2014-07-05'
date_time_convert = mis_builder._utc_midnight(
date_to_convert, 'Europe/Brussels')
self.assertEqual(date_time_convert, '2014-07-04 22:00:00',
'The converted date time convert must contains hour')
date_time_convert = mis_builder._utc_midnight(
date_to_convert, 'Europe/Brussels', add_day=1)
self.assertEqual(date_time_convert, '2014-07-05 22:00:00',
'The converted date time convert must contains hour')
date_time_convert = mis_builder._utc_midnight(
date_to_convert, 'US/Pacific')
self.assertEqual(date_time_convert, '2014-07-05 07:00:00',
'The converted date time convert must contains hour')
date_time_convert = mis_builder._utc_midnight(
date_to_convert, 'US/Pacific', add_day=1)
self.assertEqual(date_time_convert, '2014-07-06 07:00:00',
'The converted date time convert must contains hour')
def test_fetch_query(self):
# create a report on account.analytic.line
data = self.registry('mis.report.instance').compute(
self.cr, self.uid,
self.ref('mis_builder.mis_report_instance_test'))
self.assertDictContainsSubset(
{'content':
[{'kpi_name': u'total test',
'default_style': '',
'default_xlsx_style': {},
'cols': [{'period_id': self.ref('mis_builder.'
'mis_report_instance_'
'period_test'),
'style': '',
'xlsx_style': {},
'prefix': False,
'suffix': False,
'expr': u'len(test)',
'val_c': u'total_test = len(test)',
'val': 0,
'val_r': u'\u202f0\xa0',
'is_percentage': False,
'dp': 0,
'drilldown': False}]
}],
'header':
[{'kpi_name': '',
'cols': [{'date': '07/31/2014',
'colspan': 1,
'name': u'today',
}],
},
{'kpi_name': '',
'cols': [{'colspan': 1,
'name': '',
}],
},
],
}, data)

25
mis_builder/tests/test_utc_midnight.py

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import openerp.tests.common as common
from ..models.mis_report import _utc_midnight
class TestUtcMidnight(common.TransactionCase):
def test_utc_midnight(self):
date_to_convert = '2014-07-05'
date_time_convert = _utc_midnight(
date_to_convert, 'Europe/Brussels')
self.assertEqual(date_time_convert, '2014-07-04 22:00:00')
date_time_convert = _utc_midnight(
date_to_convert, 'Europe/Brussels', add_day=1)
self.assertEqual(date_time_convert, '2014-07-05 22:00:00')
date_time_convert = _utc_midnight(
date_to_convert, 'US/Pacific')
self.assertEqual(date_time_convert, '2014-07-05 07:00:00')
date_time_convert = _utc_midnight(
date_to_convert, 'US/Pacific', add_day=1)
self.assertEqual(date_time_convert, '2014-07-06 07:00:00')
Loading…
Cancel
Save