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/1382/head
Dave Lasley 7 years ago
committed by Stéphane Bidoul (ACSONE)
parent
commit
dd871c76cc
No known key found for this signature in database GPG Key ID: BCAB2555446B5B92
  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. 1
      module_auto_update/wizards/module_upgrade.py

2
module_auto_update/__manifest__.py

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

7
module_auto_update/models/module.py

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

39
module_auto_update/tests/test_module.py

@ -22,6 +22,10 @@ except ImportError:
model = 'odoo.addons.module_auto_update.models.module'
class EndTestException(Exception):
pass
class TestModule(TransactionCase):
def setUp(self):
@ -122,6 +126,41 @@ class TestModule(TransactionCase):
'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):
"""It should preserve checksum_installed when cancelling uninstall"""
self.own_module.write({'state': 'to remove'})

1
module_auto_update/wizards/module_upgrade.py

@ -10,6 +10,7 @@ class ModuleUpgrade(models.TransientModel):
@api.model
def get_module_list(self):
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(

Loading…
Cancel
Save