-
-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] add tests send confirmation mail at ticket creation from mail
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import time | ||
|
||
from odoo.addons.test_mail.tests.test_mail_gateway import MAIL_TEMPLATE | ||
|
||
from .common import TestHelpdeskTicketBase | ||
|
||
|
||
|
@@ -131,3 +133,74 @@ def test_ticket_without_team(self): | |
} | ||
) | ||
self.assertEqual(self.new_stage, new_ticket.stage_id) | ||
|
||
def test_create_ticket_with_mail_template(self): | ||
new_stage = self.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_new") | ||
new_stage.team_ids = [(6, 0, [self.team_a.id])] | ||
new_stage.mail_template_id = self.env.ref( | ||
"helpdesk_mgmt.closed_ticket_template" | ||
) | ||
ticket = self.env["helpdesk.ticket"].create( | ||
{ | ||
"name": "I'm a robot, hello", | ||
"team_id": self.team_a.id, | ||
"stage_id": new_stage.id, | ||
"description": "Description", | ||
} | ||
) | ||
ticket_good_reception = ticket.message_ids.filtered( | ||
lambda m: m.message_type == "email" | ||
) | ||
self.assertIn("closed", ticket_good_reception.subject) | ||
|
||
def test_create_ticket_from_alias_mail(self): | ||
server = self.env["fetchmail.server"].create( | ||
{ | ||
"name": "Demo server", | ||
"server_type": "pop", | ||
"server": "pop3.example.com", | ||
} | ||
) | ||
alias = self.env["mail.alias"].create( | ||
{ | ||
"alias_name": "team_a_alias", | ||
"alias_model_id": self.env.ref( | ||
"helpdesk_mgmt.model_helpdesk_ticket" | ||
).id, | ||
"alias_contact": "everyone", | ||
"alias_defaults": {"team_id": self.team_a.id}, | ||
"alias_parent_model_id": self.env.ref( | ||
"helpdesk_mgmt.model_helpdesk_ticket_team" | ||
).id, | ||
} | ||
) | ||
new_stage = self.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_new") | ||
new_stage.team_ids = [(6, 0, [self.team_a.id])] | ||
new_stage.mail_template_id = self.env.ref( | ||
"helpdesk_mgmt.closed_ticket_template" | ||
) | ||
email = "[email protected]" | ||
|
||
result = ( | ||
self.env["mail.thread"] | ||
.with_context(default_fetchmail_server_id=server.id) | ||
.message_process( | ||
server.object_id.model, | ||
MAIL_TEMPLATE.format( | ||
return_path=email, | ||
email_from=email, | ||
to="[email protected]", | ||
cc="[email protected]", | ||
subject="Hello Ticket", | ||
extra="", | ||
msg_id="<[email protected]>", | ||
), | ||
) | ||
) | ||
ticket = self.env["helpdesk.ticket"].search([("name", "=", "Hello Ticket")]) | ||
self.assertEqual(len(ticket.message_ids), 2) | ||
ticket_good_reception = ticket.message_ids.filtered( | ||
lambda m: m.message_type == "email" and m.email_from != email | ||
) | ||
self.assertEqual(len(ticket_good_reception), 1) | ||
self.assertIn("closed", ticket_good_reception.subject) |