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.

85 lines
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. from odoo import models
  5. from odoo.tests.common import SavepointCase
  6. class BaseKanbanAbstractTester(models.TransientModel):
  7. _name = 'base.kanban.abstract.tester'
  8. _inherit = 'base.kanban.abstract'
  9. class TestBaseKanbanAbstract(SavepointCase):
  10. @classmethod
  11. def _init_test_model(cls, model_cls):
  12. """ It builds a model from model_cls in order to test abstract models.
  13. Note that this does not actually create a table in the database, so
  14. there may be some unidentified edge cases.
  15. Args:
  16. model_cls (openerp.models.BaseModel): Class of model to initialize
  17. Returns:
  18. model_cls: Instance
  19. """
  20. registry = cls.env.registry
  21. cr = cls.env.cr
  22. inst = model_cls._build_model(registry, cr)
  23. model = cls.env[model_cls._name].with_context(todo=[])
  24. model._prepare_setup()
  25. model._setup_base(partial=False)
  26. model._setup_fields(partial=False)
  27. model._setup_complete()
  28. model._auto_init()
  29. model.init()
  30. model._auto_end()
  31. cls.test_model_record = cls.env['ir.model'].search([
  32. ('name', '=', model._name),
  33. ])
  34. return inst
  35. @classmethod
  36. def setUpClass(cls):
  37. super(TestBaseKanbanAbstract, cls).setUpClass()
  38. cls.env.registry.enter_test_mode()
  39. cls._init_test_model(BaseKanbanAbstractTester)
  40. cls.test_model = cls.env[BaseKanbanAbstractTester._name]
  41. @classmethod
  42. def tearDownClass(cls):
  43. cls.env.registry.leave_test_mode()
  44. super(TestBaseKanbanAbstract, cls).tearDownClass()
  45. def setUp(self):
  46. super(TestBaseKanbanAbstract, self).setUp()
  47. test_stage_1 = self.env['base.kanban.stage'].create({
  48. 'name': 'Test Stage 1',
  49. 'res_model_id': self.test_model_record.id,
  50. })
  51. test_stage_2 = self.env['base.kanban.stage'].create({
  52. 'name': 'Test Stage 2',
  53. 'res_model_id': self.test_model_record.id,
  54. 'fold': True,
  55. })
  56. self.id_1 = test_stage_1.id
  57. self.id_2 = test_stage_2.id
  58. def test_read_group_stage_ids(self):
  59. """It should return the correct recordset. """
  60. self.assertEqual(
  61. self.test_model._read_group_stage_ids(
  62. self.env['base.kanban.stage'], [], 'id',
  63. ),
  64. self.env['base.kanban.stage'].search([], order='id'),
  65. )
  66. def test_default_stage_id(self):
  67. """ It should return an empty RecordSet """
  68. self.assertEqual(
  69. self.env['base.kanban.abstract']._default_stage_id(),
  70. self.env['base.kanban.stage']
  71. )