Skip to content

Commit

Permalink
[PR OCA#463] [IMP] helpdesk_mgmt: Test submit with attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
ypapouin authored and PicchiSeba committed Apr 29, 2024
1 parent 83320e8 commit c3b9a5c
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions helpdesk_mgmt/tests/test_helpdesk_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ 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),
"subject": self.new_ticket_title,
"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)


Expand All @@ -93,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 c3b9a5c

Please sign in to comment.