Skip to content

Commit

Permalink
[REF] Test import for product.product and product.template
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Nov 21, 2024
1 parent af4bb26 commit af9fce2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@ class TestModuleProductSupplierinfoQtyMultiplier(TestModuleProduct):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.ProductProduct = cls.env["product.product"]
cls.classification_20 = cls.env.ref(
"account_product_fiscal_classification.fiscal_classification_A_company_1"
)

def test_01_import_product_account_product_fiscal_classification(self):
def _test_import_product_account_product_fiscal_classification(self, model):
products, messages = self._test_import_file(
"grap_custom_import_account_product_fiscal_classification",
"product.product",
model,
"product.csv",
folder="product",
)
self.assertFalse(messages)
self.assertEqual(len(products), 1)
self.assertEqual(products.fiscal_classification_id, self.classification_20)

def test_01_import_product_account_product_fiscal_classification_product(self):
self._test_import_product_account_product_fiscal_classification(
"product.product"
)

def test_02_import_product_account_product_fiscal_classification_template(self):
self._test_import_product_account_product_fiscal_classification(
"product.template"
)
6 changes: 4 additions & 2 deletions grap_custom_import_base/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ def setUpClass(cls):
cls.ResPartner = cls.env["res.partner"]
cls.Wizard = cls.env["base_import.import"]

def _test_import_file(self, module, model, file_name):
def _test_import_file(self, module, model, file_name, folder=False):
preview_options = {"headers": True, "quoting": '"'}
import_options = {"has_headers": True, "quoting": '"'}

# Read File
file_path = get_module_resource(module, "tests/templates/", model, file_name)
if not folder:
folder = model
file_path = get_module_resource(module, "tests/templates/", folder, file_name)
extension = file_path.split(".")[-1]
if extension == "csv":
file_type = "text/csv"
Expand Down
15 changes: 8 additions & 7 deletions grap_custom_import_product/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@

@tagged("post_install", "-at_install")
class TestModuleProduct(TestModuleBase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.ProductProduct = cls.env["product.product"]

def test_01_import_product(self):
def _test_import_product(self, model):
products, messages = self._test_import_file(
"grap_custom_import_product", "product.product", "product.csv"
"grap_custom_import_product", model, "product.csv", folder="product"
)
self.assertFalse(messages)
self.assertEqual(len(products), 3)
Expand All @@ -26,3 +21,9 @@ def test_01_import_product(self):
self.assertEqual(coca_cola.mapped("seller_ids.partner_id.name"), ["Coke Corp"])
self.assertEqual(coca_cola.mapped("seller_ids.product_code"), ["CC"])
self.assertEqual(coca_cola.mapped("seller_ids.product_name"), ["BOTTLE 33CL"])

def test_01_import_product_product(self):
self._test_import_product("product.product")

def test_02_import_product_template(self):
self._test_import_product("product.template")
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ def setUpClass(cls):
super().setUpClass()
cls.ProductProduct = cls.env["product.product"]

def test_01_import_product_supplierinfo_qty_multiplier(self):
def _test_import_product_supplierinfo_qty_multiplier(self, model):
products, messages = self._test_import_file(
"grap_custom_import_product_supplierinfo_qty_multiplier",
"product.product",
"product.csv",
folder="product",
)
self.assertFalse(messages)
self.assertEqual(len(products), 1)
self.assertEqual(products.mapped("seller_ids.multiplier_qty"), [24.0])

def test_01_import_product_supplierinfo_qty_multiplier_product(self):
self._test_import_product_supplierinfo_qty_multiplier("product.product")

def test_02_import_product_supplierinfo_qty_multiplier_template(self):
self._test_import_product_supplierinfo_qty_multiplier("product.template")

0 comments on commit af9fce2

Please sign in to comment.