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