Skip to content

Commit

Permalink
Merge PR #1424 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by lmignon
  • Loading branch information
shopinvader-git-bot committed Nov 2, 2023
2 parents 2cb499c + b6a639b commit 45307eb
Show file tree
Hide file tree
Showing 90 changed files with 1,076 additions and 193 deletions.
6 changes: 6 additions & 0 deletions setup/shopinvader_search_engine_update/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/shopinvader_search_engine_update_image/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/shopinvader_search_engine_update_product_brand/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/shopinvader_search_engine_update_product_media/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
68 changes: 68 additions & 0 deletions shopinvader_search_engine/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,71 @@ def tearDownClass(cls):
cls.loader.restore_registry()
cls.reset_extendable_registry()
super().tearDownClass()


class TestCategoryBindingBase(TestBindingIndexBase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.setup_records()

@classmethod
def _prepare_index_values(cls, backend=None):
backend = backend or cls.backend
return {
"name": "Category Index",
"backend_id": backend.id,
"model_id": cls.env["ir.model"]
.search([("model", "=", "product.category")], limit=1)
.id,
"lang_id": cls.env.ref("base.lang_en").id,
"serializer_type": "shopinvader_category_exports",
}

@classmethod
def setup_records(cls, backend=None):
backend = backend or cls.backend
# create an index for category model
cls.se_index = cls.se_index_model.create(cls._prepare_index_values(backend))
# create a binding + category alltogether
cls.category = cls.env["product.category"].create({"name": "Test category"})
cls.category_binding = cls.category._add_to_index(cls.se_index)


class TestProductBindingMixin:
@classmethod
def _prepare_index_values(cls, tst_cls, backend=None):
backend = backend or tst_cls.backend
return {
"name": "Product Index",
"backend_id": backend.id,
"model_id": tst_cls.env["ir.model"]
.search([("model", "=", "product.product")], limit=1)
.id,
"lang_id": tst_cls.env.ref("base.lang_en").id,
"serializer_type": "shopinvader_product_exports",
}

@classmethod
def setup_records(cls, tst_cls, backend=None):
backend = backend or tst_cls.backend
# create an index for product model
tst_cls.se_index = tst_cls.env["se.index"].create(
cls._prepare_index_values(tst_cls, backend)
)
# create a binding + product alltogether
tst_cls.product = tst_cls.env.ref(
"shopinvader_product.product_product_chair_vortex_white"
)
tst_cls.product_binding = tst_cls.product._add_to_index(tst_cls.se_index)
tst_cls.product_expected = {
"id": tst_cls.product.id,
"name": tst_cls.product.name,
}


class TestProductBindingBase(TestBindingIndexBase, TestProductBindingMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
TestProductBindingMixin.setup_records(cls)
43 changes: 8 additions & 35 deletions shopinvader_search_engine/tests/test_category_binding.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from .common import TestBindingIndexBase
from .common import TestCategoryBindingBase


class TestCategoryBinding(TestBindingIndexBase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.setup_records()

@classmethod
def _prepare_index_values(cls, backend=None):
backend = backend or cls.backend
return {
"name": "Category Index",
"backend_id": backend.id,
"model_id": cls.env["ir.model"]
.search([("model", "=", "product.category")], limit=1)
.id,
"lang_id": cls.env.ref("base.lang_en").id,
"serializer_type": "shopinvader_category_exports",
}

@classmethod
def setup_records(cls, backend=None):
backend = backend or cls.backend
# create an index for category model
cls.se_index = cls.se_index_model.create(cls._prepare_index_values(backend))
# create a binding + category alltogether
cls.category = cls.env["product.category"].create({"name": "Test category"})
cls.category_binding = cls.category._add_to_index(cls.se_index)
class TestCategoryBinding(TestCategoryBindingBase):
def _create_parent_category(self):
parent_category = self.env["product.category"].create(
{"name": "Parent category"}
)
self.category.parent_id = parent_category
return parent_category

def test_serialize(self):
self.category_binding.recompute_json()
Expand All @@ -39,13 +19,6 @@ def test_serialize(self):
self.assertEqual(data["name"], self.category.name)
self.assertEqual(data["level"], 0)

def _create_parent_category(self):
parent_category = self.env["product.category"].create(
{"name": "Parent category"}
)
self.category.parent_id = parent_category
return parent_category

def test_serialize_hierarchy_parent_not_in_index(self):
self._create_parent_category()
self.category_binding.recompute_json()
Expand Down
33 changes: 2 additions & 31 deletions shopinvader_search_engine/tests/test_product_binding.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from .common import TestBindingIndexBase
from .common import TestProductBindingBase


class TestProductBinding(TestBindingIndexBase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.setup_records()

@classmethod
def _prepare_index_values(cls, backend=None):
backend = backend or cls.backend
return {
"name": "Product Index",
"backend_id": backend.id,
"model_id": cls.env["ir.model"]
.search([("model", "=", "product.product")], limit=1)
.id,
"lang_id": cls.env.ref("base.lang_en").id,
"serializer_type": "shopinvader_product_exports",
}

@classmethod
def setup_records(cls, backend=None):
backend = backend or cls.backend
# create an index for product model
cls.se_index = cls.se_index_model.create(cls._prepare_index_values(backend))
# create a binding + product alltogether
cls.product = cls.env.ref(
"shopinvader_product.product_product_chair_vortex_white"
)
cls.product_binding = cls.product._add_to_index(cls.se_index)

class TestProductBinding(TestProductBindingBase):
def test_serialize(self):
self.product_binding.recompute_json()
data = self.product_binding.data
Expand Down
76 changes: 76 additions & 0 deletions shopinvader_search_engine_product_brand_image/tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import base64

from odoo.addons.shopinvader_search_engine_image.tests.common import (
TestSeMultiImageThumbnailCase,
)


class ProductBrandImageCase(TestSeMultiImageThumbnailCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.backend.image_data_url_strategy = "odoo"
# create index for brands
cls.brand_index = cls.env["se.index"].create(
{
"name": "brand",
"backend_id": cls.backend.id,
"model_id": cls.env.ref("product_brand.model_product_brand").id,
"serializer_type": "shopinvader_brand_exports",
}
)
# create sizes for brands
cls.env["se.image.field.thumbnail.size"].create(
{
"model_id": cls.env.ref("product_brand.model_product_brand").id,
"field_id": cls.env.ref(
"fs_product_brand_multi_image.field_product_brand__image_ids"
).id,
"backend_id": cls.backend.id,
"size_ids": [(6, 0, [cls.size_small.id, cls.size_medium.id])],
}
)
cls.brand = cls.env["product.brand"].create(
{
"name": "Test Brand",
}
)
cls.brand_white_image = cls.env["fs.product.brand.image"].create(
{
"sequence": 1,
"brand_id": cls.brand.id,
"specific_image": {
"filename": "white.png",
"content": base64.b64encode(cls.white_image),
},
"tag_id": cls.tag1.id,
}
)
cls.brand_black_image = cls.env["fs.product.brand.image"].create(
{
"sequence": 2,
"brand_id": cls.brand.id,
"specific_image": {
"filename": "black.png",
"content": base64.b64encode(cls.black_image),
},
"tag_id": cls.tag2.id,
}
)
cls.brand_binding = cls.brand._add_to_index(cls.brand_index)

def setUp(self):
super().setUp()
self.fs_storage = self.env["fs.storage"].create(
{
"name": "Temp FS Storage",
"protocol": "memory",
"code": "mem_dir_brand",
"directory_path": "/tmp/",
"model_xmlids": "fs_product_brand_multi_image.model_fs_product_brand_image",
"base_url": "https://media.alcyonbelux.be/",
"is_directory_path_in_url": False,
}
)
75 changes: 2 additions & 73 deletions shopinvader_search_engine_product_brand_image/tests/test_brand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,10 @@
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64
from .common import ProductBrandImageCase

from odoo.addons.shopinvader_search_engine_image.tests.common import (
TestSeMultiImageThumbnailCase,
)


class ProductBrandCase(TestSeMultiImageThumbnailCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.backend.image_data_url_strategy = "odoo"
# create index for brands
cls.brand_index = cls.env["se.index"].create(
{
"name": "brand",
"backend_id": cls.backend.id,
"model_id": cls.env.ref("product_brand.model_product_brand").id,
"serializer_type": "shopinvader_brand_exports",
}
)
# create sizes for brands
cls.env["se.image.field.thumbnail.size"].create(
{
"model_id": cls.env.ref("product_brand.model_product_brand").id,
"field_id": cls.env.ref(
"fs_product_brand_multi_image.field_product_brand__image_ids"
).id,
"backend_id": cls.backend.id,
"size_ids": [(6, 0, [cls.size_small.id, cls.size_medium.id])],
}
)
cls.brand = cls.env["product.brand"].create(
{
"name": "Test Brand",
}
)
cls.brand_white_image = cls.env["fs.product.brand.image"].create(
{
"sequence": 1,
"brand_id": cls.brand.id,
"specific_image": {
"filename": "white.png",
"content": base64.b64encode(cls.white_image),
},
"tag_id": cls.tag1.id,
}
)
cls.brand_black_image = cls.env["fs.product.brand.image"].create(
{
"sequence": 2,
"brand_id": cls.brand.id,
"specific_image": {
"filename": "black.png",
"content": base64.b64encode(cls.black_image),
},
"tag_id": cls.tag2.id,
}
)
cls.brand_binding = cls.brand._add_to_index(cls.brand_index)

def setUp(self):
super().setUp()
self.fs_storage = self.env["fs.storage"].create(
{
"name": "Temp FS Storage",
"protocol": "memory",
"code": "mem_dir_brand",
"directory_path": "/tmp/",
"model_xmlids": "fs_product_brand_multi_image.model_fs_product_brand_image",
"base_url": "https://media.alcyonbelux.be/",
"is_directory_path_in_url": False,
}
)

class TestBrand(ProductBrandImageCase):
def test_basic_images_compute(self):
brand = self.brand_binding._contextualize(self.brand_binding)
data = self.brand_index.model_serializer.serialize(brand.record)
Expand Down
Loading

0 comments on commit 45307eb

Please sign in to comment.