From 9b95ddd50c7c037f970e57cf43032fc9b6633897 Mon Sep 17 00:00:00 2001 From: angelmoya Date: Tue, 22 Dec 2020 10:18:50 +0100 Subject: [PATCH] [IMP] mail_restrict_follower_selection: Adding tests and improving pre-commit --- .../models/mail_followers.py | 7 +++---- .../models/mail_wizard_invite.py | 18 +++++++++++------- .../test_mail_restrict_follower_selection.py | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/mail_restrict_follower_selection/models/mail_followers.py b/mail_restrict_follower_selection/models/mail_followers.py index 3576e15..30ca69c 100644 --- a/mail_restrict_follower_selection/models/mail_followers.py +++ b/mail_restrict_follower_selection/models/mail_followers.py @@ -35,11 +35,10 @@ class MailFollowers(models.Model): existing_policy=existing_policy, ) domain = self.env[ - 'mail.wizard.invite' + "mail.wizard.invite" ]._mail_restrict_follower_selection_get_domain(res_model=res_model) - partners = self.env['res.partner'].search( - [('id', 'in', partner_ids)] + - safe_eval(domain) + partners = self.env["res.partner"].search( + [("id", "in", partner_ids)] + safe_eval(domain) ) _res_ids = res_ids.copy() or [0] new, update = super()._add_followers( diff --git a/mail_restrict_follower_selection/models/mail_wizard_invite.py b/mail_restrict_follower_selection/models/mail_wizard_invite.py index 0d579f7..9434f15 100644 --- a/mail_restrict_follower_selection/models/mail_wizard_invite.py +++ b/mail_restrict_follower_selection/models/mail_wizard_invite.py @@ -13,13 +13,17 @@ class MailWizardInvite(models.TransientModel): @api.model def _mail_restrict_follower_selection_get_domain(self, res_model=None): if not res_model: - res_model = self.env.context.get('default_res_model') - parameter_name = 'mail_restrict_follower_selection.domain' - return self.env['ir.config_parameter'].sudo().get_param( - "{0}.{1}".format(parameter_name, - res_model), - self.env['ir.config_parameter'].sudo().get_param( - parameter_name, default='[]') + res_model = self.env.context.get("default_res_model") + parameter_name = "mail_restrict_follower_selection.domain" + return ( + self.env["ir.config_parameter"] + .sudo() + .get_param( + "{}.{}".format(parameter_name, res_model), + self.env["ir.config_parameter"] + .sudo() + .get_param(parameter_name, default="[]"), + ) ) @api.model diff --git a/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py b/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py index 9806569..e8bf056 100644 --- a/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py +++ b/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py @@ -64,3 +64,19 @@ class TestMailRestrictFollowerSelection(TransactionCase): self.assertNotIn( self.partner, self.partner.message_follower_ids.mapped("partner_id") ) + + def test_message_add_suggested_recipient(self): + res = self.partner.with_context( + test_restrict_follower=True + )._message_add_suggested_recipient({self.partner.id: []}, partner=self.partner) + self.assertEqual(res[self.partner.id][0][0], self.partner.id) + self.env["ir.config_parameter"].create( + { + "key": "mail_restrict_follower_selection.domain.res.partner", + "value": "[('category_id.name', '!=', 'Employees')]", + } + ) + new_res = self.partner.with_context( + test_restrict_follower=True + )._message_add_suggested_recipient({self.partner.id: []}) + self.assertFalse(new_res[self.partner.id][0][0])