mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-13 15:34:49 -06:00
[FIX] attachment_zipped_download: Fix tests
attachment_zipped_download 16.0.1.0.1
This commit is contained in:
parent
f5fa389245
commit
c565c58684
@ -2,7 +2,7 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
{
|
||||
"name": "Attachment Zipped Download",
|
||||
"version": "16.0.1.0.0",
|
||||
"version": "16.0.1.0.1",
|
||||
"category": "Tools",
|
||||
"website": "https://github.com/OCA/knowledge",
|
||||
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||
|
@ -12,9 +12,7 @@ class AttachmentZippedDownloadController(http.Controller):
|
||||
if len(ids) == 0:
|
||||
return
|
||||
list_ids = map(int, ids.split(","))
|
||||
out_file = (
|
||||
request.env["ir.attachment"].sudo().browse(list_ids)._create_temp_zip()
|
||||
)
|
||||
out_file = request.env["ir.attachment"].browse(list_ids)._create_temp_zip()
|
||||
return http.send_file(
|
||||
filepath_or_fp=out_file,
|
||||
mimetype="application/zip",
|
||||
|
@ -1,36 +1,43 @@
|
||||
# Copyright 2022 Tecnativa - Víctor Martínez
|
||||
# Copyright 2022-2023 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
import base64
|
||||
|
||||
import odoo.tests
|
||||
from odoo.tests import new_test_user
|
||||
|
||||
|
||||
class TestAttachmentZippedDownload(odoo.tests.HttpCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
test_1 = self._create_attachment("test1.txt")
|
||||
test_2 = self._create_attachment("test2.txt")
|
||||
self.attachments = test_1 + test_2
|
||||
self.user = self.env["res.users"].create(
|
||||
{
|
||||
"name": "test-user",
|
||||
"login": "test-user",
|
||||
"password": "test-user",
|
||||
"groups_id": [(6, 0, [self.env.ref("base.group_user").id])],
|
||||
}
|
||||
ctx = {
|
||||
"mail_create_nolog": True,
|
||||
"mail_create_nosubscribe": True,
|
||||
"mail_notrack": True,
|
||||
"no_reset_password": True,
|
||||
}
|
||||
self.user = new_test_user(
|
||||
self.env,
|
||||
login="test-user",
|
||||
context=ctx,
|
||||
)
|
||||
test_1 = self._create_attachment(self.user, "test1.txt")
|
||||
test_2 = self._create_attachment(self.user, "test2.txt")
|
||||
self.attachments = test_1 + test_2
|
||||
|
||||
def _create_attachment(self, name):
|
||||
return self.env["ir.attachment"].create(
|
||||
{
|
||||
"name": name,
|
||||
"datas": base64.b64encode(b"\xff data"),
|
||||
}
|
||||
def _create_attachment(self, user, name):
|
||||
return (
|
||||
self.env["ir.attachment"]
|
||||
.with_user(user)
|
||||
.create(
|
||||
{
|
||||
"name": name,
|
||||
"datas": base64.b64encode(b"\xff data"),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def test_action_attachments_download(self):
|
||||
self.authenticate("test-user", "test-user")
|
||||
# 16.0 WARNING odoo odoo.http: Sorry, you are not allowed to access this document.
|
||||
res = self.attachments.sudo().action_attachments_download()
|
||||
res = self.attachments.action_attachments_download()
|
||||
response = self.url_open(res["url"], timeout=20)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
Loading…
Reference in New Issue
Block a user