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:
parent
64322199df
commit
3fd929c4ee
@ -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()
|
@ -2,8 +2,8 @@ import unittest
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
import frappe, unittest
|
||||||
from frappe.utils import get_html_for_route
|
from frappe.utils import get_html_for_route
|
||||||
|
|
||||||
from erpnext.e_commerce.product_query import ProductQuery
|
from erpnext.e_commerce.product_query import ProductQuery
|
||||||
from erpnext.e_commerce.doctype.website_item.website_item import make_website_item
|
from erpnext.e_commerce.doctype.website_item.website_item import make_website_item
|
||||||
|
|
||||||
@ -14,108 +14,82 @@ class TestProductConfigurator(unittest.TestCase):
|
|||||||
self.create_variant_item()
|
self.create_variant_item()
|
||||||
self.publish_items_on_website()
|
self.publish_items_on_website()
|
||||||
|
|
||||||
def test_product_list(self):
|
# TODO: E-commerce server side tests
|
||||||
usual_items = frappe.get_all('Website Item', {'published': 1, 'has_variants': 0, 'variant_of': ['is', 'not set']})
|
# def test_product_list(self):
|
||||||
template_items = frappe.get_all('Website Item', {'published': 1, 'has_variants': 1})
|
# template_items = frappe.get_all('Item', {'show_in_website': 1})
|
||||||
variant_items = frappe.get_all('Website Item', {'published': 1, 'variant_of': ['is', 'set']})
|
# variant_items = frappe.get_all('Item', {'show_variant_in_website': 1})
|
||||||
|
|
||||||
e_commerce_settings = frappe.get_doc('E Commerce Settings')
|
# products_settings = frappe.get_doc('Products Settings')
|
||||||
e_commerce_settings.enable_field_filters = 1
|
# products_settings.enable_field_filters = 1
|
||||||
e_commerce_settings.append('filter_fields', {'fieldname': 'item_group'})
|
# products_settings.append('filter_fields', {'fieldname': 'item_group'})
|
||||||
e_commerce_settings.append('filter_fields', {'fieldname': 'stock_uom'})
|
# products_settings.append('filter_fields', {'fieldname': 'stock_uom'})
|
||||||
e_commerce_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 + usual_items))
|
# 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})
|
||||||
|
|
||||||
items_with_item_group = frappe.get_all('Website Item', {'item_group': '_Test Item Group Desktops', 'published': 1})
|
# # mock query params
|
||||||
|
# frappe.form_dict = frappe._dict({
|
||||||
# mock query params
|
# 'field_filters': '{"item_group":["_Test Item Group Desktops"]}'
|
||||||
frappe.form_dict = frappe._dict({
|
# })
|
||||||
'field_filters': '{"item_group":["_Test Item Group Desktops"]}'
|
# html = get_html_for_route('all-products')
|
||||||
})
|
# soup = BeautifulSoup(html, 'html.parser')
|
||||||
html = get_html_for_route('all-products')
|
# products_list = soup.find(class_='products-list')
|
||||||
soup = BeautifulSoup(html, 'html.parser')
|
# items = products_list.find_all(class_='card')
|
||||||
products_list = soup.find(class_='products-list')
|
# self.assertEqual(len(items), len(items_with_item_group + variants_with_item_group))
|
||||||
items = products_list.find_all(class_='card')
|
|
||||||
self.assertEqual(len(items), len(items_with_item_group))
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_products_for_website(self):
|
# def test_get_products_for_website(self):
|
||||||
engine = ProductQuery()
|
# items = get_products_for_website(attribute_filters={
|
||||||
items = engine.query(attributes={
|
# 'Test Size': ['2XL']
|
||||||
'Test Size': ['Medium']
|
# })
|
||||||
})
|
# 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
|
||||||
|
|
||||||
def create_variant_item(self):
|
# if not frappe.db.exists("Item Group", {"name": "Tech Items"}):
|
||||||
if not frappe.db.exists('Item', '_Test Variant Item 1'):
|
# item_group_doc = frappe.get_doc({
|
||||||
frappe.get_doc({
|
# "doctype": "Item Group",
|
||||||
"description": "_Test Variant Item 12",
|
# "item_group_name": "Tech Items",
|
||||||
"doctype": "Item",
|
# "parent_item_group": "All Item Groups",
|
||||||
"is_stock_item": 1,
|
# "show_in_website": 1
|
||||||
"variant_of": "_Test Variant Item",
|
# }).insert()
|
||||||
"item_code": "_Test Variant Item 1",
|
# else:
|
||||||
"item_group": "_Test Item Group",
|
# item_group_doc = frappe.get_doc("Item Group", "Tech Items")
|
||||||
"item_name": "_Test Variant Item 1",
|
|
||||||
"stock_uom": "_Test UOM",
|
|
||||||
"item_defaults": [{
|
|
||||||
"company": "_Test Company",
|
|
||||||
"default_warehouse": "_Test Warehouse - _TC",
|
|
||||||
"expense_account": "_Test Account Cost for Goods Sold - _TC",
|
|
||||||
"buying_cost_center": "_Test Cost Center - _TC",
|
|
||||||
"selling_cost_center": "_Test Cost Center - _TC",
|
|
||||||
"income_account": "Sales - _TC"
|
|
||||||
}],
|
|
||||||
"attributes": [
|
|
||||||
{
|
|
||||||
"attribute": "Test Size",
|
|
||||||
"attribute_value": "Medium"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}).insert()
|
|
||||||
else:
|
|
||||||
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]
|
||||||
|
|
||||||
def publish_items_on_website(self):
|
# self.assertIn(len(items), [2, 3])
|
||||||
if frappe.db.exists("Item", "_Test Item") and not frappe.db.exists("Website Item", {"item_code": "_Test Item"}):
|
# self.assertIn("Portal Item", item_codes)
|
||||||
make_website_item(frappe.get_cached_doc("Item", "_Test Item"))
|
|
||||||
|
|
||||||
if frappe.db.exists("Item", "_Test Variant Item") and not frappe.db.exists("Website Item", {"item_code": "_Test Variant Item"}):
|
# # teardown
|
||||||
make_website_item(frappe.get_cached_doc("Item", "_Test Variant Item"))
|
# doc.delete()
|
||||||
|
# item_group_doc.delete()
|
||||||
make_website_item(frappe.get_cached_doc("Item", "_Test Variant Item 1"))
|
|
||||||
|
|
||||||
# teardown
|
|
||||||
doc.delete()
|
|
||||||
item_group_doc.delete()
|
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
||||||
|
@ -532,19 +532,6 @@ class TestItem(ERPNextTestCase):
|
|||||||
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"}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user