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.

44 lines
1.6 KiB

7 years ago
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  4. import mock
  5. from odoo.modules import get_module_path
  6. from odoo.modules.registry import Registry
  7. from odoo.tests.common import TransactionCase
  8. class TestModuleUpgrade(TransactionCase):
  9. def setUp(self):
  10. super(TestModuleUpgrade, self).setUp()
  11. module_name = 'module_auto_update'
  12. self.own_module = self.env['ir.module.module'].search([
  13. ('name', '=', module_name),
  14. ])
  15. self.own_dir_path = get_module_path(module_name)
  16. def test_upgrade_module_cancel(self):
  17. """It should preserve checksum_installed when cancelling upgrades"""
  18. self.own_module.write({'state': 'to upgrade'})
  19. self.own_module.checksum_installed = 'test'
  20. self.env['base.module.upgrade'].upgrade_module_cancel()
  21. self.assertEqual(
  22. self.own_module.checksum_installed, 'test',
  23. 'Upgrade cancellation does not preserve checksum_installed',
  24. )
  25. @mock.patch.object(Registry, 'new')
  26. def test_upgrade_module(self, new_mock):
  27. """Calls get_module_list when upgrading in api.model mode"""
  28. get_module_list_mock = mock.MagicMock()
  29. try:
  30. self.env['base.module.upgrade']._patch_method(
  31. 'get_module_list',
  32. get_module_list_mock,
  33. )
  34. self.env['base.module.upgrade'].upgrade_module()
  35. get_module_list_mock.assert_called_once_with()
  36. finally:
  37. self.env['base.module.upgrade']._revert_method('get_module_list')