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.

80 lines
2.6 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. def setUp(self):
  42. super(TestBaseKanbanAbstract, self).setUp()
  43. test_stage_1 = self.env['base.kanban.stage'].create({
  44. 'name': 'Test Stage 1',
  45. 'res_model_id': self.test_model_record.id,
  46. })
  47. test_stage_2 = self.env['base.kanban.stage'].create({
  48. 'name': 'Test Stage 2',
  49. 'res_model_id': self.test_model_record.id,
  50. 'fold': True,
  51. })
  52. self.id_1 = test_stage_1.id
  53. self.id_2 = test_stage_2.id
  54. def test_read_group_stage_ids(self):
  55. """It should return the correct recordset. """
  56. self.assertEqual(
  57. self.test_model._read_group_stage_ids(
  58. self.env['base.kanban.stage'], [], 'id',
  59. ),
  60. self.env['base.kanban.stage'].search([], order='id'),
  61. )
  62. def test_default_stage_id(self):
  63. """ It should return an empty RecordSet """
  64. self.assertEqual(
  65. self.env['base.kanban.abstract']._default_stage_id(),
  66. self.env['base.kanban.stage']
  67. )