You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests.common import TransactionCase
  5. class TestTile(TransactionCase):
  6. def test_tile(self):
  7. tile_obj = self.env['tile.tile']
  8. model_id = self.env['ir.model'].search([
  9. ('model', '=', 'tile.tile')])
  10. field_id = self.env['ir.model.fields'].search([
  11. ('model_id', '=', model_id.id),
  12. ('name', '=', 'sequence')])
  13. self.tile1 = tile_obj.create({
  14. 'name': 'Count / Sum',
  15. 'sequence': 1,
  16. 'model_id': model_id.id,
  17. 'domain': "[('model_id', '=', %d)]" % model_id.id,
  18. 'secondary_function': 'sum',
  19. 'secondary_field_id': field_id.id})
  20. self.tile2 = tile_obj.create({
  21. 'name': 'Min / Max',
  22. 'sequence': 2,
  23. 'model_id': model_id.id,
  24. 'domain': "[('model_id', '=', %d)]" % model_id.id,
  25. 'primary_function': 'min',
  26. 'primary_field_id': field_id.id,
  27. 'secondary_function': 'max',
  28. 'secondary_field_id': field_id.id})
  29. self.tile3 = tile_obj.create({
  30. 'name': 'Avg / Median',
  31. 'sequence': 3,
  32. 'model_id': model_id.id,
  33. 'domain': "[('model_id', '=', %d)]" % model_id.id,
  34. 'primary_function': 'avg',
  35. 'primary_field_id': field_id.id,
  36. 'secondary_function': 'median',
  37. 'secondary_field_id': field_id.id})
  38. # count
  39. self.assertEqual(self.tile1.primary_value, '3')
  40. # sum
  41. self.assertEqual(self.tile1.secondary_value, '6')
  42. # min
  43. self.assertEqual(self.tile2.primary_value, '1')
  44. # max
  45. self.assertEqual(self.tile2.secondary_value, '3')
  46. # average
  47. self.assertEqual(self.tile3.primary_value, '2')
  48. # median
  49. self.assertEqual(self.tile3.secondary_value, '2.0')