This branch is the combination of several optimizations in the ORM: * store field values once in the cache: the cache reflects more faithfully the database, only fields that explicitly depend on the context have an extra indirection in the cache; * delay recomputations by default: use method `recompute` to explicitly flush out pending recomputations; * delay updates in method `write`: updates are stored in a data structure that can be flushed efficiently to the database with method `flush` (which also flush out recomputations); * make method `modified` take advantage of inverse fields to inverse dependencies; * filter records by evaluating a domain on records in Python; * a computed field with `readonly=False` behaves like a normal field with an onchange method; * computed fields are computed in superuser mode by default. Work done by Toufik Ben Jaa, Raphael Collet, Denis Ledoux and Fabien Pinckaers. closes odoo/odoo#35659 Signed-off-by: Denis Ledoux <beledouxdenis@users.noreply.github.com>
65 lines
2.6 KiB
Python
65 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import io
|
|
import base64
|
|
|
|
from PIL import Image
|
|
|
|
from odoo.tests.common import HttpCase
|
|
|
|
|
|
class TestImage(HttpCase):
|
|
def test_01_content_image_resize_placeholder(self):
|
|
"""The goal of this test is to make sure the placeholder image is
|
|
resized appropriately depending on the given URL parameters."""
|
|
|
|
# CASE: resize placeholder, given size but original ratio is always kept
|
|
response = self.url_open('/web/image/0/200x150')
|
|
image = Image.open(io.BytesIO(response.content))
|
|
self.assertEqual(image.size, (150, 150))
|
|
|
|
# CASE: resize placeholder to small
|
|
response = self.url_open('/web/image/fake/0/image_64')
|
|
image = Image.open(io.BytesIO(response.content))
|
|
self.assertEqual(image.size, (64, 64))
|
|
|
|
# CASE: resize placeholder to medium
|
|
response = self.url_open('/web/image/fake/0/image_128')
|
|
image = Image.open(io.BytesIO(response.content))
|
|
self.assertEqual(image.size, (128, 128))
|
|
|
|
# CASE: resize placeholder to large
|
|
response = self.url_open('/web/image/fake/0/image_256')
|
|
image = Image.open(io.BytesIO(response.content))
|
|
self.assertEqual(image.size, (256, 256))
|
|
|
|
# CASE: resize placeholder to big (but placeholder image is too small)
|
|
response = self.url_open('/web/image/fake/0/image')
|
|
image = Image.open(io.BytesIO(response.content))
|
|
self.assertEqual(image.size, (256, 256))
|
|
|
|
# CASE: no size found, use placeholder original size
|
|
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,
|
|
'mimetype': 'image/gif',
|
|
})
|
|
response = self.url_open('/web/image/%s' % attachment.id, timeout=None)
|
|
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)
|