Skip to content

Commit

Permalink
[IMP] helpdesk_mgmt: Test submit with attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
ypapouin committed May 10, 2023
1 parent cf0ce80 commit 6c22428
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion helpdesk_mgmt/tests/test_helpdesk_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _create_ticket(self, partner, ticket_title):
}
)

def _submit_ticket(self):
def _submit_ticket(self, files=None):
resp = self.url_open(
"/submitted/ticket",
data={
Expand All @@ -68,6 +68,7 @@ def _submit_ticket(self):
"subject": self.new_ticket_title,
"description": "\n".join(self.new_ticket_desc_lines),
},
files=files,
)
self.assertEqual(resp.status_code, 200)

Expand All @@ -92,3 +93,34 @@ def test_submit_ticket_02(self):
"<p>" + "<br>".join(self.new_ticket_desc_lines) + "</p>",
tickets.mapped("description"),
)

def test_submit_ticket_with_attachments(self):
self.authenticate("test-user", "test-user")
self._submit_ticket(
files=[
(
"attachment",
("test.txt", b"test", "plain/text"),
),
(
"attachment",
("test.svg", b"<svg></svg>", "image/svg+xml"),
),
]
)
ticket_id = self.get_new_tickets(self.basic_user)
self.assertEqual(len(ticket_id), 1)
# check that both files have been linked to the newly created ticket
attachment_ids = self.env["ir.attachment"].search(
[
("res_model", "=", "helpdesk.ticket"),
("res_id", "=", ticket_id.id),
]
)
self.assertEqual(len(attachment_ids), 2)
# check that both files have kept their names
self.assertIn("test.txt", attachment_ids.mapped("name"))
self.assertIn("test.svg", attachment_ids.mapped("name"))
# check that both files are public (access_token is set)
self.assertTrue(attachment_ids[0].access_token)
self.assertTrue(attachment_ids[1].access_token)

0 comments on commit 6c22428

Please sign in to comment.