OCA reporting engine fork for dev and update.
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.

87 lines
2.7 KiB

7 years ago
  1. # -*- coding: utf-8 -*-
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from openerp.tests.common import TransactionCase
  4. class TestKPI(TransactionCase):
  5. def setUp(self):
  6. super(TestKPI, self).setUp()
  7. def test_invalid_threshold_range(self):
  8. range1 = self.env['kpi.threshold.range'].create({
  9. 'name': 'Range1',
  10. 'min_type': 'static',
  11. 'max_type': 'static',
  12. 'min_fixed_value': 3,
  13. 'max_fixed_value': 1,
  14. })
  15. range2 = self.env['kpi.threshold.range'].create({
  16. 'name': 'Range2',
  17. 'min_type': 'static',
  18. 'max_type': 'static',
  19. 'min_fixed_value': 4,
  20. 'max_fixed_value': 10,
  21. })
  22. self.assertFalse(range1.valid)
  23. self.assertTrue(range2.valid)
  24. def test_invalid_threshold(self):
  25. range1 = self.env['kpi.threshold.range'].create({
  26. 'name': 'Range1',
  27. 'min_type': 'static',
  28. 'max_type': 'static',
  29. 'min_fixed_value': 1,
  30. 'max_fixed_value': 4,
  31. })
  32. range2 = self.env['kpi.threshold.range'].create({
  33. 'name': 'Range2',
  34. 'min_type': 'static',
  35. 'max_type': 'static',
  36. 'min_fixed_value': 4,
  37. 'max_fixed_value': 10,
  38. })
  39. range3 = self.env['kpi.threshold.range'].create({
  40. 'name': 'Range3',
  41. 'min_type': 'static',
  42. 'max_type': 'static',
  43. 'min_fixed_value': 1,
  44. 'max_fixed_value': 3,
  45. })
  46. range_invalid = self.env['kpi.threshold.range'].create({
  47. 'name': 'RangeInvalid',
  48. 'min_type': 'static',
  49. 'max_type': 'static',
  50. 'min_fixed_value': 3,
  51. 'max_fixed_value': 1,
  52. })
  53. threshold1 = self.env['kpi.threshold'].create({
  54. 'name': 'Threshold1',
  55. 'range_ids': [(6, 0, [range1.id, range2.id])],
  56. })
  57. threshold2 = self.env['kpi.threshold'].create({
  58. 'name': 'Threshold1',
  59. 'range_ids': [(6, 0, [range3.id, range2.id])],
  60. })
  61. threshold3 = self.env['kpi.threshold'].create({
  62. 'name': 'Threshold1',
  63. 'range_ids': [(6, 0, [range_invalid.id, range2.id])],
  64. })
  65. self.assertFalse(threshold1.valid)
  66. self.assertTrue(threshold2.valid)
  67. self.assertFalse(threshold3.valid)
  68. def test_invalid_threshold_range_exception(self):
  69. range_error = self.env['kpi.threshold.range'].create({
  70. 'name': 'RangeError',
  71. 'min_type': 'python',
  72. 'min_code': '<Not a valid python expression>',
  73. 'max_type': 'static',
  74. 'max_fixed_value': 1,
  75. })
  76. self.assertFalse(range_error.valid)