[MIG] web_notify: Migrated in v17

This commit is contained in:
Nikul-OSI
2024-02-16 16:30:37 +05:30
committed by trisdoan
parent decbb9173f
commit 51412c2cc8
7 changed files with 25 additions and 6 deletions

View File

@@ -3,7 +3,7 @@
import json
from odoo import exceptions
from odoo import SUPERUSER_ID, exceptions
from odoo.tests import common
from ..models.res_users import DANGER, DEFAULT, INFO, SUCCESS, WARNING
@@ -22,6 +22,7 @@ class TestResUsers(common.TransactionCase):
"params": {},
}
self.env.user.notify_success(**test_msg)
self.env.cr.precommit.run() # trigger the creation of bus.bus records
news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news))
test_msg.update({"type": SUCCESS})
@@ -40,6 +41,7 @@ class TestResUsers(common.TransactionCase):
"params": {},
}
self.env.user.notify_danger(**test_msg)
self.env.cr.precommit.run()
news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news))
test_msg.update({"type": DANGER})
@@ -58,6 +60,7 @@ class TestResUsers(common.TransactionCase):
"params": {},
}
self.env.user.notify_warning(**test_msg)
self.env.cr.precommit.run()
news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news))
test_msg.update({"type": WARNING})
@@ -76,6 +79,7 @@ class TestResUsers(common.TransactionCase):
"params": {},
}
self.env.user.notify_info(**test_msg)
self.env.cr.precommit.run()
news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news))
test_msg.update({"type": INFO})
@@ -94,6 +98,7 @@ class TestResUsers(common.TransactionCase):
"params": {},
}
self.env.user.notify_default(**test_msg)
self.env.cr.precommit.run()
news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news))
test_msg.update({"type": DEFAULT})
@@ -114,6 +119,12 @@ class TestResUsers(common.TransactionCase):
with self.assertRaises(exceptions.UserError):
other_user_model.browse(self.env.uid).notify_info(message="hello")
# This method for SUPER user
other_user = self.env.ref("base.user_demo")
other_user_model = self.env["res.users"].with_user(other_user)
with self.assertRaises(exceptions.UserError):
other_user_model.browse(SUPERUSER_ID).notify_info(message="hello")
def test_notify_admin_allowed_other_user(self):
other_user = self.env.ref("base.user_demo")
other_user.notify_info(message="hello")