Debian Codegraph @

addons/sale_pdf_quote_builder/tests/test_controllers.py

raw
1 from odoo import http
2 from odoo.tests import HttpCase, tagged
3 from odoo.tools import mute_logger
4 from odoo.tools.misc import file_open
5
6
7 @tagged("-at_install", "post_install")
8 class TestUpload(HttpCase):
9
10 @mute_logger("odoo.addons.sale_pdf_quote_builder.controllers.quotation_document", "odoo.http")
11 def test_wrong_pdf(self):
12 self.authenticate("admin", "admin")
13 data = {'csrf_token': http.Request.csrf_token(self)}
14 # Structurally valid but AES-encrypted PDF file (generated with PyPDF)
15 with file_open('sale_pdf_quote_builder/tests/files/test_AES.pdf', 'rb') as f:
16 files = [('ufile', ('test_AES.pdf', f.read(), 'application/pdf'))]
17 resp = self.url_open("/sale_pdf_quote_builder/quotation_document/upload", data=data, files=files)
18 self.assertEqual(resp.status_code, 422)
19 self.assertEqual(resp.headers['Content-Type'], 'application/json; charset=utf-8')
20 self.assertEqual(resp.text, R'''{"error": "It seems that we're not able to process this pdf inside a quotation. It is either encrypted, or encoded in a format we do not support."}''')