summaryrefslogtreecommitdiff
path: root/addons/web/tests
diff options
context:
space:
mode:
authorThanh Dodeur <tso@odoo.com>2019-06-11 10:47:31 +0000
committerThanh Dodeur <tso@odoo.com>2019-06-19 12:31:07 +0000
commitf3e10f698032407f8e6da9abcd37aa224e7c0c1e (patch)
tree8280a41eb33508091c0219853621e9b58d0db2eb /addons/web/tests
parent82bf73fe3049978d5fa0b6984e129c5aa2870d95 (diff)
[FIX] base, web: set 304 status in binary_content
Before this commit, the No Change status wasn't properly set because the `filehash` wasn't passed to `_binary_set_headers` and because the status was not changed to 304 if it was already set to 200 earlier. This commit fixes this issue and also prevents images to be processed in `content_image` if the status is 304. opw-2008426 closes odoo/odoo#34032 Signed-off-by: Christophe Simonis <chs@odoo.com>
Diffstat (limited to 'addons/web/tests')
-rw-r--r--addons/web/tests/test_image.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/addons/web/tests/test_image.py b/addons/web/tests/test_image.py
index e17073d0fb7..d26528b88e3 100644
--- a/addons/web/tests/test_image.py
+++ b/addons/web/tests/test_image.py
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import io
+import base64
from PIL import Image
@@ -42,3 +43,23 @@ class TestImage(HttpCase):
response = self.url_open('/web/image/fake/0/image_no_size')
image = Image.open(io.BytesIO(response.content))
self.assertEqual(image.size, (256, 256))
+
+ def test_02_content_image_Etag_304(self):
+ """This test makes sure that the 304 response is properly returned if the ETag is properly set"""
+
+ attachment = self.env['ir.attachment'].create({
+ 'datas': b"R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=",
+ 'name': 'testEtag.gif',
+ 'public': True,
+ 'datas_fname': 'testEtag.gif',
+ 'mimetype': 'image/gif',
+ })
+ response = self.url_open('/web/image/%s' % attachment.id)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(base64.b64encode(response.content), attachment.datas)
+
+ etag = response.headers.get('ETag')
+
+ response2 = self.url_open('/web/image/%s' % attachment.id, headers={"If-None-Match": etag})
+ self.assertEqual(response2.status_code, 304)
+ self.assertEqual(len(response2.content), 0)