mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-15 18:01:41 +00:00
Merge pull request #56234 from mihir-kandoi/pg-stock-index-tests
test(stock): make Bin/Item index tests Postgres-valid (SHOW INDEX → db-agnostic helpers)
This commit is contained in:
@@ -27,6 +27,6 @@ class TestBin(ERPNextTestSuite):
|
|||||||
self.assertEqual(bin.item_code, item_code)
|
self.assertEqual(bin.item_code, item_code)
|
||||||
|
|
||||||
def test_index_exists(self):
|
def test_index_exists(self):
|
||||||
indexes = frappe.db.sql("show index from tabBin where Non_unique = 0", as_dict=1)
|
# has_index is db-agnostic; raw "SHOW INDEX" is MySQL-only and errors on Postgres
|
||||||
if not any(index.get("Key_name") == "unique_item_warehouse" for index in indexes):
|
if not frappe.db.has_index("tabBin", "unique_item_warehouse"):
|
||||||
self.fail("Expected unique index on item-warehouse")
|
self.fail("Expected unique index on item-warehouse")
|
||||||
|
|||||||
@@ -778,10 +778,13 @@ class TestItem(ERPNextTestSuite):
|
|||||||
def test_index_creation(self):
|
def test_index_creation(self):
|
||||||
"check if index is getting created in db"
|
"check if index is getting created in db"
|
||||||
|
|
||||||
indices = frappe.db.sql("show index from tabItem", as_dict=1)
|
# get_column_index is db-agnostic; raw "SHOW INDEX" is MySQL-only and errors on Postgres
|
||||||
expected_columns = {"item_code", "item_name", "item_group"}
|
expected_columns = {"item_code", "item_name", "item_group"}
|
||||||
for index in indices:
|
for column in list(expected_columns):
|
||||||
expected_columns.discard(index.get("Column_name"))
|
if frappe.db.get_column_index("tabItem", column, unique=False) or frappe.db.get_column_index(
|
||||||
|
"tabItem", column, unique=True
|
||||||
|
):
|
||||||
|
expected_columns.discard(column)
|
||||||
|
|
||||||
if expected_columns:
|
if expected_columns:
|
||||||
self.fail(f"Expected db index on these columns: {', '.join(expected_columns)}")
|
self.fail(f"Expected db index on these columns: {', '.join(expected_columns)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user