Skip to content

Commit

Permalink
[IMP]product_attribute_set: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillemCForgeFlow committed May 8, 2023
1 parent 9236a1a commit 03e40ea
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions product_attribute_set/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_product_attribute_set
55 changes: 55 additions & 0 deletions product_attribute_set/tests/test_product_attribute_set.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 2023 Copyright ForgeFlow, S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.tests.common import SavepointCase


class TestProductAttributeSet(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Models
cls.product_ctg_model = cls.env["product.category"]
cls.product_tmpl_model = cls.env["product.template"]
cls.attribute_set_model = cls.env["attribute.set"]
cls.product_tmpl_odoo_model = cls.env.ref("product.model_product_template")

# Instances
cls.attribute_set_01 = cls.attribute_set_model.create(
{"name": "Attribute Set 01", "model_id": cls.product_tmpl_odoo_model.id}
)
cls.attribute_set_02 = cls.attribute_set_model.create(
{"name": "Attribute Set 02", "model_id": cls.product_tmpl_odoo_model.id}
)
cls.product_ctg_01 = cls.product_ctg_model.create({"name": "Category 01"})
cls.product_ctg_02 = cls.product_ctg_model.create(
{"name": "Category 02", "attribute_set_id": cls.attribute_set_02.id}
)
cls.product_tmpl_01 = cls.product_tmpl_model.create(
{"name": "Product 01", "categ_id": cls.product_ctg_01.id}
)
cls.product_tmpl_02 = cls.product_tmpl_model.create(
{
"name": "Product 02",
"categ_id": cls.product_ctg_01.id,
"attribute_set_id": cls.attribute_set_02.id,
}
)

def test_01_product_category_to_non_assigned_templates(self):
"""
Should assign the value to only the first template as the second one already
has a value.
"""
self.product_ctg_01.attribute_set_id = self.attribute_set_01
self.assertEqual(self.attribute_set_01, self.product_tmpl_01.attribute_set_id)
self.assertNotEqual(self.attribute_set_01, self.product_tmpl_02)

def test_02_category_change(self):
"""
When the category changes, the attribute set value is also changed based on the
value assigned in the category.
"""
self.assertFalse(self.product_tmpl_01.attribute_set_id)
self.product_tmpl_01.categ_id = self.product_ctg_02
self.assertEqual(self.attribute_set_02, self.product_tmpl_01.attribute_set_id)

0 comments on commit 03e40ea

Please sign in to comment.