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.

65 lines
2.7 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Module - Parent Dependencies module for Odoo
  5. # Copyright (C) 2014 GRAP (http://www.grap.coop)
  6. # @author Sylvain LE GAL (https://twitter.com/legalsylvain)
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp.tests.common import TransactionCase
  23. class TestmoduleParentDependencies(TransactionCase):
  24. """Tests for 'Parent Dependencies module' Module"""
  25. def setUp(self):
  26. super(TestmoduleParentDependencies, self).setUp()
  27. self.im_obj = self.registry('ir.module.module')
  28. # Test Section
  29. def test_01_direct_parent(self):
  30. """Test if the compute of the field direct_parent_ids is correct."""
  31. cr, uid = self.cr, self.uid
  32. # compute expected values
  33. cr.execute("""SELECT module_id
  34. FROM ir_module_module_dependency immd
  35. INNER JOIN ir_module_module imm on imm.id = immd.module_id
  36. WHERE immd.name='base'
  37. AND imm.state not in ('uninstalled', 'uninstallable')""")
  38. expected_parent_ids = [x[0] for x in cr.fetchall()]
  39. # Get values
  40. base_id = self.im_obj.search(cr, uid, [('name', '=', 'base')])
  41. tmp = self.im_obj.browse(
  42. cr, uid, base_id)
  43. parent_ids = [x.id for x in tmp[0].direct_parent_ids]
  44. self.assertEqual(
  45. sorted(parent_ids), sorted(expected_parent_ids),
  46. "Incorrect computation of 'direct_parent_id's fields.")
  47. def test_02_all_parent(self):
  48. """Test if the compute of the field direct_parent_ids doesn't crash."""
  49. cr, uid = self.cr, self.uid
  50. base_id = self.im_obj.search(cr, uid, [('name', '=', 'base')])
  51. tmp = self.im_obj.browse(
  52. cr, uid, base_id)
  53. parent_ids = [x.id for x in tmp[0].all_parent_ids]
  54. self.assertNotEqual(
  55. sorted(parent_ids), [],
  56. "Incorrect computation of 'direct_parent_id's fields.")