diff options
| author | Raphael Collet <rco@odoo.com> | 2019-10-15 14:07:39 +0000 |
|---|---|---|
| committer | fw-bot <otis@odoo.com> | 2019-10-21 09:08:10 +0000 |
| commit | 883fd9e045350512c437fe8e518f08e3b880b511 (patch) | |
| tree | 954f592b9eba3303e8561735605d4f34b1dde5e6 /odoo/addons/test_new_api/tests/test_new_fields.py | |
| parent | db90ae1cd6b7417d17f0af076d9ec1987d94b509 (diff) | |
[FIX] fields: ensure Binary are never recomputed with "bin_size"
The compute methods are always expecting the real value and not the bin_size.
The solution is to always compute with `bin_size=False`, and then manually
compute the `bin_size` and set it on the cache of `bin_size=True`.
PR: #38292
Co-authored-by Sébastien Theys <seb@odoo.com>
X-original-commit: 7744886d6141ca7971d91807d0444c707e10fdf8
Diffstat (limited to 'odoo/addons/test_new_api/tests/test_new_fields.py')
| -rw-r--r-- | odoo/addons/test_new_api/tests/test_new_fields.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py index e326d8575b1..805688f45ed 100644 --- a/odoo/addons/test_new_api/tests/test_new_fields.py +++ b/odoo/addons/test_new_api/tests/test_new_fields.py @@ -1497,6 +1497,64 @@ class TestFields(common.TransactionCase): self.assertEqual(Image.open(io.BytesIO(base64.b64decode(record.image))).size, (2000, 4000)) self.assertEqual(Image.open(io.BytesIO(base64.b64decode(record.image_256))).size, (128, 256)) + # test bin_size + record_bin_size = record.with_context(bin_size=True) + self.assertEqual(record_bin_size.image, b'31.54 Kb') + self.assertEqual(record_bin_size.image_512, b'1.02 Kb') + self.assertEqual(record_bin_size.image_256, b'424.00 bytes') + + def test_95_binary_bin_size(self): + binary_value = base64.b64encode(b'content') + binary_size = b'7.00 bytes' + + def assertBinaryValue(record, value): + for field in ('binary', 'binary_related_store', 'binary_related_no_store'): + self.assertEqual(record[field], value) + + # created, flushed, and first read without context + record = self.env['test_new_api.model_binary'].create({'binary': binary_value}) + record.flush() + record.invalidate_cache() + record_no_bin_size = record.with_context(bin_size=False) + record_bin_size = record.with_context(bin_size=True) + + assertBinaryValue(record, binary_value) + assertBinaryValue(record_no_bin_size, binary_value) + assertBinaryValue(record_bin_size, binary_size) + + # created, flushed, and first read with bin_size=False + record_no_bin_size = self.env['test_new_api.model_binary'].with_context(bin_size=False).create({'binary': binary_value}) + record_no_bin_size.flush() + record_no_bin_size.invalidate_cache() + record = self.env['test_new_api.model_binary'].browse(record.id) + record_bin_size = record.with_context(bin_size=True) + + assertBinaryValue(record_no_bin_size, binary_value) + assertBinaryValue(record, binary_value) + assertBinaryValue(record_bin_size, binary_size) + + # created, flushed, and first read with bin_size=True + record_bin_size = self.env['test_new_api.model_binary'].with_context(bin_size=True).create({'binary': binary_value}) + record_bin_size.flush() + record_bin_size.invalidate_cache() + record = self.env['test_new_api.model_binary'].browse(record.id) + record_no_bin_size = record.with_context(bin_size=False) + + assertBinaryValue(record_bin_size, binary_size) + assertBinaryValue(record_no_bin_size, binary_value) + assertBinaryValue(record, binary_value) + + # created without context and flushed with bin_size + record = self.env['test_new_api.model_binary'].create({'binary': binary_value}) + record_no_bin_size = record.with_context(bin_size=False) + record_bin_size = record.with_context(bin_size=True) + record_bin_size.flush() + record_bin_size.invalidate_cache() + + assertBinaryValue(record, binary_value) + assertBinaryValue(record_no_bin_size, binary_value) + assertBinaryValue(record_bin_size, binary_size) + class TestX2many(common.TransactionCase): def test_definition_many2many(self): |
