From 19f059b783fab6efb410164c81c2a50a823283c2 Mon Sep 17 00:00:00 2001 From: "laurent.corron" Date: Thu, 14 Nov 2019 15:39:25 +0100 Subject: [PATCH] [REF] web_notify: Black python code --- web_notify/__manifest__.py | 30 ++++++++-------------- web_notify/models/res_users.py | 26 +++++-------------- web_notify/tests/test_res_users.py | 41 ++++++++---------------------- 3 files changed, 27 insertions(+), 70 deletions(-) diff --git a/web_notify/__manifest__.py b/web_notify/__manifest__.py index cfee5407c..1c5353ce4 100644 --- a/web_notify/__manifest__.py +++ b/web_notify/__manifest__.py @@ -3,25 +3,15 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Web Notify', - 'summary': """ + "name": "Web Notify", + "summary": """ Send notification messages to user""", - 'version': '12.0.1.0.0', - 'license': 'AGPL-3', - 'author': 'ACSONE SA/NV,' - 'AdaptiveCity,' - 'Odoo Community Association (OCA)', - 'website': 'https://github.com/OCA/web', - 'depends': [ - 'web', - 'bus', - 'base', - ], - 'data': [ - 'views/web_notify.xml' - ], - 'demo': [ - 'views/res_users_demo.xml' - ], - 'installable': True, + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV," "AdaptiveCity," "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "depends": ["web", "bus", "base"], + "data": ["views/web_notify.xml"], + "demo": ["views/res_users_demo.xml"], + "installable": True, } diff --git a/web_notify/models/res_users.py b/web_notify/models/res_users.py index 76d80aee0..d973940ea 100644 --- a/web_notify/models/res_users.py +++ b/web_notify/models/res_users.py @@ -32,21 +32,15 @@ class ResUsers(models.Model): notify_info_channel_name = fields.Char(compute="_compute_channel_names") notify_default_channel_name = fields.Char(compute="_compute_channel_names") - def notify_success( - self, message="Default message", title=None, sticky=False - ): + def notify_success(self, message="Default message", title=None, sticky=False): title = title or _("Success") self._notify_channel(SUCCESS, message, title, sticky) - def notify_danger( - self, message="Default message", title=None, sticky=False - ): + def notify_danger(self, message="Default message", title=None, sticky=False): title = title or _("Danger") self._notify_channel(DANGER, message, title, sticky) - def notify_warning( - self, message="Default message", title=None, sticky=False - ): + def notify_warning(self, message="Default message", title=None, sticky=False): title = title or _("Warning") self._notify_channel(WARNING, message, title, sticky) @@ -54,18 +48,12 @@ class ResUsers(models.Model): title = title or _("Information") self._notify_channel(INFO, message, title, sticky) - def notify_default( - self, message="Default message", title=None, sticky=False - ): + def notify_default(self, message="Default message", title=None, sticky=False): title = title or _("Default") self._notify_channel(DEFAULT, message, title, sticky) def _notify_channel( - self, - type_message=DEFAULT, - message=DEFAULT_MESSAGE, - title=None, - sticky=False, + self, type_message=DEFAULT, message=DEFAULT_MESSAGE, title=None, sticky=False ): # pylint: disable=protected-access if not self.env.user._is_admin() and any( @@ -81,7 +69,5 @@ class ResUsers(models.Model): "title": title, "sticky": sticky, } - notifications = [ - (record[channel_name_field], bus_message) for record in self - ] + notifications = [(record[channel_name_field], bus_message) for record in self] self.env["bus.bus"].sendmany(notifications) diff --git a/web_notify/tests/test_res_users.py b/web_notify/tests/test_res_users.py index 36b003323..0904be2cf 100644 --- a/web_notify/tests/test_res_users.py +++ b/web_notify/tests/test_res_users.py @@ -4,21 +4,20 @@ import json import mock + from odoo import exceptions -from odoo.addons.bus.models.bus import json_dump -from ..models.res_users import SUCCESS, DANGER, WARNING, INFO, DEFAULT from odoo.tests import common +from odoo.addons.bus.models.bus import json_dump + +from ..models.res_users import DANGER, DEFAULT, INFO, SUCCESS, WARNING + class TestResUsers(common.TransactionCase): def test_notify_success(self): bus_bus = self.env["bus.bus"] domain = [ - ( - "channel", - "=", - json_dump(self.env.user.notify_success_channel_name), - ) + ("channel", "=", json_dump(self.env.user.notify_success_channel_name)) ] existing = bus_bus.search(domain) test_msg = {"message": "message", "title": "title", "sticky": True} @@ -30,13 +29,7 @@ class TestResUsers(common.TransactionCase): def test_notify_danger(self): bus_bus = self.env["bus.bus"] - domain = [ - ( - "channel", - "=", - json_dump(self.env.user.notify_danger_channel_name), - ) - ] + domain = [("channel", "=", json_dump(self.env.user.notify_danger_channel_name))] existing = bus_bus.search(domain) test_msg = {"message": "message", "title": "title", "sticky": True} self.env.user.notify_danger(**test_msg) @@ -48,11 +41,7 @@ class TestResUsers(common.TransactionCase): def test_notify_warning(self): bus_bus = self.env["bus.bus"] domain = [ - ( - "channel", - "=", - json_dump(self.env.user.notify_warning_channel_name), - ) + ("channel", "=", json_dump(self.env.user.notify_warning_channel_name)) ] existing = bus_bus.search(domain) test_msg = {"message": "message", "title": "title", "sticky": True} @@ -64,9 +53,7 @@ class TestResUsers(common.TransactionCase): def test_notify_info(self): bus_bus = self.env["bus.bus"] - domain = [ - ("channel", "=", json_dump(self.env.user.notify_info_channel_name)) - ] + domain = [("channel", "=", json_dump(self.env.user.notify_info_channel_name))] existing = bus_bus.search(domain) test_msg = {"message": "message", "title": "title", "sticky": True} self.env.user.notify_info(**test_msg) @@ -78,11 +65,7 @@ class TestResUsers(common.TransactionCase): def test_notify_default(self): bus_bus = self.env["bus.bus"] domain = [ - ( - "channel", - "=", - json_dump(self.env.user.notify_default_channel_name), - ) + ("channel", "=", json_dump(self.env.user.notify_default_channel_name)) ] existing = bus_bus.search(domain) test_msg = {"message": "message", "title": "title", "sticky": True} @@ -95,9 +78,7 @@ class TestResUsers(common.TransactionCase): def test_notify_many(self): # check that the notification of a list of users is done with # a single call to the bus - with mock.patch( - "odoo.addons.bus.models.bus.ImBus.sendmany" - ) as mockedSendMany: + with mock.patch("odoo.addons.bus.models.bus.ImBus.sendmany") as mockedSendMany: users = self.env.user.search([(1, "=", 1)]) self.assertTrue(len(users) > 1) users.notify_warning(message="message")