diff --git a/helpdesk_mgmt/tests/test_helpdesk_portal.py b/helpdesk_mgmt/tests/test_helpdesk_portal.py index e9954cde9e..4509ec8483 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_portal.py +++ b/helpdesk_mgmt/tests/test_helpdesk_portal.py @@ -58,7 +58,7 @@ def _create_ticket(self, partner, ticket_title, **values): data.update(**values) return self.env["helpdesk.ticket"].create(data) - def _submit_ticket(self, **values): + def _submit_ticket(self, files=None, **values): data = { "category": self.env.ref("helpdesk_mgmt.helpdesk_category_1").id, "csrf_token": http.WebRequest.csrf_token(self), @@ -66,7 +66,7 @@ def _submit_ticket(self, **values): "description": "\n".join(self.new_ticket_desc_lines), } data.update(**values) - resp = self.url_open("/submitted/ticket", data=data) + resp = self.url_open("/submitted/ticket", data=data, files=files) self.assertEqual(resp.status_code, 200) @@ -93,3 +93,34 @@ def test_submit_ticket_02(self): "

" + "
".join(self.new_ticket_desc_lines) + "

", 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"", "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)