diff options
Diffstat (limited to 'addons/web/tests/test_image.py')
| -rw-r--r-- | addons/web/tests/test_image.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/addons/web/tests/test_image.py b/addons/web/tests/test_image.py index 1e4b0c3c5b5..544276082a1 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) |
