Best Python code snippet using autotest_python
test_uninstall.py
Source: test_uninstall.py
1# -*- coding: utf-8 -*-2from unittest.mock import MagicMock, PropertyMock3from odoo import models4from odoo.addons.cerp_core.models.uninstall import (5 _filter_affected_models)6from ._base import TestCloudERPModels7_filter_affected_param_list = (8 ([], None, False),9 ([], False, False),10 ([], [], False),11 ([], ['other.foo'], False),12 ([], ['keychain2.foo'], True),13 ([], ['keychain2.foo', 'other.bar'], True),14 (['notkeychain2'], ['keychain2.foo', 'other.bar'], True),15 ([], ['other.model_cerp_core_account'], True),16 ([], ['other.model_cerp_core_account', 'other.bar'], True),17 (['baz.foo'], ['other.model_cerp_core_account', 'other.bar'], True),18 (['foo'], ['foo.bar', 'foo.baz'], True),19 (['foo', 'bar'], ['foo.bar', 'bar.baz'], True),20 (['foo'], ['foo.bar', 'foo.baz'], True),21 (['foo', 'bar'], ['foo.bar', 'baz.foo'], False))22class TestCloudERPModuleUninstall(TestCloudERPModels):23 def test_uninstall_wizard(self):24 keychain = self.env['ir.module.module'].search(25 [('name', '=', 'keychain2')])26 wizard = self.env['cerp_core.module.uninstall'].create(27 dict(module_id=keychain.id))28 assert wizard._inherit == 'base.module.uninstall'29 assert isinstance(wizard, models.TransientModel)30 def test_get_models(self):31 keychain = self.env['ir.module.module'].search(32 [('name', '=', 'keychain2')])33 wizard = self.env['cerp_core.module.uninstall'].create(34 dict(module_id=keychain.id))35 wizard.env = MagicMock()36 _models = wizard._get_models()37 assert (38 list(wizard.env.__getitem__.call_args)39 == [('ir.model',), {}])40 assert (41 list(wizard.env.__getitem__.return_value.search.call_args)42 == [([('transient', '=', False)],), {}])43 assert (44 _models45 == wizard.env.__getitem__.return_value.search.return_value)46 def test_action_uninstall(self):47 keychain = self.env['ir.module.module'].search(48 [('name', '=', 'keychain2')])49 wizard = self.env['cerp_core.module.uninstall'].create(50 dict(module_id=keychain.id))51 wizard.env = MagicMock()52 wizard.ensure_one = MagicMock()53 _module_id = type(wizard).module_id54 type(wizard).module_id = MagicMock()55 _patch = self._patch('models.uninstall.utils.success_action')56 with _patch as success_mock:57 result = wizard.action_uninstall()58 assert wizard.ensure_one.called59 assert wizard.module_id.button_immediate_uninstall.called60 assert (61 list(success_mock.call_args)62 == [(wizard.env,63 "Module (%s) uninstalled" % (wizard.module_id.name)), {}])64 assert result == success_mock.return_value65 type(wizard).module_id = _module_id66 def test_compute_model_ids(self):67 keychain = self.env['ir.module.module'].search(68 [('name', '=', 'keychain2')])69 wizard = self.env['cerp_core.module.uninstall'].create(70 dict(module_id=keychain.id))71 wizard._get_models = MagicMock()72 assert (73 wizard._compute_model_ids._depends74 == ('module_ids',))75 _model_ids = type(wizard).model_ids76 _get_modules = type(wizard)._get_modules77 type(wizard).model_ids = MagicMock(new_callable=PropertyMock)78 get_modules_mock = MagicMock()79 type(wizard)._get_modules = get_modules_mock80 wizard._get_modules = MagicMock()81 with self._patch('models.uninstall.functools') as funct_mock:82 with self._patch('models.uninstall.set') as set_mock:83 wizard._compute_model_ids()84 assert wizard._get_models.called85 assert not wizard._get_modules.called86 assert get_modules_mock.called87 assert (88 list(get_modules_mock.return_value.mapped.call_args)89 == [('name',), {}])90 assert (91 list(set_mock.call_args)92 == [(get_modules_mock.return_value.mapped.return_value,), {}])93 assert (94 list(list(c) for c in set_mock.return_value.add.call_args_list)95 == [[('cerp_core',), {}]])96 _ir_models = wizard._get_models.return_value97 _ir_models_xids = _ir_models._get_external_ids.return_value98 assert (99 wizard.model_ids100 == _ir_models.filtered.return_value.sorted.return_value)101 assert (102 list(_ir_models.filtered.call_args)103 == [(funct_mock.partial.return_value,), {}])104 assert (105 list(funct_mock.partial.call_args)106 == [(_filter_affected_models,107 set_mock.return_value,108 _ir_models_xids), {}])109 type(wizard).model_ids = _model_ids110 type(wizard)._get_modules = _get_modules111 def test_filter_affected_models(self):112 _model = MagicMock()113 _xids = MagicMock()114 for _mods, _xids_return, expected in _filter_affected_param_list:115 with self.subTest():116 _xids.get.return_value = _xids_return117 assert (118 _filter_affected_models(_mods, _xids, _model)119 == expected)120 assert (121 list(_xids.get.call_args)122 == [(_model.id, ()), {}])...
base_module_uninstall.py
Source: base_module_uninstall.py
...13 module_ids = fields.Many2many('ir.module.module', string="Impacted modules",14 compute='_compute_module_ids')15 model_ids = fields.Many2many('ir.model', string="Impacted data models",16 compute='_compute_model_ids')17 def _get_modules(self):18 """ Return all the modules impacted by self. """19 return self.module_id.downstream_dependencies(self.module_id)20 @api.depends('module_id', 'show_all')21 def _compute_module_ids(self):22 for wizard in self:23 modules = wizard._get_modules()24 wizard.module_ids = modules if wizard.show_all else modules.filtered('application')25 def _get_models(self):26 """ Return the models (ir.model) to consider for the impact. """27 return self.env['ir.model'].search([('transient', '=', False)])28 @api.depends('module_ids')29 def _compute_model_ids(self):30 ir_models = self._get_models()31 ir_models_xids = ir_models._get_external_ids()32 for wizard in self:33 if wizard.module_id:34 module_names = set(wizard._get_modules().mapped('name'))35 def lost(model):36 xids = ir_models_xids.get(model.id, ())37 return xids and all(xid.split('.')[0] in module_names for xid in xids)38 # find the models that have all their XIDs in the given modules39 self.model_ids = ir_models.filtered(lost).sorted('name')40 @api.onchange('module_id')41 def _onchange_module_id(self):42 # if we select a technical module, show technical modules by default43 if not self.module_id.application:44 self.show_all = True45 def action_uninstall(self):46 modules = self.module_id...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!