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.

86 lines
2.7 KiB

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