Skip to content
Snippets Groups Projects
Commit de0b9e51 authored by Thibault Delavallée's avatar Thibault Delavallée
Browse files

[IMP] test_mail: add an assert method for bus notifications content

Purpose is to ease the check of bus notifications content by having a tool
method doing it.
parent a4df9f8c
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import json
from contextlib import contextmanager from contextlib import contextmanager
from email.utils import formataddr from email.utils import formataddr
from odoo import api from odoo import api
from odoo.addons.bus.models.bus import json_dump
from odoo.tests import common from odoo.tests import common
...@@ -78,6 +81,39 @@ class BaseFunctionalTest(common.SavepointCase): ...@@ -78,6 +81,39 @@ class BaseFunctionalTest(common.SavepointCase):
if hasattr(self, 'assertEmails') and len(new_messages) == 1: if hasattr(self, 'assertEmails') and len(new_messages) == 1:
self.assertEmails(new_messages.author_id, new_notifications.filtered(lambda n: n.is_email).mapped('res_partner_id')) self.assertEmails(new_messages.author_id, new_notifications.filtered(lambda n: n.is_email).mapped('res_partner_id'))
def assertBusNotification(self, channels, message_dicts=None, init=True):
""" Check for bus notifications. Basic check is about used channels.
Verifying content is optional.
:param channels: list of channel
:param messages: if given, list of message making a valid pair (channel,
message) to be found in bus.bus
"""
if init:
self.assertEqual(len(self.env['bus.bus'].search([])), len(channels))
notifications = self.env['bus.bus'].search([('channel', 'in', [json_dump(channel) for channel in channels])])
self.assertEqual(len(notifications), len(channels))
if message_dicts:
notif_messages = [json.loads(n.message) for n in notifications]
for expected in message_dicts:
found = False
for returned in notif_messages:
for key, val in expected.items():
if key not in returned:
continue
if isinstance(returned[key], list):
if set(returned[key]) != set(val):
continue
else:
if returned[key] != val:
continue
found = True
break
if found:
break
if not found:
raise AssertionError("Bus notification content %s not found" % (repr(expected)))
@contextmanager @contextmanager
def sudoAs(self, login): def sudoAs(self, login):
old_uid = self.uid old_uid = self.uid
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment