Browse Source

[FIX] module_auto_update: Don't compute upgrade on uninstall

* `button_uninstall` calls `get_module_list`, which subsequently forces module upgrades. Add a context validation to prevent that
* Add test for button_immediate_uninstall
* Mock commit for immediate uninstall
* Fix immediate uninstall test
* Switch nesting
* Bump module version
pull/1118/head
Dave Lasley 7 years ago
committed by Jairo Llopis
parent
commit
84fb073ffe
  1. 2
      module_auto_update/__manifest__.py
  2. 7
      module_auto_update/models/module.py
  3. 39
      module_auto_update/tests/test_module.py
  4. 13
      module_auto_update/wizards/module_upgrade.py

2
module_auto_update/__manifest__.py

@ -5,7 +5,7 @@
{ {
'name': 'Module Auto Update', 'name': 'Module Auto Update',
'summary': 'Automatically update Odoo modules', 'summary': 'Automatically update Odoo modules',
'version': '10.0.1.0.0',
'version': '10.0.1.0.1',
'category': 'Extra Tools', 'category': 'Extra Tools',
'website': 'https://odoo-community.org/', 'website': 'https://odoo-community.org/',
'author': 'LasLabs, ' 'author': 'LasLabs, '

7
module_auto_update/models/module.py

@ -51,6 +51,13 @@ class Module(models.Model):
elif vals.get('state') == 'uninstalled': elif vals.get('state') == 'uninstalled':
self.write({'checksum_installed': False}) self.write({'checksum_installed': False})
@api.multi
def button_uninstall(self):
return super(
Module,
self.with_context(module_uninstall=True),
).button_uninstall()
@api.multi @api.multi
def button_uninstall_cancel(self): def button_uninstall_cancel(self):
return super( return super(

39
module_auto_update/tests/test_module.py

@ -22,6 +22,10 @@ except ImportError:
model = 'odoo.addons.module_auto_update.models.module' model = 'odoo.addons.module_auto_update.models.module'
class EndTestException(Exception):
pass
class TestModule(TransactionCase): class TestModule(TransactionCase):
def setUp(self): def setUp(self):
@ -122,6 +126,41 @@ class TestModule(TransactionCase):
'overwrite', 'overwrite',
) )
@mock.patch('%s.get_module_path' % model)
def test_button_uninstall_no_recompute(self, module_path_mock):
"""It should not attempt update on `button_uninstall`."""
module_path_mock.return_value = self.own_dir_path
vals = {
'name': 'module_auto_update_test_module',
'state': 'installed',
}
test_module = self.create_test_module(vals)
test_module.checksum_installed = 'test'
uninstall_module = self.env['ir.module.module'].search([
('name', '=', 'web'),
])
uninstall_module.button_uninstall()
self.assertNotEqual(
test_module.state, 'to upgrade',
'Auto update logic was triggered during uninstall.',
)
def test_button_immediate_uninstall_no_recompute(self):
"""It should not attempt update on `button_immediate_uninstall`."""
uninstall_module = self.env['ir.module.module'].search([
('name', '=', 'web'),
])
try:
mk = mock.MagicMock()
uninstall_module._patch_method('button_uninstall', mk)
mk.side_effect = EndTestException
with self.assertRaises(EndTestException):
uninstall_module.button_immediate_uninstall()
finally:
uninstall_module._revert_method('button_uninstall')
def test_button_uninstall_cancel(self): def test_button_uninstall_cancel(self):
"""It should preserve checksum_installed when cancelling uninstall""" """It should preserve checksum_installed when cancelling uninstall"""
self.own_module.write({'state': 'to remove'}) self.own_module.write({'state': 'to remove'})

13
module_auto_update/wizards/module_upgrade.py

@ -10,12 +10,13 @@ class ModuleUpgrade(models.TransientModel):
@api.model @api.model
def get_module_list(self): def get_module_list(self):
Module = self.env["ir.module.module"]
installed_modules = Module.search([('state', '=', 'installed')])
upgradeable_modules = installed_modules.filtered(
lambda r: r.checksum_dir != r.checksum_installed,
)
upgradeable_modules.button_upgrade()
if not self.env.context.get('module_uninstall'):
Module = self.env["ir.module.module"]
installed_modules = Module.search([('state', '=', 'installed')])
upgradeable_modules = installed_modules.filtered(
lambda r: r.checksum_dir != r.checksum_installed,
)
upgradeable_modules.button_upgrade()
return super(ModuleUpgrade, self).get_module_list() return super(ModuleUpgrade, self).get_module_list()
@api.multi @api.multi

Loading…
Cancel
Save