Skip to content

Commit d8f0cdf

Browse files
committed
storage_image_product: ease test setup for other modules
Having a mixin class allows to run the setup of the base data explicitly where needed especially when you have test classes with multiple inheritances. After the Odoo tests apocalypse we cannot rely anymore on running Klass.setUpClass() w/o tons of attributes warning. Now you can inherit the mixin and do the setup properly.
1 parent 89130b7 commit d8f0cdf

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

storage_image_product/tests/common.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from odoo.addons.component.tests.common import TransactionComponentCase
99

1010

11-
class ProductImageCommonCase(TransactionComponentCase):
11+
class ProductImageCaseMixin:
1212
@staticmethod
1313
def _get_file_content(name, base_path=None, as_binary=False):
1414
path = base_path or os.path.dirname(os.path.abspath(__file__))
@@ -25,12 +25,18 @@ def _create_storage_image(cls, name):
2525
)
2626

2727
@classmethod
28-
def setUpClass(cls):
29-
super().setUpClass()
28+
def _setup_base_image_data(cls):
3029
cls.template = cls.env.ref("product.product_product_4_product_template")
3130
cls.product_a = cls.env.ref("product.product_product_4")
3231
cls.product_b = cls.env.ref("product.product_product_4b")
3332
cls.product_c = cls.env.ref("product.product_product_4c")
3433
cls.logo_image = cls._create_storage_image("logo-image.jpg")
3534
cls.white_image = cls._create_storage_image("white-image.jpg")
3635
cls.black_image = cls._create_storage_image("black-image.jpg")
36+
37+
38+
class ProductImageCommonCase(TransactionComponentCase, ProductImageCaseMixin):
39+
@classmethod
40+
def setUpClass(cls):
41+
super().setUpClass()
42+
cls._setup_base_image_data()

0 commit comments

Comments
 (0)