fix: limit rocket notification size
This commit is contained in:
@@ -43,6 +43,8 @@ def make_config():
|
||||
config.set("rocket", "webhook_url", "https://rocket.example.test/webhook-test")
|
||||
config.add_section("http")
|
||||
config.set("http", "timeout", "5")
|
||||
config.add_section("notification")
|
||||
config.set("notification", "max_message_chars", "3500")
|
||||
return config
|
||||
|
||||
|
||||
@@ -98,6 +100,7 @@ class TicketingStateTest(unittest.TestCase):
|
||||
tickets,
|
||||
previous_state,
|
||||
1,
|
||||
3500,
|
||||
"{odoo_url}/web#id={id}&model={model}&view_type=form",
|
||||
"https://odoo.example.test",
|
||||
"helpdesk.ticket",
|
||||
@@ -113,6 +116,26 @@ class TicketingStateTest(unittest.TestCase):
|
||||
self.assertIn("1 ticket(s) supplementaire(s) non affiche(s) sur 2 au total", message)
|
||||
self.assertNotIn("Nouveau ticket", message)
|
||||
|
||||
def test_build_notification_message_is_limited_by_message_size(self):
|
||||
tickets = [
|
||||
{"id": 1, "name": "Premier ticket avec sujet assez long", "user_id": False},
|
||||
{"id": 2, "name": "Deuxieme ticket avec sujet assez long", "user_id": False},
|
||||
]
|
||||
|
||||
message = ticketing.build_notification_message(
|
||||
tickets,
|
||||
{},
|
||||
50,
|
||||
260,
|
||||
"{odoo_url}/web#id={id}&model={model}&view_type=form",
|
||||
"https://odoo.example.test",
|
||||
"helpdesk.ticket",
|
||||
)
|
||||
|
||||
self.assertIn("1 : Sujet : Premier ticket", message)
|
||||
self.assertNotIn("2 : Sujet : Deuxieme ticket", message)
|
||||
self.assertIn("1 ticket(s) supplementaire(s) non affiche(s) sur 2 au total", message)
|
||||
|
||||
def test_format_ticket_line_uses_personne_when_no_assignee(self):
|
||||
line = ticketing.format_ticket_line(
|
||||
{"id": 2, "name": "Nouveau ticket", "user_id": False},
|
||||
@@ -192,6 +215,7 @@ class TicketingStateTest(unittest.TestCase):
|
||||
@patch("ticketing_setup.requests.post")
|
||||
def test_send_to_rocket_raises_for_http_errors(self, post):
|
||||
response = Mock()
|
||||
response.status_code = 200
|
||||
post.return_value = response
|
||||
|
||||
ticketing.send_to_rocket("message de test", conf_wapt=make_config())
|
||||
|
||||
Reference in New Issue
Block a user