test: Website Item basic test & removed product configurator tests

- Sider fixes: missing semicolons
- Added two basic tests for Website Item
- Commented Product Configurator tests, needs to re-written fully
This commit is contained in:
marination
2021-07-19 13:27:17 +05:30
parent ece4f391ac
commit 7ef2af203f
5 changed files with 130 additions and 85 deletions

View File

@@ -3,8 +3,66 @@
# See license.txt # See license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
# import frappe import frappe
import unittest import unittest
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.e_commerce.doctype.website_item.website_item import make_website_item
class TestWebsiteItem(unittest.TestCase): class TestWebsiteItem(unittest.TestCase):
pass @classmethod
def setUpClass(cls):
make_item("Test Web Item", {
"has_variant": 1,
"variant_based_on": "Item Attribute",
"attributes": [
{
"attribute": "Test Size"
}
]
})
def test_index_creation(self):
"Check if index is getting created in db."
from erpnext.e_commerce.doctype.website_item.website_item import on_doctype_update
on_doctype_update()
indices = frappe.db.sql("show index from `tabWebsite Item`", as_dict=1)
expected_columns = {"route", "item_group", "brand"}
for index in indices:
expected_columns.discard(index.get("Column_name"))
if expected_columns:
self.fail(f"Expected db index on these columns: {', '.join(expected_columns)}")
def test_website_item_desk_item_sync(self):
"Check creation/updation/deletion of Website Item and its impact on Item master."
web_item = None
item = make_item("Test Web Item")
try:
web_item = make_website_item(item, save=False)
web_item.save()
except Exception:
self.fail(f"Error while creating website item for {item.item_code}")
# check if website item was created
self.assertTrue(bool(web_item))
item.reload()
# check if item was back updated
self.assertEqual(web_item.published, 1)
self.assertEqual(item.published_in_website, 1)
self.assertEqual(web_item.item_group, item.item_group)
# check if disabling item unpublished website item
item.disabled = 1
item.save()
web_item.reload()
self.assertEqual(web_item.published, 0)
# check if website item deletion, unpublishes desk item
web_item.delete()
item.reload()
self.assertEqual(item.published_in_website, 0)
# tear down
item.delete()

View File

@@ -2,10 +2,9 @@ from __future__ import unicode_literals
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import frappe, unittest import frappe, unittest
from frappe.utils import set_request, get_html_for_route from frappe.utils import get_html_for_route
from frappe.website.render import render from erpnext.e_commerce.product_query import ProductQuery
from erpnext.portal.product_configurator.utils import get_products_for_website from erpnext.e_commerce.doctype.website_item.website_item import make_website_item
from erpnext.stock.doctype.item.test_item import make_item_variant
test_dependencies = ["Item"] test_dependencies = ["Item"]
@@ -67,81 +66,82 @@ class TestProductConfigurator(unittest.TestCase):
doc = frappe.get_doc("Item", name) doc = frappe.get_doc("Item", name)
return doc return doc
def test_product_list(self): # TODO: E-commerce server side tests
template_items = frappe.get_all('Item', {'show_in_website': 1}) # def test_product_list(self):
variant_items = frappe.get_all('Item', {'show_variant_in_website': 1}) # template_items = frappe.get_all('Item', {'show_in_website': 1})
# variant_items = frappe.get_all('Item', {'show_variant_in_website': 1})
products_settings = frappe.get_doc('Products Settings') # products_settings = frappe.get_doc('Products Settings')
products_settings.enable_field_filters = 1 # products_settings.enable_field_filters = 1
products_settings.append('filter_fields', {'fieldname': 'item_group'}) # products_settings.append('filter_fields', {'fieldname': 'item_group'})
products_settings.append('filter_fields', {'fieldname': 'stock_uom'}) # products_settings.append('filter_fields', {'fieldname': 'stock_uom'})
products_settings.save() # products_settings.save()
html = get_html_for_route('all-products') # html = get_html_for_route('all-products')
soup = BeautifulSoup(html, 'html.parser') # soup = BeautifulSoup(html, 'html.parser')
products_list = soup.find(class_='products-list') # products_list = soup.find(class_='products-list')
items = products_list.find_all(class_='card') # items = products_list.find_all(class_='card')
self.assertEqual(len(items), len(template_items + variant_items)) # self.assertEqual(len(items), len(template_items + variant_items))
items_with_item_group = frappe.get_all('Item', {'item_group': '_Test Item Group Desktops', 'show_in_website': 1}) # items_with_item_group = frappe.get_all('Item', {'item_group': '_Test Item Group Desktops', 'show_in_website': 1})
variants_with_item_group = frappe.get_all('Item', {'item_group': '_Test Item Group Desktops', 'show_variant_in_website': 1}) # variants_with_item_group = frappe.get_all('Item', {'item_group': '_Test Item Group Desktops', 'show_variant_in_website': 1})
# mock query params # # mock query params
frappe.form_dict = frappe._dict({ # frappe.form_dict = frappe._dict({
'field_filters': '{"item_group":["_Test Item Group Desktops"]}' # 'field_filters': '{"item_group":["_Test Item Group Desktops"]}'
}) # })
html = get_html_for_route('all-products') # html = get_html_for_route('all-products')
soup = BeautifulSoup(html, 'html.parser') # soup = BeautifulSoup(html, 'html.parser')
products_list = soup.find(class_='products-list') # products_list = soup.find(class_='products-list')
items = products_list.find_all(class_='card') # items = products_list.find_all(class_='card')
self.assertEqual(len(items), len(items_with_item_group + variants_with_item_group)) # self.assertEqual(len(items), len(items_with_item_group + variants_with_item_group))
def test_get_products_for_website(self): # def test_get_products_for_website(self):
items = get_products_for_website(attribute_filters={ # items = get_products_for_website(attribute_filters={
'Test Size': ['2XL'] # 'Test Size': ['2XL']
}) # })
self.assertEqual(len(items), 1) # self.assertEqual(len(items), 1)
def test_products_in_multiple_item_groups(self): # def test_products_in_multiple_item_groups(self):
"""Check if product is visible on multiple item group pages barring its own.""" # """Check if product is visible on multiple item group pages barring its own."""
from erpnext.shopping_cart.product_query import ProductQuery # from erpnext.shopping_cart.product_query import ProductQuery
if not frappe.db.exists("Item Group", {"name": "Tech Items"}): # if not frappe.db.exists("Item Group", {"name": "Tech Items"}):
item_group_doc = frappe.get_doc({ # item_group_doc = frappe.get_doc({
"doctype": "Item Group", # "doctype": "Item Group",
"item_group_name": "Tech Items", # "item_group_name": "Tech Items",
"parent_item_group": "All Item Groups", # "parent_item_group": "All Item Groups",
"show_in_website": 1 # "show_in_website": 1
}).insert() # }).insert()
else: # else:
item_group_doc = frappe.get_doc("Item Group", "Tech Items") # item_group_doc = frappe.get_doc("Item Group", "Tech Items")
doc = self.create_regular_web_item("Portal Item", item_group="Tech Items") # doc = self.create_regular_web_item("Portal Item", item_group="Tech Items")
if not frappe.db.exists("Website Item Group", {"parent": "Portal Item"}): # if not frappe.db.exists("Website Item Group", {"parent": "Portal Item"}):
doc.append("website_item_groups", { # doc.append("website_item_groups", {
"item_group": "_Test Item Group Desktops" # "item_group": "_Test Item Group Desktops"
}) # })
doc.save() # doc.save()
# check if item is visible in its own Item Group's page # # check if item is visible in its own Item Group's page
engine = ProductQuery() # engine = ProductQuery()
result = engine.query({}, {"item_group": "Tech Items"}, None, start=0, item_group="Tech Items") # result = engine.query({}, {"item_group": "Tech Items"}, None, start=0, item_group="Tech Items")
items = result["items"] # items = result["items"]
self.assertEqual(len(items), 1) # self.assertEqual(len(items), 1)
self.assertEqual(items[0].item_code, "Portal Item") # self.assertEqual(items[0].item_code, "Portal Item")
# check if item is visible in configured foreign Item Group's page # # check if item is visible in configured foreign Item Group's page
engine = ProductQuery() # engine = ProductQuery()
result = engine.query({}, {"item_group": "_Test Item Group Desktops"}, None, start=0, item_group="_Test Item Group Desktops") # result = engine.query({}, {"item_group": "_Test Item Group Desktops"}, None, start=0, item_group="_Test Item Group Desktops")
items = result["items"] # items = result["items"]
item_codes = [row.item_code for row in items] # item_codes = [row.item_code for row in items]
self.assertIn(len(items), [2, 3]) # self.assertIn(len(items), [2, 3])
self.assertIn("Portal Item", item_codes) # self.assertIn("Portal Item", item_codes)
# teardown # # teardown
doc.delete() # doc.delete()
item_group_doc.delete() # item_group_doc.delete()

View File

@@ -84,7 +84,7 @@ erpnext.ProductSearch = class {
</div> </div>
`).find("#search-results-container"); `).find("#search-results-container");
this.setupCategoryContainer() this.setupCategoryContainer();
this.setupProductsContainer(); this.setupProductsContainer();
this.setupRecentsContainer(); this.setupRecentsContainer();
} }

View File

@@ -355,7 +355,7 @@ erpnext.ProductView = class {
delete this.field_filters["discount"]; delete this.field_filters["discount"];
if (is_checked) { if (is_checked) {
this.field_filters["discount"] = [] this.field_filters["discount"] = [];
this.field_filters["discount"].push(filter_value); this.field_filters["discount"].push(filter_value);
} }
@@ -364,7 +364,7 @@ erpnext.ProductView = class {
} }
me.change_route_with_filters(); me.change_route_with_filters();
}) });
} }
bind_filters() { bind_filters() {

View File

@@ -503,19 +503,6 @@ class TestItem(unittest.TestCase):
self.assertIsInstance(count, int) self.assertIsInstance(count, int)
self.assertTrue(count >= 0) self.assertTrue(count >= 0)
def test_index_creation(self):
"check if index is getting created in db"
from erpnext.stock.doctype.item.item import on_doctype_update
on_doctype_update()
indices = frappe.db.sql("show index from tabItem", as_dict=1)
expected_columns = {"item_code", "item_name", "item_group", "route"}
for index in indices:
expected_columns.discard(index.get("Column_name"))
if expected_columns:
self.fail(f"Expected db index on these columns: {', '.join(expected_columns)}")
def test_attribute_completions(self): def test_attribute_completions(self):
expected_attrs = {"Small", "Extra Small", "Extra Large", "Large", "2XL", "Medium"} expected_attrs = {"Small", "Extra Small", "Extra Large", "Large", "2XL", "Medium"}