refactor(test): move dimension setup to test data bootstrap

and remove create_dimension() and disable_dimension()
This commit is contained in:
ruthra kumar
2026-03-20 11:50:01 +05:30
parent ed76d6699a
commit 342ce65401
7 changed files with 32 additions and 102 deletions

View File

@@ -9,9 +9,6 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestAccountingDimension(ERPNextTestSuite): class TestAccountingDimension(ERPNextTestSuite):
def setUp(self):
create_dimension()
def test_dimension_against_sales_invoice(self): def test_dimension_against_sales_invoice(self):
si = create_sales_invoice(do_not_save=1) si = create_sales_invoice(do_not_save=1)
@@ -76,63 +73,3 @@ class TestAccountingDimension(ERPNextTestSuite):
si.save() si.save()
self.assertRaises(frappe.ValidationError, si.submit) self.assertRaises(frappe.ValidationError, si.submit)
def create_dimension():
frappe.set_user("Administrator")
if not frappe.db.exists("Accounting Dimension", {"document_type": "Department"}):
dimension = frappe.get_doc(
{
"doctype": "Accounting Dimension",
"document_type": "Department",
}
)
dimension.append(
"dimension_defaults",
{
"company": "_Test Company",
"reference_document": "Department",
"default_dimension": "_Test Department - _TC",
},
)
dimension.insert()
dimension.save()
else:
dimension = frappe.get_doc("Accounting Dimension", "Department")
dimension.disabled = 0
dimension.save()
if not frappe.db.exists("Accounting Dimension", {"document_type": "Location"}):
dimension1 = frappe.get_doc(
{
"doctype": "Accounting Dimension",
"document_type": "Location",
}
)
dimension1.append(
"dimension_defaults",
{
"company": "_Test Company",
"reference_document": "Location",
"default_dimension": "Block 1",
},
)
dimension1.insert()
dimension1.save()
else:
dimension1 = frappe.get_doc("Accounting Dimension", "Location")
dimension1.disabled = 0
dimension1.save()
def disable_dimension():
dimension1 = frappe.get_doc("Accounting Dimension", "Department")
dimension1.disabled = 1
dimension1.save()
dimension2 = frappe.get_doc("Accounting Dimension", "Location")
dimension2.disabled = 1
dimension2.save()

View File

@@ -3,9 +3,6 @@
import frappe import frappe
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import (
create_dimension,
)
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.exceptions import InvalidAccountDimensionError, MandatoryAccountDimensionError from erpnext.exceptions import InvalidAccountDimensionError, MandatoryAccountDimensionError
from erpnext.tests.utils import ERPNextTestSuite from erpnext.tests.utils import ERPNextTestSuite
@@ -13,7 +10,6 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestAccountingDimensionFilter(ERPNextTestSuite): class TestAccountingDimensionFilter(ERPNextTestSuite):
def setUp(self): def setUp(self):
create_dimension()
create_accounting_dimension_filter() create_accounting_dimension_filter()
self.invoice_list = [] self.invoice_list = []

View File

@@ -3,9 +3,6 @@
import frappe import frappe
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import (
create_dimension,
)
from erpnext.accounts.doctype.opening_invoice_creation_tool.opening_invoice_creation_tool import ( from erpnext.accounts.doctype.opening_invoice_creation_tool.opening_invoice_creation_tool import (
get_temporary_opening_account, get_temporary_opening_account,
) )
@@ -14,9 +11,9 @@ from erpnext.tests.utils import ERPNextTestSuite
class TestOpeningInvoiceCreationTool(ERPNextTestSuite): class TestOpeningInvoiceCreationTool(ERPNextTestSuite):
def setUp(self): def setUp(self):
# TODO: move to bootstrap
if not frappe.db.exists("Company", "_Test Opening Invoice Company"): if not frappe.db.exists("Company", "_Test Opening Invoice Company"):
make_company() make_company()
create_dimension()
def make_invoices( def make_invoices(
self, self,

View File

@@ -3,10 +3,6 @@
import frappe import frappe
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import (
create_dimension,
disable_dimension,
)
from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import ( from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import (
make_closing_entry_from_opening, make_closing_entry_from_opening,
) )
@@ -161,7 +157,6 @@ class TestPOSClosingEntry(ERPNextTestSuite):
test case to check whether we can create POS Closing Entry without mandatory accounting dimension test case to check whether we can create POS Closing Entry without mandatory accounting dimension
""" """
create_dimension()
location = frappe.get_doc("Accounting Dimension", "Location") location = frappe.get_doc("Accounting Dimension", "Location")
location.dimension_defaults[0].mandatory_for_bs = True location.dimension_defaults[0].mandatory_for_bs = True
location.save() location.save()
@@ -197,7 +192,6 @@ class TestPOSClosingEntry(ERPNextTestSuite):
) )
accounting_dimension_department.mandatory_for_bs = 0 accounting_dimension_department.mandatory_for_bs = 0
accounting_dimension_department.save() accounting_dimension_department.save()
disable_dimension()
def test_merging_into_sales_invoice_for_batched_item(self): def test_merging_into_sales_invoice_for_batched_item(self):
frappe.flags.print_message = False frappe.flags.print_message = False

View File

@@ -2246,13 +2246,6 @@ class TestSalesInvoice(ERPNextTestSuite):
@ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True})
def test_rounding_adjustment_3(self): def test_rounding_adjustment_3(self):
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import create_dimension
# Dimension creates custom field, which does an implicit DB commit as it is a DDL command
# Ensure dimension don't have any mandatory fields
create_dimension()
# rollback from tearDown() happens till here
si = create_sales_invoice(do_not_save=True) si = create_sales_invoice(do_not_save=True)
si.items = [] si.items = []
for d in [(1122, 2), (1122.01, 1), (1122.01, 1)]: for d in [(1122, 2), (1122.01, 1), (1122.01, 1)]:

View File

@@ -1567,25 +1567,10 @@ class TestAccountsController(ERPNextTestSuite):
frappe.db.set_value("Company", self.company, "cost_center", cc) frappe.db.set_value("Company", self.company, "cost_center", cc)
def setup_dimensions(self):
# create dimension
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import (
create_dimension,
)
create_dimension()
# make it non-mandatory
loc = frappe.get_doc("Accounting Dimension", "Location")
for x in loc.dimension_defaults:
x.mandatory_for_bs = False
x.mandatory_for_pl = False
loc.save()
def test_90_dimensions_filter(self): def test_90_dimensions_filter(self):
""" """
Test workings of dimension filters Test workings of dimension filters
""" """
self.setup_dimensions()
rate_in_account_currency = 1 rate_in_account_currency = 1
# Invoices # Invoices
@@ -1653,7 +1638,6 @@ class TestAccountsController(ERPNextTestSuite):
self.assertEqual(len(pr.payments), 1) self.assertEqual(len(pr.payments), 1)
def test_91_cr_note_should_inherit_dimension(self): def test_91_cr_note_should_inherit_dimension(self):
self.setup_dimensions()
rate_in_account_currency = 1 rate_in_account_currency = 1
# Invoice # Invoice
@@ -1698,7 +1682,6 @@ class TestAccountsController(ERPNextTestSuite):
def test_92_dimension_inhertiance_exc_gain_loss(self): def test_92_dimension_inhertiance_exc_gain_loss(self):
# Sales Invoice in Foreign Currency # Sales Invoice in Foreign Currency
self.setup_dimensions()
rate_in_account_currency = 1 rate_in_account_currency = 1
dpt = "Research & Development - _TC" dpt = "Research & Development - _TC"
@@ -1734,7 +1717,6 @@ class TestAccountsController(ERPNextTestSuite):
) )
def test_93_dimension_inheritance_on_advance(self): def test_93_dimension_inheritance_on_advance(self):
self.setup_dimensions()
dpt = "Research & Development - _TC" dpt = "Research & Development - _TC"
adv = self.create_payment_entry(amount=1, source_exc_rate=85) adv = self.create_payment_entry(amount=1, source_exc_rate=85)

View File

@@ -246,6 +246,10 @@ class BootStrapTestData:
frappe.db.commit() # nosemgrep frappe.db.commit() # nosemgrep
# Dimensions
# DDL commands have implicit commit
self.make_dimensions()
# custom doctype # custom doctype
# DDL commands have implicit commit # DDL commands have implicit commit
self.make_custom_doctype() self.make_custom_doctype()
@@ -2794,6 +2798,33 @@ class BootStrapTestData:
] ]
self.make_records(["address_title", "address_type"], records) self.make_records(["address_title", "address_type"], records)
def make_dimensions(self):
records = [
{
"doctype": "Accounting Dimension",
"document_type": "Department",
"dimension_defaults": [
{
"company": "_Test Company",
"reference_document": "Department",
"default_dimension": "_Test Department - _TC",
}
],
},
{
"doctype": "Accounting Dimension",
"document_type": "Location",
"dimension_defaults": [
{
"company": "_Test Company",
"reference_document": "Location",
"default_dimension": "Block 1",
}
],
},
]
self.make_records(["document_type"], records)
BootStrapTestData() BootStrapTestData()