[REF] web_notify: Black python code

pull/2412/head
laurent.corron 2019-11-14 15:39:25 +01:00 committed by Benoit Aimont
parent 0fab8889d3
commit 19f059b783
3 changed files with 27 additions and 70 deletions

View File

@ -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,
}

View File

@ -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)

View File

@ -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")