diff --git a/.github/workflows/run-indinvidual-tests.yml b/.github/workflows/run-individual-tests.yml similarity index 82% rename from .github/workflows/run-indinvidual-tests.yml rename to .github/workflows/run-individual-tests.yml index 3e4b8371f8a..a70a2394757 100644 --- a/.github/workflows/run-indinvidual-tests.yml +++ b/.github/workflows/run-individual-tests.yml @@ -4,8 +4,8 @@ on: workflow_dispatch: concurrency: - group: server-individual-tests-develop-${{ github.event_name }}-${{ github.event.number || github.event_name == 'workflow_dispatch' && github.run_id || '' }} - cancel-in-progress: false + group: server-individual-tests-lightmode-develop + cancel-in-progress: true permissions: contents: read @@ -21,7 +21,7 @@ jobs: - id: set-matrix run: | # Use grep and find to get the list of test files - matrix=$(find . -path '*/doctype/*/test_*.py' | xargs grep -l 'def test_' | awk '{ + matrix=$(find . -path '*/test_*.py' | xargs grep -l 'def test_' | sort | awk '{ # Remove ./ prefix, file extension, and replace / with . gsub(/^\.\//, "", $0) gsub(/\.py$/, "", $0) @@ -58,6 +58,7 @@ jobs: strategy: fail-fast: false matrix: ${{fromJson(needs.discover.outputs.matrix)}} + max-parallel: 14 name: Test @@ -130,4 +131,13 @@ jobs: FRAPPE_BRANCH: ${{ github.event.inputs.branch }} - name: Run Tests - run: 'cd ~/frappe-bench/ && bench --site test_site run-tests --app erpnext --module ${{ matrix.test }}' + run: | + site_name=$(echo "${{matrix.test}}" | sed -e 's/.*\.\(test_.*$\)/\1/') + echo "$site_name" + mkdir ~/frappe-bench/sites/$site_name + cp -r "${GITHUB_WORKSPACE}/.github/helper/site_config_mariadb.json" ~/frappe-bench/sites/$site_name/site_config.json + cd ~/frappe-bench/ + bench --site $site_name reinstall --yes + bench --site $site_name set-config allow_tests true + bench --site $site_name run-tests --module ${{ matrix.test }} --lightmode + diff --git a/.github/workflows/server-tests-mariadb.yml b/.github/workflows/server-tests-mariadb.yml index 2bfe5e7065d..b8e88d1b5f3 100644 --- a/.github/workflows/server-tests-mariadb.yml +++ b/.github/workflows/server-tests-mariadb.yml @@ -129,7 +129,7 @@ jobs: FRAPPE_BRANCH: ${{ github.event.client_payload.sha || github.event.inputs.branch }} - name: Run Tests - run: 'cd ~/frappe-bench/ && bench --site test_site run-parallel-tests --app erpnext --total-builds ${{ strategy.job-total }} --build-number ${{ matrix.container }} --with-coverage' + run: 'cd ~/frappe-bench/ && bench --site test_site run-parallel-tests --lightmode --app erpnext --total-builds ${{ strategy.job-total }} --build-number ${{ matrix.container }} --with-coverage' env: TYPE: server diff --git a/erpnext/accounts/deferred_revenue.py b/erpnext/accounts/deferred_revenue.py index c3e23fe6e50..3c841aef05f 100644 --- a/erpnext/accounts/deferred_revenue.py +++ b/erpnext/accounts/deferred_revenue.py @@ -524,7 +524,8 @@ def make_gl_entries( if gl_entries: try: make_gl_entries(gl_entries, cancel=(doc.docstatus == 2), merge_entries=True) - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() except Exception as e: if frappe.in_test: doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}") @@ -606,7 +607,8 @@ def book_revenue_via_journal_entry( if submit: journal_entry.submit() - frappe.db.commit() + if not frappe.in_test: + frappe.db.commit() except Exception: frappe.db.rollback() doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}") diff --git a/erpnext/accounts/doctype/account/test_account.py b/erpnext/accounts/doctype/account/test_account.py index 6deff1ac3e6..95f17967fa7 100644 --- a/erpnext/accounts/doctype/account/test_account.py +++ b/erpnext/accounts/doctype/account/test_account.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate from erpnext.accounts.doctype.account.account import ( @@ -12,11 +11,10 @@ from erpnext.accounts.doctype.account.account import ( update_account_number, ) from erpnext.stock import get_company_default_inventory_account, get_warehouse_account - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Company"] +from erpnext.tests.utils import ERPNextTestSuite -class TestAccount(IntegrationTestCase): +class TestAccount(ERPNextTestSuite): def test_rename_account(self): if not frappe.db.exists("Account", "1210 - Debtors - _TC"): acc = frappe.new_doc("Account") diff --git a/erpnext/accounts/doctype/account/test_records.json b/erpnext/accounts/doctype/account/test_records.json deleted file mode 100644 index d15f7ad4c0a..00000000000 --- a/erpnext/accounts/doctype/account/test_records.json +++ /dev/null @@ -1,6 +0,0 @@ -[ - { - "doctype": "Account", - "name": "_Test Account 1" - } -] diff --git a/erpnext/accounts/doctype/account_category/test_account_category.py b/erpnext/accounts/doctype/account_category/test_account_category.py index ea3c2c7783c..e695b11bcb5 100644 --- a/erpnext/accounts/doctype/account_category/test_account_category.py +++ b/erpnext/accounts/doctype/account_category/test_account_category.py @@ -2,19 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class IntegrationTestAccountCategory(IntegrationTestCase): - """ - Integration tests for AccountCategory. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/accounts/doctype/account_closing_balance/test_account_closing_balance.py b/erpnext/accounts/doctype/account_closing_balance/test_account_closing_balance.py index 53f4e5d15af..a39bd00579e 100644 --- a/erpnext/accounts/doctype/account_closing_balance/test_account_closing_balance.py +++ b/erpnext/accounts/doctype/account_closing_balance/test_account_closing_balance.py @@ -2,8 +2,9 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountClosingBalance(IntegrationTestCase): +class TestAccountClosingBalance(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py index 769522e2642..81e639dc6b2 100644 --- a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py @@ -3,15 +3,13 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Cost Center", "Location", "Warehouse", "Department"] +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountingDimension(IntegrationTestCase): +class TestAccountingDimension(ERPNextTestSuite): def setUp(self): create_dimension() @@ -80,11 +78,6 @@ class TestAccountingDimension(IntegrationTestCase): si.save() self.assertRaises(frappe.ValidationError, si.submit) - def tearDown(self): - disable_dimension() - frappe.flags.accounting_dimensions_details = None - frappe.flags.dimension_filter_map = None - def create_dimension(): frappe.set_user("Administrator") diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py index bff288cf4d8..9bed10824bb 100644 --- a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py +++ b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py @@ -11,11 +11,10 @@ from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension imp ) from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.exceptions import InvalidAccountDimensionError, MandatoryAccountDimensionError - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Location", "Cost Center", "Department"] +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountingDimensionFilter(unittest.TestCase): +class TestAccountingDimensionFilter(ERPNextTestSuite): def setUp(self): create_dimension() create_accounting_dimension_filter() @@ -44,17 +43,6 @@ class TestAccountingDimensionFilter(unittest.TestCase): self.assertRaises(MandatoryAccountDimensionError, si.submit) self.invoice_list.append(si) - def tearDown(self): - disable_dimension_filter() - disable_dimension() - frappe.flags.accounting_dimensions_details = None - frappe.flags.dimension_filter_map = None - - for si in self.invoice_list: - si.load_from_db() - if si.docstatus == 1: - si.cancel() - def create_accounting_dimension_filter(): if not frappe.db.get_value("Accounting Dimension Filter", {"accounting_dimension": "Cost Center"}): diff --git a/erpnext/accounts/doctype/accounting_period/test_accounting_period.py b/erpnext/accounts/doctype/accounting_period/test_accounting_period.py index 1dde96c223d..84df275f305 100644 --- a/erpnext/accounts/doctype/accounting_period/test_accounting_period.py +++ b/erpnext/accounts/doctype/accounting_period/test_accounting_period.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_months, nowdate from erpnext.accounts.doctype.accounting_period.accounting_period import ( @@ -11,11 +10,10 @@ from erpnext.accounts.doctype.accounting_period.accounting_period import ( OverlapError, ) from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"] +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountingPeriod(IntegrationTestCase): +class TestAccountingPeriod(ERPNextTestSuite): def test_overlap(self): ap1 = create_accounting_period( start_date="2018-04-01", end_date="2018-06-30", company="Wind Power LLC" @@ -90,10 +88,6 @@ class TestAccountingPeriod(IntegrationTestCase): doc.submit() # Should not raise self.assertEqual(doc.docstatus, 1) - def tearDown(self): - for d in frappe.get_all("Accounting Period"): - frappe.delete_doc("Accounting Period", d.name) - def create_accounting_period(**args): args = frappe._dict(args) diff --git a/erpnext/accounts/doctype/accounts_settings/test_accounts_settings.py b/erpnext/accounts/doctype/accounts_settings/test_accounts_settings.py index e555f0ded15..d57bd1cc009 100644 --- a/erpnext/accounts/doctype/accounts_settings/test_accounts_settings.py +++ b/erpnext/accounts/doctype/accounts_settings/test_accounts_settings.py @@ -1,17 +1,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountsSettings(IntegrationTestCase): - def tearDown(self): - # Just in case `save` method succeeds, we need to take things back to default so that other tests - # don't break - cur_settings = frappe.get_doc("Accounts Settings", "Accounts Settings") - cur_settings.allow_stale = 1 - cur_settings.save() - +class TestAccountsSettings(ERPNextTestSuite): def test_stale_days(self): cur_settings = frappe.get_doc("Accounts Settings", "Accounts Settings") cur_settings.allow_stale = 0 diff --git a/erpnext/accounts/doctype/advance_payment_ledger_entry/test_advance_payment_ledger_entry.py b/erpnext/accounts/doctype/advance_payment_ledger_entry/test_advance_payment_ledger_entry.py index f824e6893e4..53047b61718 100644 --- a/erpnext/accounts/doctype/advance_payment_ledger_entry/test_advance_payment_ledger_entry.py +++ b/erpnext/accounts/doctype/advance_payment_ledger_entry/test_advance_payment_ledger_entry.py @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate, today from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry @@ -10,14 +9,13 @@ from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order -# On IntegrationTestCase, the doctype test records and all +# On ERPNextTestSuite, the doctype test records and all # link-field test record depdendencies are recursively loaded # Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] +from erpnext.tests.utils import ERPNextTestSuite -class TestAdvancePaymentLedgerEntry(AccountsTestMixin, IntegrationTestCase): +class TestAdvancePaymentLedgerEntry(AccountsTestMixin, ERPNextTestSuite): """ Integration tests for AdvancePaymentLedgerEntry. Use this class for testing interactions between multiple components. @@ -30,9 +28,6 @@ class TestAdvancePaymentLedgerEntry(AccountsTestMixin, IntegrationTestCase): self.create_item() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_sales_order(self, qty=1, rate=100, currency="INR", do_not_submit=False): """ Helper method diff --git a/erpnext/accounts/doctype/bank/test_bank.py b/erpnext/accounts/doctype/bank/test_bank.py index 98e83fd5837..1249b6cc34a 100644 --- a/erpnext/accounts/doctype/bank/test_bank.py +++ b/erpnext/accounts/doctype/bank/test_bank.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBank(IntegrationTestCase): +class TestBank(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bank_account/test_bank_account.py b/erpnext/accounts/doctype/bank_account/test_bank_account.py index 146f426e6c7..0645a110140 100644 --- a/erpnext/accounts/doctype/bank_account/test_bank_account.py +++ b/erpnext/accounts/doctype/bank_account/test_bank_account.py @@ -2,10 +2,8 @@ # See license.txt import unittest -import frappe -from frappe import ValidationError -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBankAccount(IntegrationTestCase): +class TestBankAccount(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bank_account_subtype/test_bank_account_subtype.py b/erpnext/accounts/doctype/bank_account_subtype/test_bank_account_subtype.py index d4a6c689bc3..0e6a2c52138 100644 --- a/erpnext/accounts/doctype/bank_account_subtype/test_bank_account_subtype.py +++ b/erpnext/accounts/doctype/bank_account_subtype/test_bank_account_subtype.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBankAccountSubtype(IntegrationTestCase): +class TestBankAccountSubtype(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bank_account_type/test_bank_account_type.py b/erpnext/accounts/doctype/bank_account_type/test_bank_account_type.py index 0d41686da59..0b602b3b9d6 100644 --- a/erpnext/accounts/doctype/bank_account_type/test_bank_account_type.py +++ b/erpnext/accounts/doctype/bank_account_type/test_bank_account_type.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBankAccountType(IntegrationTestCase): +class TestBankAccountType(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bank_clearance/test_bank_clearance.py b/erpnext/accounts/doctype/bank_clearance/test_bank_clearance.py index dda65594554..4982177e73b 100644 --- a/erpnext/accounts/doctype/bank_clearance/test_bank_clearance.py +++ b/erpnext/accounts/doctype/bank_clearance/test_bank_clearance.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_months, getdate from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center @@ -15,13 +14,12 @@ from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse -from erpnext.tests.utils import if_lending_app_installed, if_lending_app_not_installed +from erpnext.tests.utils import ERPNextTestSuite, if_lending_app_installed, if_lending_app_not_installed -class TestBankClearance(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestBankClearance(ERPNextTestSuite): + def setUp(self): + frappe.clear_cache() create_warehouse( warehouse_name="_Test Warehouse", properties={"parent_warehouse": "All Warehouses - _TC"}, diff --git a/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py index eaf55ce7708..72dad011e56 100644 --- a/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBankGuarantee(IntegrationTestCase): +class TestBankGuarantee(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py b/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py index 53586b333b4..5354aa0c4dd 100644 --- a/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py +++ b/erpnext/accounts/doctype/bank_reconciliation_tool/test_bank_reconciliation_tool.py @@ -4,7 +4,6 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, today from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool import ( @@ -13,9 +12,10 @@ from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool ) from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestBankReconciliationTool(AccountsTestMixin, IntegrationTestCase): +class TestBankReconciliationTool(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() @@ -24,9 +24,6 @@ class TestBankReconciliationTool(AccountsTestMixin, IntegrationTestCase): qb.from_(bank_dt).delete().where(bank_dt.name == "HDFC").run() self.create_bank_account() - def tearDown(self): - frappe.db.rollback() - def create_bank_account(self): bank = frappe.get_doc( { @@ -43,6 +40,7 @@ class TestBankReconciliationTool(AccountsTestMixin, IntegrationTestCase): "bank": bank.name, "is_company_account": True, "account": self.bank, # account from Chart of Accounts + "company": self.company, } ) .insert() diff --git a/erpnext/accounts/doctype/bank_statement_import/test_bank_statement_import.py b/erpnext/accounts/doctype/bank_statement_import/test_bank_statement_import.py index 3e1cee9115e..2ae00059c83 100644 --- a/erpnext/accounts/doctype/bank_statement_import/test_bank_statement_import.py +++ b/erpnext/accounts/doctype/bank_statement_import/test_bank_statement_import.py @@ -1,15 +1,14 @@ # Copyright (c) 2020, Frappe Technologies and Contributors # See license.txt -import unittest - from erpnext.accounts.doctype.bank_statement_import.bank_statement_import import ( is_mt940_format, preprocess_mt940_content, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestBankStatementImport(unittest.TestCase): +class TestBankStatementImport(ERPNextTestSuite): """Unit tests for Bank Statement Import functions""" def test_preprocess_mt940_content_with_long_statement_number(self): diff --git a/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py b/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py index da2c28a148c..bb1e436c5f7 100644 --- a/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py +++ b/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py @@ -2,27 +2,20 @@ # License: GNU General Public License v3. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate from erpnext.accounts.doctype.bank_transaction.test_bank_transaction import create_bank_account +from erpnext.tests.utils import ERPNextTestSuite IBAN_1 = "DE02000000003716541159" IBAN_2 = "DE02500105170137075030" -class TestAutoMatchParty(IntegrationTestCase): - @classmethod - def setUpClass(cls): +class TestAutoMatchParty(ERPNextTestSuite): + def setUp(self): create_bank_account() frappe.db.set_single_value("Accounts Settings", "enable_party_matching", 1) frappe.db.set_single_value("Accounts Settings", "enable_fuzzy_matching", 1) - return super().setUpClass() - - @classmethod - def tearDownClass(cls): - frappe.db.set_single_value("Accounts Settings", "enable_party_matching", 0) - frappe.db.set_single_value("Accounts Settings", "enable_fuzzy_matching", 0) def test_match_by_account_number(self): create_supplier_for_match(account_no=IBAN_1[11:]) diff --git a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py index e04c67e54d4..c69d255c51a 100644 --- a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py @@ -6,7 +6,6 @@ import json import frappe from frappe import utils from frappe.model.docstatus import DocStatus -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool import ( get_linked_payments, @@ -19,12 +18,10 @@ from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_paymen from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice -from erpnext.tests.utils import if_lending_app_installed - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Cost Center"] +from erpnext.tests.utils import ERPNextTestSuite, if_lending_app_installed -class TestBankTransaction(IntegrationTestCase): +class TestBankTransaction(ERPNextTestSuite): def setUp(self): make_pos_profile() diff --git a/erpnext/accounts/doctype/bisect_accounting_statements/test_bisect_accounting_statements.py b/erpnext/accounts/doctype/bisect_accounting_statements/test_bisect_accounting_statements.py index fd1793b2560..55e4811a87f 100644 --- a/erpnext/accounts/doctype/bisect_accounting_statements/test_bisect_accounting_statements.py +++ b/erpnext/accounts/doctype/bisect_accounting_statements/test_bisect_accounting_statements.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestBisectAccountingStatements(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestBisectAccountingStatements(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/bisect_nodes/test_bisect_nodes.py b/erpnext/accounts/doctype/bisect_nodes/test_bisect_nodes.py index 1f37009d8e2..082b2a28f1f 100644 --- a/erpnext/accounts/doctype/bisect_nodes/test_bisect_nodes.py +++ b/erpnext/accounts/doctype/bisect_nodes/test_bisect_nodes.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestBisectNodes(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestBisectNodes(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py index ba9b4c04e08..9632981b1c1 100644 --- a/erpnext/accounts/doctype/budget/test_budget.py +++ b/erpnext/accounts/doctype/budget/test_budget.py @@ -19,12 +19,6 @@ from erpnext.tests.utils import ERPNextTestSuite class TestBudget(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.make_monthly_distribution() - cls.make_projects() - def setUp(self): frappe.db.set_single_value("Accounts Settings", "use_legacy_budget_controller", False) self.company = "_Test Company" diff --git a/erpnext/accounts/doctype/cashier_closing/test_cashier_closing.py b/erpnext/accounts/doctype/cashier_closing/test_cashier_closing.py index 56cf2b53919..1c826e31add 100644 --- a/erpnext/accounts/doctype/cashier_closing/test_cashier_closing.py +++ b/erpnext/accounts/doctype/cashier_closing/test_cashier_closing.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCashierClosing(IntegrationTestCase): +class TestCashierClosing(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/chart_of_accounts_importer/test_chart_of_accounts_importer.py b/erpnext/accounts/doctype/chart_of_accounts_importer/test_chart_of_accounts_importer.py index 214de348169..f96d46e90a9 100644 --- a/erpnext/accounts/doctype/chart_of_accounts_importer/test_chart_of_accounts_importer.py +++ b/erpnext/accounts/doctype/chart_of_accounts_importer/test_chart_of_accounts_importer.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestChartofAccountsImporter(IntegrationTestCase): +class TestChartofAccountsImporter(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/cheque_print_template/test_cheque_print_template.py b/erpnext/accounts/doctype/cheque_print_template/test_cheque_print_template.py index b7ee19d4422..54c62141e1c 100644 --- a/erpnext/accounts/doctype/cheque_print_template/test_cheque_print_template.py +++ b/erpnext/accounts/doctype/cheque_print_template/test_cheque_print_template.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestChequePrintTemplate(IntegrationTestCase): +class TestChequePrintTemplate(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/cost_center/test_cost_center.py b/erpnext/accounts/doctype/cost_center/test_cost_center.py index 375541a3960..cfde7238eab 100644 --- a/erpnext/accounts/doctype/cost_center/test_cost_center.py +++ b/erpnext/accounts/doctype/cost_center/test_cost_center.py @@ -3,10 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestCostCenter(IntegrationTestCase): +class TestCostCenter(ERPNextTestSuite): def test_cost_center_creation_against_child_node(self): cost_center = frappe.get_doc( { diff --git a/erpnext/accounts/doctype/cost_center/test_records.json b/erpnext/accounts/doctype/cost_center/test_records.json deleted file mode 100644 index 941a85b382d..00000000000 --- a/erpnext/accounts/doctype/cost_center/test_records.json +++ /dev/null @@ -1,23 +0,0 @@ -[ - { - "company": "_Test Company", - "cost_center_name": "_Test Cost Center", - "doctype": "Cost Center", - "is_group": 0, - "parent_cost_center": "_Test Company - _TC" - }, - { - "company": "_Test Company", - "cost_center_name": "_Test Cost Center 2", - "doctype": "Cost Center", - "is_group": 0, - "parent_cost_center": "_Test Company - _TC" - }, - { - "company": "_Test Company", - "cost_center_name": "_Test Write Off Cost Center", - "doctype": "Cost Center", - "is_group": 0, - "parent_cost_center": "_Test Company - _TC" - } -] diff --git a/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py b/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py index 680e2113ec1..4047e6c7169 100644 --- a/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py +++ b/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py @@ -4,7 +4,6 @@ import unittest import frappe from frappe.query_builder.functions import Sum -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, today from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center @@ -16,9 +15,10 @@ from erpnext.accounts.doctype.cost_center_allocation.cost_center_allocation impo WrongPercentageAllocation, ) from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestCostCenterAllocation(IntegrationTestCase): +class TestCostCenterAllocation(ERPNextTestSuite): def setUp(self): cost_centers = [ "Main Cost Center 1", @@ -191,7 +191,7 @@ class TestCostCenterAllocation(IntegrationTestCase): coa2.cancel() jv.cancel() - @IntegrationTestCase.change_settings("System Settings", {"rounding_method": "Commercial Rounding"}) + @ERPNextTestSuite.change_settings("System Settings", {"rounding_method": "Commercial Rounding"}) def test_debit_credit_on_cost_center_allocation_for_commercial_rounding(self): from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice diff --git a/erpnext/accounts/doctype/coupon_code/test_coupon_code.py b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py index ce57a27a536..770c24cd740 100644 --- a/erpnext/accounts/doctype/coupon_code/test_coupon_code.py +++ b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py @@ -3,11 +3,9 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"] +from erpnext.tests.utils import ERPNextTestSuite def test_create_test_data(): @@ -88,6 +86,7 @@ def test_create_test_data(): "partner_name": "_Test Coupon Partner", "commission_rate": 2, "referral_code": "COPART", + "territory": "All Territories", } ) sales_partner.insert() @@ -110,13 +109,10 @@ def test_create_test_data(): coupon_code.insert() -class TestCouponCode(IntegrationTestCase): +class TestCouponCode(ERPNextTestSuite): def setUp(self): test_create_test_data() - def tearDown(self): - frappe.set_user("Administrator") - def test_sales_order_with_coupon_code(self): frappe.db.set_value("Coupon Code", "SAVE30", "used", 0) diff --git a/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py b/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py index 3097f72d628..0c1c163a398 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py +++ b/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCurrencyExchangeSettings(IntegrationTestCase): +class TestCurrencyExchangeSettings(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/dunning/test_dunning.py b/erpnext/accounts/doctype/dunning/test_dunning.py index 4ba44a2a3c9..6eaf1d8798e 100644 --- a/erpnext/accounts/doctype/dunning/test_dunning.py +++ b/erpnext/accounts/doctype/dunning/test_dunning.py @@ -4,37 +4,20 @@ import json import frappe from frappe.model import mapper -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, nowdate, today from erpnext import get_default_cost_center from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry -from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import ( - unlink_payment_on_cancel_of_invoice, -) from erpnext.accounts.doctype.sales_invoice.sales_invoice import ( create_dunning as create_dunning_from_sales_invoice, ) from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import ( create_sales_invoice_against_cost_center, ) - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Company", "Cost Center"] +from erpnext.tests.utils import ERPNextTestSuite -class TestDunning(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - create_dunning_type("First Notice", fee=0.0, interest=0.0, is_default=1) - create_dunning_type("Second Notice", fee=10.0, interest=10.0, is_default=0) - unlink_payment_on_cancel_of_invoice() - - @classmethod - def tearDownClass(cls): - unlink_payment_on_cancel_of_invoice(0) - super().tearDownClass() - +class TestDunning(ERPNextTestSuite): def test_dunning_without_fees(self): dunning = create_dunning(overdue_days=20) diff --git a/erpnext/accounts/doctype/dunning_type/test_dunning_type.py b/erpnext/accounts/doctype/dunning_type/test_dunning_type.py index 5a95aa68ea9..4cf60c86600 100644 --- a/erpnext/accounts/doctype/dunning_type/test_dunning_type.py +++ b/erpnext/accounts/doctype/dunning_type/test_dunning_type.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestDunningType(IntegrationTestCase): +class TestDunningType(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/dunning_type/test_records.json b/erpnext/accounts/doctype/dunning_type/test_records.json deleted file mode 100644 index 7f28aab873c..00000000000 --- a/erpnext/accounts/doctype/dunning_type/test_records.json +++ /dev/null @@ -1,36 +0,0 @@ -[ - { - "doctype": "Dunning Type", - "dunning_type": "_Test First Notice", - "company": "_Test Company", - "is_default": 1, - "dunning_fee": 0.0, - "rate_of_interest": 0.0, - "dunning_letter_text": [ - { - "language": "en", - "body_text": "We have still not received payment for our invoice", - "closing_text": "We kindly request that you pay the outstanding amount immediately, including interest and late fees." - } - ], - "income_account": "Sales - _TC", - "cost_center": "_Test Cost Center - _TC" - }, - { - "doctype": "Dunning Type", - "dunning_type": "_Test Second Notice", - "company": "_Test Company", - "is_default": 0, - "dunning_fee": 10.0, - "rate_of_interest": 10.0, - "dunning_letter_text": [ - { - "language": "en", - "body_text": "We have still not received payment for our invoice", - "closing_text": "We kindly request that you pay the outstanding amount immediately, including interest and late fees." - } - ], - "income_account": "Sales - _TC", - "cost_center": "_Test Cost Center - _TC" - } -] diff --git a/erpnext/accounts/doctype/exchange_rate_revaluation/test_exchange_rate_revaluation.py b/erpnext/accounts/doctype/exchange_rate_revaluation/test_exchange_rate_revaluation.py index 96079284dd9..1310a8b482b 100644 --- a/erpnext/accounts/doctype/exchange_rate_revaluation/test_exchange_rate_revaluation.py +++ b/erpnext/accounts/doctype/exchange_rate_revaluation/test_exchange_rate_revaluation.py @@ -5,15 +5,15 @@ import frappe from frappe.query_builder import functions from frappe.query_builder.utils import DocType -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, flt, today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): +class TestExchangeRateRevaluation(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_usd_receivable_account() @@ -22,14 +22,13 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): self.clear_old_entries() self.set_system_and_company_settings() - def tearDown(self): - frappe.db.rollback() - def set_system_and_company_settings(self): # set number and currency precision system_settings = frappe.get_doc("System Settings") system_settings.float_precision = 2 system_settings.currency_precision = 2 + system_settings.language = "en" + system_settings.time_zone = "Asia/Kolkata" system_settings.save() # Using Exchange Gain/Loss account for unrealized as well. @@ -37,7 +36,7 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): company_doc.unrealized_exchange_gain_loss_account = company_doc.exchange_gain_loss_account company_doc.save() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, ) @@ -91,7 +90,7 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): )[0] self.assertEqual(acc_balance.balance, 8500.0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, ) @@ -164,7 +163,7 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): self.assertEqual(acc_balance.balance, 0.0) self.assertEqual(acc_balance.balance_in_account_currency, 0.0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, ) @@ -259,7 +258,7 @@ class TestExchangeRateRevaluation(AccountsTestMixin, IntegrationTestCase): self.assertEqual(flt(acc_balance.balance, precision), 0.0) self.assertEqual(flt(acc_balance.balance_in_account_currency, precision), 0.0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, ) diff --git a/erpnext/accounts/doctype/finance_book/test_finance_book.py b/erpnext/accounts/doctype/finance_book/test_finance_book.py index e2c156a1df5..e803eabf93a 100644 --- a/erpnext/accounts/doctype/finance_book/test_finance_book.py +++ b/erpnext/accounts/doctype/finance_book/test_finance_book.py @@ -3,12 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestFinanceBook(IntegrationTestCase): +class TestFinanceBook(ERPNextTestSuite): def test_finance_book(self): finance_book = create_finance_book() diff --git a/erpnext/accounts/doctype/financial_report_template/test_financial_report_engine.py b/erpnext/accounts/doctype/financial_report_template/test_financial_report_engine.py index dcfe884bdf3..a23c6bb6883 100644 --- a/erpnext/accounts/doctype/financial_report_template/test_financial_report_engine.py +++ b/erpnext/accounts/doctype/financial_report_template/test_financial_report_engine.py @@ -19,12 +19,6 @@ from erpnext.accounts.doctype.financial_report_template.test_financial_report_te from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry from erpnext.accounts.utils import get_currency_precision, get_fiscal_year -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - class TestDependencyResolver(FinancialReportTemplateTestCase): """Test cases for DependencyResolver class""" diff --git a/erpnext/accounts/doctype/financial_report_template/test_financial_report_template.py b/erpnext/accounts/doctype/financial_report_template/test_financial_report_template.py index ef5404bd478..9372c503d12 100644 --- a/erpnext/accounts/doctype/financial_report_template/test_financial_report_template.py +++ b/erpnext/accounts/doctype/financial_report_template/test_financial_report_template.py @@ -2,29 +2,16 @@ # For license information, please see license.txt import frappe -from frappe.tests import IntegrationTestCase -from frappe.tests.utils import make_test_records -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] +from erpnext.tests.utils import ERPNextTestSuite -class TestFinancialReportTemplate(IntegrationTestCase): - pass - - -class FinancialReportTemplateTestCase(IntegrationTestCase): +class FinancialReportTemplateTestCase(ERPNextTestSuite): """Utility class with common setup and helper methods for all test classes""" - @classmethod - def setUpClass(cls): + def setUp(self): """Set up test data""" - make_test_records("Company") - make_test_records("Fiscal Year") - cls.create_test_template() + self.create_test_template() @classmethod def create_test_template(cls): diff --git a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py index 22624e270aa..b6ce0696bdb 100644 --- a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py +++ b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py @@ -3,13 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import now_datetime -IGNORE_TEST_RECORD_DEPENDENCIES = ["Company"] +from erpnext.tests.utils import ERPNextTestSuite -class TestFiscalYear(IntegrationTestCase): +class TestFiscalYear(ERPNextTestSuite): def test_extra_year(self): if frappe.db.exists("Fiscal Year", "_Test Fiscal Year 2000"): frappe.delete_doc("Fiscal Year", "_Test Fiscal Year 2000") diff --git a/erpnext/accounts/doctype/gl_entry/test_gl_entry.py b/erpnext/accounts/doctype/gl_entry/test_gl_entry.py index 11269f005db..bd391b4b8f4 100644 --- a/erpnext/accounts/doctype/gl_entry/test_gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/test_gl_entry.py @@ -4,13 +4,13 @@ import unittest import frappe from frappe.model.naming import parse_naming_series -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.gl_entry.gl_entry import rename_gle_sle_docs from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestGLEntry(IntegrationTestCase): +class TestGLEntry(ERPNextTestSuite): def test_round_off_entry(self): frappe.db.set_value("Company", "_Test Company", "round_off_account", "_Test Write Off - _TC") frappe.db.set_value("Company", "_Test Company", "round_off_cost_center", "_Test Cost Center - _TC") diff --git a/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py b/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py index f34e2fd2434..00946e5fec1 100644 --- a/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py +++ b/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py @@ -3,16 +3,16 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, flt, nowdate from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry_against_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries +from erpnext.tests.utils import ERPNextTestSuite -class TestInvoiceDiscounting(IntegrationTestCase): +class TestInvoiceDiscounting(ERPNextTestSuite): def setUp(self): self.ar_credit = create_account( account_name="_Test Accounts Receivable Credit", diff --git a/erpnext/accounts/doctype/item_tax_template/test_item_tax_template.py b/erpnext/accounts/doctype/item_tax_template/test_item_tax_template.py index d5d8701fdc2..07032b79db2 100644 --- a/erpnext/accounts/doctype/item_tax_template/test_item_tax_template.py +++ b/erpnext/accounts/doctype/item_tax_template/test_item_tax_template.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestItemTaxTemplate(IntegrationTestCase): +class TestItemTaxTemplate(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/item_tax_template/test_records.json b/erpnext/accounts/doctype/item_tax_template/test_records.json deleted file mode 100644 index 4d9537d4b89..00000000000 --- a/erpnext/accounts/doctype/item_tax_template/test_records.json +++ /dev/null @@ -1,79 +0,0 @@ -[ - { - "doctype": "Item Tax Template", - "title": "_Test Account Excise Duty @ 10", - "company": "_Test Company", - "taxes": [ - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 10, - "tax_type": "_Test Account Excise Duty - _TC" - } - ] - }, - { - "doctype": "Item Tax Template", - "title": "_Test Account Excise Duty @ 12", - "company": "_Test Company", - "taxes": [ - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 12, - "tax_type": "_Test Account Excise Duty - _TC" - } - ] - }, - { - "doctype": "Item Tax Template", - "title": "_Test Account Excise Duty @ 15", - "company": "_Test Company", - "taxes": [ - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 15, - "tax_type": "_Test Account Excise Duty - _TC" - } - ] - }, - { - "doctype": "Item Tax Template", - "title": "_Test Account Excise Duty @ 20", - "company": "_Test Company", - "taxes": [ - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 20, - "tax_type": "_Test Account Excise Duty - _TC" - } - ] - }, - { - "doctype": "Item Tax Template", - "title": "_Test Item Tax Template 1", - "company": "_Test Company", - "taxes": [ - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 5, - "tax_type": "_Test Account Excise Duty - _TC" - }, - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 10, - "tax_type": "_Test Account Education Cess - _TC" - }, - { - "doctype": "Item Tax Template Detail", - "parentfield": "taxes", - "tax_rate": 15, - "tax_type": "_Test Account S&H Education Cess - _TC" - } - ] - } -] diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py index 1a048a237bf..53d6013e1e2 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -2,19 +2,20 @@ # License: GNU General Public License v3. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import flt, nowdate from erpnext.accounts.doctype.account.test_account import get_inventory_account from erpnext.accounts.doctype.journal_entry.journal_entry import StockAccountInvalidTransaction from erpnext.exceptions import InvalidAccountCurrency from erpnext.selling.doctype.customer.test_customer import make_customer, set_credit_limit +from erpnext.tests.utils import ERPNextTestSuite -class TestJournalEntry(IntegrationTestCase): - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) +class TestJournalEntry(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Journal Entry") + + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_journal_entry_with_against_jv(self): jv_invoice = frappe.copy_doc(self.globalTestRecords["Journal Entry"][2]) base_jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][0]) @@ -149,7 +150,6 @@ class TestJournalEntry(IntegrationTestCase): if account_bal == stock_bal: self.assertRaises(StockAccountInvalidTransaction, jv.save) - frappe.db.rollback() else: jv.submit() jv.cancel() diff --git a/erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py b/erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py index 95a287435ff..946f4a64a43 100644 --- a/erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py +++ b/erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestJournalEntryTemplate(IntegrationTestCase): +class TestJournalEntryTemplate(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/ledger_health/test_ledger_health.py b/erpnext/accounts/doctype/ledger_health/test_ledger_health.py index 0eec86ccc0f..84fd3925ded 100644 --- a/erpnext/accounts/doctype/ledger_health/test_ledger_health.py +++ b/erpnext/accounts/doctype/ledger_health/test_ledger_health.py @@ -3,23 +3,20 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.accounts.utils import run_ledger_health_checks +from erpnext.tests.utils import ERPNextTestSuite -class TestLedgerHealth(AccountsTestMixin, IntegrationTestCase): +class TestLedgerHealth(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.configure_monitoring_tool() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def configure_monitoring_tool(self): monitor_settings = frappe.get_doc("Ledger Health Monitor") monitor_settings.enable_health_monitor = True diff --git a/erpnext/accounts/doctype/ledger_health_monitor/test_ledger_health_monitor.py b/erpnext/accounts/doctype/ledger_health_monitor/test_ledger_health_monitor.py index bc2193f10ce..191a06510b9 100644 --- a/erpnext/accounts/doctype/ledger_health_monitor/test_ledger_health_monitor.py +++ b/erpnext/accounts/doctype/ledger_health_monitor/test_ledger_health_monitor.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestLedgerHealthMonitor(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestLedgerHealthMonitor(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/ledger_merge/test_ledger_merge.py b/erpnext/accounts/doctype/ledger_merge/test_ledger_merge.py index fd5001f97bc..28822dff52d 100644 --- a/erpnext/accounts/doctype/ledger_merge/test_ledger_merge.py +++ b/erpnext/accounts/doctype/ledger_merge/test_ledger_merge.py @@ -3,12 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.ledger_merge.ledger_merge import start_merge +from erpnext.tests.utils import ERPNextTestSuite -class TestLedgerMerge(IntegrationTestCase): +class TestLedgerMerge(ERPNextTestSuite): def test_merge_success(self): if not frappe.db.exists("Account", "Indirect Expenses - _TC"): acc = frappe.new_doc("Account") @@ -101,16 +101,3 @@ class TestLedgerMerge(IntegrationTestCase): self.assertFalse(frappe.db.exists("Account", "Indirect Test Income - _TC")) self.assertTrue(frappe.db.exists("Account", "Administrative Test Income - _TC")) - - def tearDown(self): - for entry in frappe.db.get_all("Ledger Merge"): - frappe.delete_doc("Ledger Merge", entry.name) - - test_accounts = [ - "Indirect Test Expenses - _TC", - "Administrative Test Expenses - _TC", - "Indirect Test Income - _TC", - "Administrative Test Income - _TC", - ] - for account in test_accounts: - frappe.delete_doc_if_exists("Account", account) diff --git a/erpnext/accounts/doctype/loyalty_point_entry/test_loyalty_point_entry.py b/erpnext/accounts/doctype/loyalty_point_entry/test_loyalty_point_entry.py index c085e6caf5e..090c905c013 100644 --- a/erpnext/accounts/doctype/loyalty_point_entry/test_loyalty_point_entry.py +++ b/erpnext/accounts/doctype/loyalty_point_entry/test_loyalty_point_entry.py @@ -3,31 +3,20 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today -from erpnext.accounts.doctype.loyalty_program.test_loyalty_program import create_records from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice +from erpnext.tests.utils import ERPNextTestSuite -class TestLoyaltyPointEntry(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestLoyaltyPointEntry(ERPNextTestSuite): + def setUp(self): # Create test records - create_records() - cls.loyalty_program_name = "Test Single Loyalty" - cls.customer_name = "Test Loyalty Customer" - customer = frappe.get_doc("Customer", cls.customer_name) - customer.db_set("loyalty_program", cls.loyalty_program_name) - - @classmethod - def tearDownClass(cls): - # Delete all Loyalty Point Entries - frappe.db.sql("DELETE FROM `tabLoyalty Point Entry` WHERE customer = %s", cls.customer_name) - frappe.db.sql("DELETE FROM `tabSales Invoice` WHERE customer = %s", cls.customer_name) - frappe.db.commit() - # cls.customer.delete() + self.loyalty_program_name = "Test Single Loyalty" + self.customer_name = "Test Loyalty Customer" + customer = frappe.get_doc("Customer", self.customer_name) + customer.loyalty_program = self.loyalty_program_name + customer.save() def create_test_invoice(self, redeem=None): if redeem: @@ -69,9 +58,10 @@ class TestLoyaltyPointEntry(IntegrationTestCase): self.assertEqual(entry.discretionary_reason, "Customer Appreciation") def test_redeem_loyalty_points(self): - self.create_test_invoice(redeem=10) + self.create_test_invoice() + self.create_test_invoice(redeem=7) doc = frappe.get_last_doc("Loyalty Point Entry") - self.assertEqual(doc.loyalty_points, -10) + self.assertEqual(doc.loyalty_points, -7) # Check balance balance = frappe.db.sql( @@ -83,4 +73,4 @@ class TestLoyaltyPointEntry(IntegrationTestCase): (self.customer_name,), )[0][0] - self.assertEqual(balance, 75) # 85 added, 10 redeemed + self.assertEqual(balance, 3) # 10 added, 7 redeemed diff --git a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py index 604e95df6b8..28731e4db51 100644 --- a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py +++ b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import cint, flt, getdate, today from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( @@ -11,15 +10,10 @@ from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( get_loyalty_program_details_with_points, ) from erpnext.accounts.party import get_dashboard_info +from erpnext.tests.utils import ERPNextTestSuite -class TestLoyaltyProgram(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - # create relevant item, customer, loyalty program, etc - create_records() - +class TestLoyaltyProgram(ERPNextTestSuite): def test_loyalty_points_earned_single_tier(self): frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty") # create a new sales invoice @@ -323,96 +317,3 @@ def create_sales_invoice_record(qty=1): ], } ) - - -def create_records(): - # create a new loyalty Account - if not frappe.db.exists("Account", "Loyalty - _TC"): - frappe.get_doc( - { - "doctype": "Account", - "account_name": "Loyalty", - "parent_account": "Direct Expenses - _TC", - "company": "_Test Company", - "is_group": 0, - "account_type": "Expense Account", - } - ).insert() - - # create a new loyalty program Single tier - if not frappe.db.exists("Loyalty Program", "Test Single Loyalty"): - frappe.get_doc( - { - "doctype": "Loyalty Program", - "loyalty_program_name": "Test Single Loyalty", - "auto_opt_in": 1, - "from_date": today(), - "loyalty_program_type": "Single Tier Program", - "conversion_factor": 1, - "expiry_duration": 10, - "company": "_Test Company", - "cost_center": "Main - _TC", - "expense_account": "Loyalty - _TC", - "collection_rules": [{"tier_name": "Bronce", "collection_factor": 1000, "min_spent": 0}], - } - ).insert() - - # create a new customer - if not frappe.db.exists("Customer", "Test Loyalty Customer"): - frappe.get_doc( - { - "customer_group": "_Test Customer Group", - "customer_name": "Test Loyalty Customer", - "customer_type": "Individual", - "doctype": "Customer", - "territory": "_Test Territory", - } - ).insert() - - # create a new loyalty program Multiple tier - if not frappe.db.exists("Loyalty Program", "Test Multiple Loyalty"): - frappe.get_doc( - { - "doctype": "Loyalty Program", - "loyalty_program_name": "Test Multiple Loyalty", - "auto_opt_in": 1, - "from_date": today(), - "loyalty_program_type": "Multiple Tier Program", - "conversion_factor": 1, - "expiry_duration": 10, - "company": "_Test Company", - "cost_center": "Main - _TC", - "expense_account": "Loyalty - _TC", - "collection_rules": [ - {"tier_name": "Bronze", "collection_factor": 1000, "min_spent": 0}, - {"tier_name": "Silver", "collection_factor": 1000, "min_spent": 10000}, - {"tier_name": "Gold", "collection_factor": 1000, "min_spent": 19000}, - ], - } - ).insert() - - # create an item - if not frappe.db.exists("Item", "Loyal Item"): - frappe.get_doc( - { - "doctype": "Item", - "item_code": "Loyal Item", - "item_name": "Loyal Item", - "item_group": "All Item Groups", - "company": "_Test Company", - "is_stock_item": 1, - "opening_stock": 100, - "valuation_rate": 10000, - } - ).insert() - - # create item price - if not frappe.db.exists("Item Price", {"price_list": "Standard Selling", "item_code": "Loyal Item"}): - frappe.get_doc( - { - "doctype": "Item Price", - "price_list": "Standard Selling", - "item_code": "Loyal Item", - "price_list_rate": 10000, - } - ).insert() diff --git a/erpnext/accounts/doctype/mode_of_payment/test_mode_of_payment.py b/erpnext/accounts/doctype/mode_of_payment/test_mode_of_payment.py index ee2a594f8f0..2f485f10f81 100644 --- a/erpnext/accounts/doctype/mode_of_payment/test_mode_of_payment.py +++ b/erpnext/accounts/doctype/mode_of_payment/test_mode_of_payment.py @@ -3,10 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestModeofPayment(IntegrationTestCase): +class TestModeofPayment(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/monthly_distribution/test_monthly_distribution.py b/erpnext/accounts/doctype/monthly_distribution/test_monthly_distribution.py index 06c153940a8..30d35527136 100644 --- a/erpnext/accounts/doctype/monthly_distribution/test_monthly_distribution.py +++ b/erpnext/accounts/doctype/monthly_distribution/test_monthly_distribution.py @@ -2,9 +2,8 @@ # See license.txt import unittest -import frappe -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestMonthlyDistribution(IntegrationTestCase): +class TestMonthlyDistribution(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py index 730d5db8ae6..3d57c781983 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( create_dimension, @@ -11,17 +10,14 @@ from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension imp from erpnext.accounts.doctype.opening_invoice_creation_tool.opening_invoice_creation_tool import ( get_temporary_opening_account, ) - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Customer", "Supplier", "Accounting Dimension"] +from erpnext.tests.utils import ERPNextTestSuite -class TestOpeningInvoiceCreationTool(IntegrationTestCase): - @classmethod - def setUpClass(cls): +class TestOpeningInvoiceCreationTool(ERPNextTestSuite): + def setUp(self): if not frappe.db.exists("Company", "_Test Opening Invoice Company"): make_company() create_dimension() - return super().setUpClass() def make_invoices( self, @@ -149,9 +145,6 @@ class TestOpeningInvoiceCreationTool(IntegrationTestCase): } self.check_expected_values(invoices, expected_value, invoice_type="Sales") - def tearDown(self): - disable_dimension() - def get_opening_invoice_creation_dict(**args): party = "Customer" if args.get("invoice_type", "Sales") == "Sales" else "Supplier" diff --git a/erpnext/accounts/doctype/party_link/test_party_link.py b/erpnext/accounts/doctype/party_link/test_party_link.py index 1c93c65e3c3..c1f59a2209a 100644 --- a/erpnext/accounts/doctype/party_link/test_party_link.py +++ b/erpnext/accounts/doctype/party_link/test_party_link.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestPartyLink(IntegrationTestCase): +class TestPartyLink(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index f6c240c0714..12f5276fbfb 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -4,7 +4,6 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, flt, nowdate from erpnext.accounts.doctype.account.test_account import create_account @@ -24,14 +23,10 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import ( ) from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.setup.doctype.employee.test_employee import make_employee - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Currency Exchange"] +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentEntry(IntegrationTestCase): - def tearDown(self): - frappe.db.rollback() - +class TestPaymentEntry(ERPNextTestSuite): def get_journals_for(self, voucher_type: str, voucher_no: str) -> list: journals = [] if voucher_type and voucher_no: @@ -427,7 +422,7 @@ class TestPaymentEntry(IntegrationTestCase): self.assertEqual(si.payment_schedule[0].outstanding, 0) self.assertEqual(si.payment_schedule[0].discounted_amount, 50) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "allow_multi_currency_invoices_against_single_party_account": 1, @@ -645,6 +640,7 @@ class TestPaymentEntry(IntegrationTestCase): def test_payment_entry_retrieves_last_exchange_rate(self): from erpnext.setup.doctype.currency_exchange.test_currency_exchange import save_new_records + self.load_test_records("Currency Exchange") save_new_records(self.globalTestRecords["Currency Exchange"]) pe = frappe.new_doc("Payment Entry") @@ -982,6 +978,7 @@ class TestPaymentEntry(IntegrationTestCase): def test_gl_of_multi_currency_payment_transaction(self): from erpnext.setup.doctype.currency_exchange.test_currency_exchange import save_new_records + self.load_test_records("Currency Exchange") save_new_records(self.globalTestRecords["Currency Exchange"]) paid_from = create_account( parent_account="Current Liabilities - _TC", @@ -1158,7 +1155,7 @@ class TestPaymentEntry(IntegrationTestCase): } self.assertDictEqual(ref_details, expected_response) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "unlink_payment_on_cancellation_of_invoice": 1, @@ -1253,7 +1250,7 @@ class TestPaymentEntry(IntegrationTestCase): si3.cancel() si3.delete() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "unlink_payment_on_cancellation_of_invoice": 1, @@ -1949,7 +1946,7 @@ class TestPaymentEntry(IntegrationTestCase): # 'Is Opening' should always be 'No' for normal advance payments self.assertEqual(gl_with_opening_set, []) - @IntegrationTestCase.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) def test_delete_linked_exchange_gain_loss_journal(self): from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import ( diff --git a/erpnext/accounts/doctype/payment_gateway_account/test_payment_gateway_account.py b/erpnext/accounts/doctype/payment_gateway_account/test_payment_gateway_account.py index 030844e7148..ad4373edd75 100644 --- a/erpnext/accounts/doctype/payment_gateway_account/test_payment_gateway_account.py +++ b/erpnext/accounts/doctype/payment_gateway_account/test_payment_gateway_account.py @@ -2,10 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase - -IGNORE_TEST_RECORD_DEPENDENCIES = ["Payment Gateway"] +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentGatewayAccount(IntegrationTestCase): +class TestPaymentGatewayAccount(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py b/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py index 1de103764a4..c2528040e98 100644 --- a/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py +++ b/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py @@ -3,7 +3,6 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -11,9 +10,10 @@ from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_pay from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.stock.doctype.item.test_item import create_item +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentLedgerEntry(IntegrationTestCase): +class TestPaymentLedgerEntry(ERPNextTestSuite): def setUp(self): self.ple = qb.DocType("Payment Ledger Entry") self.create_company() @@ -21,9 +21,6 @@ class TestPaymentLedgerEntry(IntegrationTestCase): self.create_customer() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_company(self): company_name = "_Test Payment Ledger" company = None @@ -445,7 +442,7 @@ class TestPaymentLedgerEntry(IntegrationTestCase): self.assertEqual(pl_entries_for_crnote[0], expected_values[0]) self.assertEqual(pl_entries_for_crnote[1], expected_values[1]) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1, "delete_linked_ledger_entries": 1}, ) @@ -474,7 +471,7 @@ class TestPaymentLedgerEntry(IntegrationTestCase): si.delete() self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, si.doctype, si.name) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1, "delete_linked_ledger_entries": 1}, ) @@ -507,7 +504,7 @@ class TestPaymentLedgerEntry(IntegrationTestCase): si.delete() self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, si.doctype, si.name) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "unlink_payment_on_cancellation_of_invoice": 1, diff --git a/erpnext/accounts/doctype/payment_order/test_payment_order.py b/erpnext/accounts/doctype/payment_order/test_payment_order.py index f12491fdf15..b11500cfd20 100644 --- a/erpnext/accounts/doctype/payment_order/test_payment_order.py +++ b/erpnext/accounts/doctype/payment_order/test_payment_order.py @@ -3,7 +3,6 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import getdate from erpnext.accounts.doctype.bank_transaction.test_bank_transaction import ( @@ -15,9 +14,10 @@ from erpnext.accounts.doctype.payment_entry.payment_entry import ( make_payment_order, ) from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentOrder(IntegrationTestCase): +class TestPaymentOrder(ERPNextTestSuite): def setUp(self): # generate and use a uniq hash identifier for 'Bank Account' and it's linked GL 'Account' to avoid validation error uniq_identifier = frappe.generate_hash(length=10) @@ -26,9 +26,6 @@ class TestPaymentOrder(IntegrationTestCase): gl_account=self.gl_account, bank_account_name="Checking Account " + uniq_identifier ) - def tearDown(self): - frappe.db.rollback() - def test_payment_order_creation_against_payment_entry(self): purchase_invoice = make_purchase_invoice() payment_entry = get_payment_entry( diff --git a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py index 3682e7c63a9..1bbf228d73a 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py @@ -4,7 +4,6 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_years, flt, getdate, nowdate, today from frappe.utils.data import getdate as convert_to_date @@ -17,11 +16,10 @@ from erpnext.accounts.party import get_party_account from erpnext.accounts.utils import get_fiscal_year from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.stock.doctype.item.test_item import create_item - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"] +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentReconciliation(IntegrationTestCase): +class TestPaymentReconciliation(ERPNextTestSuite): def setUp(self): self.create_company() self.create_item() @@ -30,9 +28,6 @@ class TestPaymentReconciliation(IntegrationTestCase): self.create_cost_center() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_company(self): company = None if frappe.db.exists("Company", "_Test Payment Reconciliation"): @@ -1235,7 +1230,7 @@ class TestPaymentReconciliation(IntegrationTestCase): payment_vouchers = [x.get("reference_name") for x in pr.get("payments")] self.assertCountEqual(payment_vouchers, [je2.name, pe2.name]) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "allow_multi_currency_invoices_against_single_party_account": 1, diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py index 41375d9d9af..453a52518a7 100644 --- a/erpnext/accounts/doctype/payment_request/test_payment_request.py +++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py @@ -7,7 +7,6 @@ import unittest from unittest.mock import patch import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, nowdate from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -18,8 +17,7 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sal from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.setup.utils import get_exchange_rate - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Currency Exchange", "Journal Entry", "Contact", "Address"] +from erpnext.tests.utils import ERPNextTestSuite PAYMENT_URL = "https://example.com/payment" @@ -64,7 +62,7 @@ payment_method = [ ] -class TestPaymentRequest(IntegrationTestCase): +class TestPaymentRequest(ERPNextTestSuite): def setUp(self): for payment_gateway in payment_gateways: if not frappe.db.get_value("Payment Gateway", payment_gateway["gateway"], "name"): @@ -101,9 +99,6 @@ class TestPaymentRequest(IntegrationTestCase): self._get_payment_gateway_controller = _get_payment_gateway_controller.start() self.addCleanup(_get_payment_gateway_controller.stop) - def tearDown(self): - frappe.db.rollback() - def test_payment_request_linkings(self): so_inr = make_sales_order(currency="INR", do_not_save=True) so_inr.disable_rounded_total = 1 @@ -504,7 +499,7 @@ class TestPaymentRequest(IntegrationTestCase): return_doc=1, ) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} ) def test_multiple_payment_if_partially_paid_for_multi_currency(self): @@ -622,7 +617,7 @@ class TestPaymentRequest(IntegrationTestCase): self.assertEqual(pr.outstanding_amount, 0) self.assertEqual(pr.grand_total, 20000) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} ) def test_single_payment_with_payment_term_for_multi_currency(self): diff --git a/erpnext/accounts/doctype/payment_term/test_payment_term.py b/erpnext/accounts/doctype/payment_term/test_payment_term.py index 08f51cfb4e9..62129971c16 100644 --- a/erpnext/accounts/doctype/payment_term/test_payment_term.py +++ b/erpnext/accounts/doctype/payment_term/test_payment_term.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentTerm(IntegrationTestCase): +class TestPaymentTerm(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/payment_term/test_records.json b/erpnext/accounts/doctype/payment_term/test_records.json deleted file mode 100644 index ef6e0693b3c..00000000000 --- a/erpnext/accounts/doctype/payment_term/test_records.json +++ /dev/null @@ -1,34 +0,0 @@ -[ - { - "doctype":"Payment Term", - "due_date_based_on":"Day(s) after invoice date", - "payment_term_name":"_Test N30", - "description":"_Test Net 30 Days", - "invoice_portion":50, - "credit_days":30 - }, - { - "doctype":"Payment Term", - "due_date_based_on":"Day(s) after invoice date", - "payment_term_name":"_Test COD", - "description":"_Test Cash on Delivery", - "invoice_portion":50, - "credit_days":0 - }, - { - "doctype":"Payment Term", - "due_date_based_on":"Month(s) after the end of the invoice month", - "payment_term_name":"_Test EONM", - "description":"_Test End of Next Month", - "invoice_portion":100, - "credit_months":1 - }, - { - "doctype":"Payment Term", - "due_date_based_on":"Day(s) after invoice date", - "payment_term_name":"_Test N30 1", - "description":"_Test Net 30 Days", - "invoice_portion":100, - "credit_days":30 - } -] \ No newline at end of file diff --git a/erpnext/accounts/doctype/payment_terms_template/test_payment_terms_template.py b/erpnext/accounts/doctype/payment_terms_template/test_payment_terms_template.py index fb0020f78ac..36c21f7ee78 100644 --- a/erpnext/accounts/doctype/payment_terms_template/test_payment_terms_template.py +++ b/erpnext/accounts/doctype/payment_terms_template/test_payment_terms_template.py @@ -3,13 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentTermsTemplate(IntegrationTestCase): - def tearDown(self): - frappe.delete_doc("Payment Terms Template", "_Test Payment Terms Template For Test", force=1) - +class TestPaymentTermsTemplate(ERPNextTestSuite): def test_create_template(self): template = frappe.get_doc( { diff --git a/erpnext/accounts/doctype/payment_terms_template/test_records.json b/erpnext/accounts/doctype/payment_terms_template/test_records.json deleted file mode 100644 index fea0b35c112..00000000000 --- a/erpnext/accounts/doctype/payment_terms_template/test_records.json +++ /dev/null @@ -1,60 +0,0 @@ -[ - { - "doctype":"Payment Terms Template", - "terms":[ - { - "doctype":"Payment Terms Template Detail", - "due_date_based_on":"Day(s) after invoice date", - "idx":1, - "description":"Cash on Delivery", - "invoice_portion":50, - "credit_days":0, - "credit_months":0, - "payment_term":"_Test COD" - }, - { - "doctype":"Payment Terms Template Detail", - "due_date_based_on":"Day(s) after invoice date", - "idx":2, - "description":"Net 30 Days ", - "invoice_portion":50, - "credit_days":30, - "credit_months":0, - "payment_term":"_Test N30" - } - ], - "template_name":"_Test Payment Term Template" - }, - { - "doctype":"Payment Terms Template", - "terms":[ - { - "doctype":"Payment Terms Template Detail", - "due_date_based_on":"Month(s) after the end of the invoice month", - "idx":1, - "description":"_Test End of Next Months", - "invoice_portion":100, - "credit_days":0, - "credit_months":1, - "payment_term":"_Test EONM" - } - ], - "template_name":"_Test Payment Term Template 1" - }, - { - "doctype":"Payment Terms Template", - "terms":[ - { - "doctype":"Payment Terms Template Detail", - "due_date_based_on":"Day(s) after invoice date", - "idx":1, - "description":"_Test Net Within 30 days", - "invoice_portion":100, - "credit_days":30, - "credit_months":0, - "payment_term":"_Test N30 1" - } - ], - "template_name":"_Test Payment Term Template 3" - } -] \ No newline at end of file diff --git a/erpnext/accounts/doctype/pegged_currencies/test_pegged_currencies.py b/erpnext/accounts/doctype/pegged_currencies/test_pegged_currencies.py index 32bb3f34fd5..e695b11bcb5 100644 --- a/erpnext/accounts/doctype/pegged_currencies/test_pegged_currencies.py +++ b/erpnext/accounts/doctype/pegged_currencies/test_pegged_currencies.py @@ -2,28 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase, UnitTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class UnitTestPeggedCurrencies(UnitTestCase): - """ - Unit tests for PeggedCurrencies. - Use this class for testing individual functions and methods. - """ - - pass - - -class IntegrationTestPeggedCurrencies(IntegrationTestCase): - """ - Integration tests for PeggedCurrencies. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py index e9bc137fcd4..1fcff98a467 100644 --- a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py +++ b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py @@ -3,16 +3,16 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.doctype.finance_book.test_finance_book import create_finance_book from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.utils import get_fiscal_year +from erpnext.tests.utils import ERPNextTestSuite -class TestPeriodClosingVoucher(IntegrationTestCase): +class TestPeriodClosingVoucher(ERPNextTestSuite): def setUp(self): super().setUp() frappe.db.set_single_value("Accounts Settings", "use_legacy_controller_for_pcv", 1) @@ -391,6 +391,3 @@ def create_cost_center(cc_name): ) costcenter.insert(ignore_if_duplicate=True) return costcenter.name - - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Customer", "Cost Center"] diff --git a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py index 148a5a83030..af5f73a39ec 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py +++ b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( create_dimension, @@ -22,26 +21,14 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle get_batch_from_bundle, ) from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSClosingEntry(IntegrationTestCase): - @classmethod - def setUpClass(cls): - frappe.db.sql("delete from `tabPOS Opening Entry`") - cls.enterClassContext(cls.change_settings("POS Settings", {"invoice_type": "POS Invoice"})) - - @classmethod - def tearDownClass(cls): - frappe.db.sql("delete from `tabPOS Opening Entry`") - +class TestPOSClosingEntry(ERPNextTestSuite): def setUp(self): - # Make stock available for POS Sales - frappe.db.sql("delete from `tabPOS Opening Entry`") + init_user_and_profile() make_stock_entry(target="_Test Warehouse - _TC", qty=2, basic_rate=100) - - def tearDown(self): - frappe.set_user("Administrator") - frappe.db.sql("delete from `tabPOS Profile`") + frappe.db.set_single_value("POS Settings", "invoice_type", "POS Invoice") def test_pos_closing_entry(self): test_user, pos_profile = init_user_and_profile() @@ -58,6 +45,7 @@ class TestPOSClosingEntry(IntegrationTestCase): pos_inv2.submit() pcv_doc = make_closing_entry_from_opening(opening_entry) + pcv_doc.flags.in_test = True payment = pcv_doc.payment_reconciliation[0] self.assertEqual(payment.mode_of_payment, "Cash") @@ -66,6 +54,7 @@ class TestPOSClosingEntry(IntegrationTestCase): if d.mode_of_payment == "Cash": d.closing_amount = 6700 + pcv_doc.flags.in_test = True pcv_doc.submit() self.assertEqual(pcv_doc.total_quantity, 2) @@ -84,6 +73,7 @@ class TestPOSClosingEntry(IntegrationTestCase): pos_inv.submit() pcv_doc = make_closing_entry_from_opening(opening_entry) + pcv_doc.flags.in_test = True pcv_doc.submit() self.assertTrue(pcv_doc.name) @@ -116,6 +106,7 @@ class TestPOSClosingEntry(IntegrationTestCase): pos_return.submit() pcv_doc = make_closing_entry_from_opening(opening_entry) + pcv_doc.flags.in_test = True pcv_doc.submit() opening_entry = create_opening_entry(pos_profile, test_user.name) @@ -145,6 +136,7 @@ class TestPOSClosingEntry(IntegrationTestCase): if d.mode_of_payment == "Cash": d.closing_amount = 6700 + pcv_doc.flags.in_test = True pcv_doc.submit() pos_inv1.load_from_db() @@ -198,6 +190,7 @@ class TestPOSClosingEntry(IntegrationTestCase): pcv_doc = make_closing_entry_from_opening(opening_entry) # will assert coz the new mandatory accounting dimension bank is not set in POS Profile + pcv_doc.flags.in_test = True self.assertRaises(frappe.ValidationError, pcv_doc.submit) accounting_dimension_department = frappe.get_doc( @@ -265,6 +258,7 @@ class TestPOSClosingEntry(IntegrationTestCase): self.assertEqual(batch_qty_with_pos, 0.0) pcv_doc = make_closing_entry_from_opening(opening_entry) + pcv_doc.flags.in_test = True pcv_doc.submit() piv_merge = frappe.db.get_value("POS Invoice Merge Log", {"pos_closing_entry": pcv_doc.name}, "name") @@ -288,6 +282,7 @@ class TestPOSClosingEntry(IntegrationTestCase): frappe.flags.print_message = True pcv_doc.reload() + pcv_doc.flags.in_test = True pcv_doc.cancel() batch_qty_with_pos = get_batch_qty(batch_no, "_Test Warehouse - _TC", item_code) @@ -302,7 +297,7 @@ class TestPOSClosingEntry(IntegrationTestCase): batch_qty_with_pos = get_batch_qty(batch_no, "_Test Warehouse - _TC", item_code) self.assertEqual(batch_qty_with_pos, 10.0) - @IntegrationTestCase.change_settings("POS Settings", {"invoice_type": "Sales Invoice"}) + @ERPNextTestSuite.change_settings("POS Settings", {"invoice_type": "Sales Invoice"}) def test_closing_entries_with_sales_invoice(self): test_user, pos_profile = init_user_and_profile() opening_entry = create_opening_entry(pos_profile, test_user.name) @@ -330,6 +325,7 @@ class TestPOSClosingEntry(IntegrationTestCase): if d.mode_of_payment == "Cash": d.closing_amount = 1500 + pcv_doc.flags.in_test = True pcv_doc.submit() self.assertEqual(pcv_doc.total_quantity, 15) @@ -473,7 +469,7 @@ def init_user_and_profile(**args): user = "test@example.com" test_user = frappe.get_doc("User", user) - roles = ("Accounts Manager", "Accounts User", "Sales Manager") + roles = ("Accounts Manager", "Accounts User", "Sales Manager", "Stock User", "Item Manager") test_user.add_roles(*roles) frappe.set_user(user) diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py index 1a94e1c9990..8cf4d0cb90f 100644 --- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py @@ -5,7 +5,6 @@ import unittest import frappe from frappe import _ -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.mode_of_payment.test_mode_of_payment import ( set_default_account_for_mode_of_payment, @@ -22,37 +21,34 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle make_serial_batch_bundle, ) from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSInvoice(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0)) - cls.enterClassContext(cls.change_settings("POS Settings", invoice_type="POS Invoice")) - make_stock_entry(target="_Test Warehouse - _TC", item_code="_Test Item", qty=800, basic_rate=100) - frappe.db.sql("delete from `tabTax Rule`") - +class POSInvoiceTestMixin(ERPNextTestSuite): + def setUp(self): from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile - from erpnext.accounts.doctype.pos_opening_entry.test_pos_opening_entry import create_opening_entry - cls.test_user, cls.pos_profile = init_user_and_profile() - cls.opening_entry = create_opening_entry(cls.pos_profile, cls.test_user.name) - mode_of_payment = frappe.get_doc("Mode of Payment", "Bank Draft") - set_default_account_for_mode_of_payment(mode_of_payment, "_Test Company", "_Test Bank - _TC") + self.load_test_records("Stock Entry") + self.test_user, self.pos_profile = init_user_and_profile() - @classmethod - def tearDownClass(cls): - frappe.db.sql("delete from `tabPOS Invoice`") - opening_entry_doc = frappe.get_doc("POS Opening Entry", cls.opening_entry.name) - opening_entry_doc.cancel() - - def tearDown(self): if frappe.session.user != "Administrator": frappe.set_user("Administrator") - if frappe.db.get_single_value("Selling Settings", "validate_selling_price"): - frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) + frappe.db.set_single_value("POS Settings", "invoice_type", "POS Invoice") + make_stock_entry(target="_Test Warehouse - _TC", item_code="_Test Item", qty=800, basic_rate=100) + frappe.db.sql("delete from `tabTax Rule`") + + mode_of_payment = frappe.get_doc("Mode of Payment", "Bank Draft") + set_default_account_for_mode_of_payment(mode_of_payment, "_Test Company", "_Test Bank - _TC") + + +class TestPOSInvoice(POSInvoiceTestMixin): + def setUp(self): + super().setUp() + from erpnext.accounts.doctype.pos_opening_entry.test_pos_opening_entry import create_opening_entry + + self.opening_entry = create_opening_entry(self.pos_profile, self.test_user.name) def test_timestamp_change(self): w = create_pos_invoice(do_not_save=1) @@ -642,9 +638,7 @@ class TestPOSInvoice(IntegrationTestCase): from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( get_loyalty_program_details_with_points, ) - from erpnext.accounts.doctype.loyalty_program.test_loyalty_program import create_records - create_records() frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty") before_lp_details = get_loyalty_program_details_with_points( "Test Loyalty Customer", company="_Test Company", loyalty_program="Test Single Loyalty" @@ -681,6 +675,7 @@ class TestPOSInvoice(IntegrationTestCase): get_loyalty_program_details_with_points, ) + frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty") # add 10 loyalty points pos_inv = create_pos_invoice(customer="Test Loyalty Customer", rate=10000, do_not_save=1) pos_inv.append( @@ -710,134 +705,6 @@ class TestPOSInvoice(IntegrationTestCase): ) self.assertEqual(after_redeem_lp_details.loyalty_points, 9) - def test_merging_into_sales_invoice_with_discount(self): - from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( - init_user_and_profile, - ) - from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( - consolidate_pos_invoices, - ) - - frappe.db.sql("delete from `tabPOS Invoice`") - test_user, pos_profile = init_user_and_profile() - pos_inv = create_pos_invoice(rate=300, additional_discount_percentage=10, do_not_submit=1) - pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 270}) - pos_inv.save() - pos_inv.submit() - - pos_inv2 = create_pos_invoice(rate=3200, do_not_submit=1) - pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 3200}) - pos_inv2.save() - pos_inv2.submit() - - consolidate_pos_invoices() - - pos_inv.load_from_db() - rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total") - self.assertEqual(rounded_total, 3470) - - def test_merging_into_sales_invoice_with_discount_and_inclusive_tax(self): - from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( - init_user_and_profile, - ) - from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( - consolidate_pos_invoices, - ) - - frappe.db.sql("delete from `tabPOS Invoice`") - test_user, pos_profile = init_user_and_profile() - pos_inv = create_pos_invoice(rate=300, do_not_submit=1) - pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 300}) - pos_inv.append( - "taxes", - { - "charge_type": "On Net Total", - "account_head": "_Test Account Service Tax - _TC", - "cost_center": "_Test Cost Center - _TC", - "description": "Service Tax", - "rate": 14, - "included_in_print_rate": 1, - }, - ) - pos_inv.save() - pos_inv.submit() - - pos_inv2 = create_pos_invoice(rate=300, qty=2, do_not_submit=1) - pos_inv2.additional_discount_percentage = 10 - pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 540}) - pos_inv2.append( - "taxes", - { - "charge_type": "On Net Total", - "account_head": "_Test Account Service Tax - _TC", - "cost_center": "_Test Cost Center - _TC", - "description": "Service Tax", - "rate": 14, - "included_in_print_rate": 1, - }, - ) - pos_inv2.save() - pos_inv2.submit() - - consolidate_pos_invoices() - - pos_inv.load_from_db() - rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total") - self.assertEqual(rounded_total, 840) - - def test_merging_with_validate_selling_price(self): - from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( - init_user_and_profile, - ) - from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( - consolidate_pos_invoices, - ) - - if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"): - frappe.db.set_single_value("Selling Settings", "validate_selling_price", 1) - - item = "Test Selling Price Validation" - make_item(item, {"is_stock_item": 1}) - make_purchase_receipt(item_code=item, warehouse="_Test Warehouse - _TC", qty=1, rate=300) - frappe.db.sql("delete from `tabPOS Invoice`") - test_user, pos_profile = init_user_and_profile() - pos_inv = create_pos_invoice(item=item, rate=300, do_not_submit=1) - pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 300}) - pos_inv.append( - "taxes", - { - "charge_type": "On Net Total", - "account_head": "_Test Account Service Tax - _TC", - "cost_center": "_Test Cost Center - _TC", - "description": "Service Tax", - "rate": 14, - "included_in_print_rate": 1, - }, - ) - self.assertRaises(frappe.ValidationError, pos_inv.submit) - - pos_inv2 = create_pos_invoice(item=item, rate=400, do_not_submit=1) - pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 400}) - pos_inv2.append( - "taxes", - { - "charge_type": "On Net Total", - "account_head": "_Test Account Service Tax - _TC", - "cost_center": "_Test Cost Center - _TC", - "description": "Service Tax", - "rate": 14, - "included_in_print_rate": 1, - }, - ) - pos_inv2.save() - pos_inv2.submit() - - consolidate_pos_invoices() - - pos_inv2.load_from_db() - rounded_total = frappe.db.get_value("Sales Invoice", pos_inv2.consolidated_invoice, "rounded_total") - self.assertEqual(rounded_total, 400) - def test_pos_batch_reservation(self): from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle import ( get_auto_batch_nos, @@ -1004,40 +871,39 @@ class TestPOSInvoice(IntegrationTestCase): def test_ignore_pricing_rule(self): from erpnext.accounts.doctype.pricing_rule.test_pricing_rule import make_pricing_rule - item_price = frappe.get_doc( - { - "doctype": "Item Price", - "item_code": "_Test Item", - "price_list": "_Test Price List", - "price_list_rate": "450", - } - ) - item_price.insert() + if not frappe.db.exists( + "Item Price", + {"item_code": "_Test Item", "price_list": "_Test Price List", "price_list_rate": "450"}, + ): + item_price = frappe.get_doc( + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Price List", + "price_list_rate": "450", + } + ) + item_price.insert() + pr = make_pricing_rule(selling=1, priority=5, discount_percentage=10) pr.save() - try: - pos_inv = create_pos_invoice(qty=1, do_not_submit=1) - pos_inv.items[0].rate = 300 - pos_inv.save() - self.assertEqual(pos_inv.items[0].discount_percentage, 10) - # rate shouldn't change - self.assertEqual(pos_inv.items[0].rate, 405) + pos_inv = create_pos_invoice(qty=1, do_not_submit=1) + pos_inv.items[0].rate = 300 + pos_inv.save() + self.assertEqual(pos_inv.items[0].discount_percentage, 10) + # rate shouldn't change + self.assertEqual(pos_inv.items[0].rate, 405) - pos_inv.ignore_pricing_rule = 1 - pos_inv.save() - self.assertEqual(pos_inv.ignore_pricing_rule, 1) - # rate should reset since pricing rules are ignored - self.assertEqual(pos_inv.items[0].rate, 450) + pos_inv.ignore_pricing_rule = 1 + pos_inv.save() + self.assertEqual(pos_inv.ignore_pricing_rule, 1) + # rate should reset since pricing rules are ignored + self.assertEqual(pos_inv.items[0].rate, 450) - pos_inv.items[0].rate = 300 - pos_inv.save() - self.assertEqual(pos_inv.items[0].rate, 300) - - finally: - item_price.delete() - pos_inv.delete() - pr.delete() + pos_inv.items[0].rate = 300 + pos_inv.save() + self.assertEqual(pos_inv.items[0].rate, 300) def test_delivered_serial_no_case(self): from erpnext.accounts.doctype.pos_invoice_merge_log.test_pos_invoice_merge_log import ( @@ -1046,32 +912,26 @@ class TestPOSInvoice(IntegrationTestCase): from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item - frappe.db.savepoint("before_test_delivered_serial_no_case") - try: - se = make_serialized_item(self) - serial_no = get_serial_nos_from_bundle(se.get("items")[0].serial_and_batch_bundle)[0] + se = make_serialized_item(self) + serial_no = get_serial_nos_from_bundle(se.get("items")[0].serial_and_batch_bundle)[0] - dn = create_delivery_note(item_code="_Test Serialized Item With Series", serial_no=[serial_no]) - delivered_serial_no = get_serial_nos_from_bundle(dn.get("items")[0].serial_and_batch_bundle)[0] + dn = create_delivery_note(item_code="_Test Serialized Item With Series", serial_no=[serial_no]) + delivered_serial_no = get_serial_nos_from_bundle(dn.get("items")[0].serial_and_batch_bundle)[0] - self.assertEqual(serial_no, delivered_serial_no) + self.assertEqual(serial_no, delivered_serial_no) - init_user_and_profile() + init_user_and_profile() - pos_inv = create_pos_invoice( - item_code="_Test Serialized Item With Series", - serial_no=[serial_no], - qty=1, - rate=100, - do_not_submit=True, - ignore_sabb_validation=True, - ) + pos_inv = create_pos_invoice( + item_code="_Test Serialized Item With Series", + serial_no=[serial_no], + qty=1, + rate=100, + do_not_submit=True, + ignore_sabb_validation=True, + ) - self.assertRaises(frappe.ValidationError, pos_inv.submit) - - finally: - frappe.db.rollback(save_point="before_test_delivered_serial_no_case") - frappe.set_user("Administrator") + self.assertRaises(frappe.ValidationError, pos_inv.submit) def test_bundle_stock_availability_validation(self): from erpnext.accounts.doctype.pos_invoice.pos_invoice import ProductBundleStockValidationError diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice_merge.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice_merge.py new file mode 100644 index 00000000000..5c490d303be --- /dev/null +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice_merge.py @@ -0,0 +1,164 @@ +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt + +import frappe + +from erpnext.accounts.doctype.pos_invoice.test_pos_invoice import POSInvoiceTestMixin, create_pos_invoice +from erpnext.stock.doctype.item.test_item import make_item +from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite + + +class TestPOSInvoiceMerging(POSInvoiceTestMixin): + def clear_pos_data(self): + frappe.db.sql("delete from `tabPOS Opening Entry`;") + frappe.db.sql("delete from `tabPOS Closing Entry`;") + frappe.db.sql("delete from `tabPOS Invoice`;") + + def setUp(self): + self.clear_pos_data() + super().setUp() + + from erpnext.accounts.doctype.pos_opening_entry.test_pos_opening_entry import create_opening_entry + + self.opening_entry = create_opening_entry(self.pos_profile, self.test_user.name) + + def test_merging_into_sales_invoice_with_discount(self): + from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import ( + make_closing_entry_from_opening, + ) + from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( + init_user_and_profile, + ) + from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( + consolidate_pos_invoices, + ) + + frappe.db.sql("delete from `tabPOS Invoice`") + test_user, pos_profile = init_user_and_profile() + pos_inv = create_pos_invoice(rate=300, additional_discount_percentage=10, do_not_submit=1) + pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 270}) + pos_inv.save() + pos_inv.submit() + + pos_inv2 = create_pos_invoice(rate=3200, do_not_submit=1) + pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 3200}) + pos_inv2.save() + pos_inv2.submit() + + closing_entry = make_closing_entry_from_opening(self.opening_entry) + consolidate_pos_invoices(closing_entry=closing_entry) # does DB commit + + pos_inv.load_from_db() + rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total") + self.assertEqual(rounded_total, 3470) + + def test_merging_into_sales_invoice_with_discount_and_inclusive_tax(self): + from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import ( + make_closing_entry_from_opening, + ) + from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( + init_user_and_profile, + ) + from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( + consolidate_pos_invoices, + ) + + frappe.db.sql("delete from `tabPOS Invoice`") + test_user, pos_profile = init_user_and_profile() + pos_inv = create_pos_invoice(rate=300, do_not_submit=1) + pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 300}) + pos_inv.append( + "taxes", + { + "charge_type": "On Net Total", + "account_head": "_Test Account Service Tax - _TC", + "cost_center": "_Test Cost Center - _TC", + "description": "Service Tax", + "rate": 14, + "included_in_print_rate": 1, + }, + ) + pos_inv.save() + pos_inv.submit() + + pos_inv2 = create_pos_invoice(rate=300, qty=2, do_not_submit=1) + pos_inv2.additional_discount_percentage = 10 + pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 540}) + pos_inv2.append( + "taxes", + { + "charge_type": "On Net Total", + "account_head": "_Test Account Service Tax - _TC", + "cost_center": "_Test Cost Center - _TC", + "description": "Service Tax", + "rate": 14, + "included_in_print_rate": 1, + }, + ) + pos_inv2.save() + pos_inv2.submit() + + self.closing_entry = make_closing_entry_from_opening(self.opening_entry) + consolidate_pos_invoices(closing_entry=self.closing_entry) # does DB commit + + pos_inv.load_from_db() + rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total") + self.assertEqual(rounded_total, 840) + + def test_merging_with_validate_selling_price(self): + from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import ( + make_closing_entry_from_opening, + ) + from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import ( + init_user_and_profile, + ) + from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( + consolidate_pos_invoices, + ) + + if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"): + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 1) + + item = "Test Selling Price Validation" + make_item(item, {"is_stock_item": 1}) + make_purchase_receipt(item_code=item, warehouse="_Test Warehouse - _TC", qty=1, rate=300) + frappe.db.sql("delete from `tabPOS Invoice`") + test_user, pos_profile = init_user_and_profile() + pos_inv = create_pos_invoice(item=item, rate=300, do_not_submit=1) + pos_inv.append("payments", {"mode_of_payment": "Cash", "amount": 300}) + pos_inv.append( + "taxes", + { + "charge_type": "On Net Total", + "account_head": "_Test Account Service Tax - _TC", + "cost_center": "_Test Cost Center - _TC", + "description": "Service Tax", + "rate": 14, + "included_in_print_rate": 1, + }, + ) + self.assertRaises(frappe.ValidationError, pos_inv.submit) + + pos_inv2 = create_pos_invoice(item=item, rate=400, do_not_submit=1) + pos_inv2.append("payments", {"mode_of_payment": "Cash", "amount": 400}) + pos_inv2.append( + "taxes", + { + "charge_type": "On Net Total", + "account_head": "_Test Account Service Tax - _TC", + "cost_center": "_Test Cost Center - _TC", + "description": "Service Tax", + "rate": 14, + "included_in_print_rate": 1, + }, + ) + pos_inv2.save() + pos_inv2.submit() + + self.closing_entry = make_closing_entry_from_opening(self.opening_entry) + consolidate_pos_invoices(closing_entry=self.closing_entry) # does DB commit + + pos_inv2.load_from_db() + rounded_total = frappe.db.get_value("Sales Invoice", pos_inv2.consolidated_invoice, "rounded_total") + self.assertEqual(rounded_total, 400) diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index 0874955ec47..e41548b89f6 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -283,7 +283,7 @@ class POSInvoiceMergeLog(Document): base_rounding_adjustment += doc.base_rounding_adjustment base_rounded_total += doc.base_rounded_total - for d in doc.get("item_wise_tax_details"): + for d in doc.get("item_wise_tax_details") or []: row = frappe._dict( item=old_new_item_map[d.item_row], tax=old_new_tax_map[d.tax_row], @@ -572,7 +572,7 @@ def split_invoices(invoices): def create_merge_logs(invoice_by_customer, closing_entry=None): - try: + def merge_and_close(): for customer, invoices_acc_dim in invoice_by_customer.items(): for invoices in invoices_acc_dim.values(): for _invoices in split_invoices(invoices): @@ -594,25 +594,30 @@ def create_merge_logs(invoice_by_customer, closing_entry=None): closing_entry.db_set("error_message", "") closing_entry.update_opening_entry() - except Exception as e: - frappe.db.rollback() - message_log = frappe.message_log.pop() if frappe.message_log else str(e) - error_message = get_error_message(message_log) + if frappe.in_test: + merge_and_close() + else: + try: + merge_and_close() + except Exception as e: + frappe.db.rollback() + message_log = frappe.message_log.pop() if frappe.message_log else str(e) + error_message = get_error_message(message_log) - if closing_entry: - closing_entry.set_status(update=True, status="Failed") - if isinstance(error_message, list): - error_message = json.dumps(error_message) - closing_entry.db_set("error_message", error_message) - raise + if closing_entry: + closing_entry.set_status(update=True, status="Failed") + if isinstance(error_message, list): + error_message = json.dumps(error_message) + closing_entry.db_set("error_message", error_message) + raise - finally: - frappe.db.commit() - frappe.publish_realtime("closing_process_complete", user=frappe.session.user) + finally: + frappe.db.commit() + frappe.publish_realtime("closing_process_complete", user=frappe.session.user) def cancel_merge_logs(merge_logs, closing_entry=None): - try: + def merge_cancel_and_close(): for log in merge_logs: merge_log = frappe.get_doc("POS Invoice Merge Log", log) if merge_log.docstatus == 2: @@ -626,19 +631,24 @@ def cancel_merge_logs(merge_logs, closing_entry=None): closing_entry.db_set("error_message", "") closing_entry.update_opening_entry(for_cancel=True) - except Exception as e: - frappe.db.rollback() - message_log = frappe.message_log.pop() if frappe.message_log else str(e) - error_message = get_error_message(message_log) + if frappe.flags.in_test: + merge_cancel_and_close() + else: + try: + merge_cancel_and_close() + except Exception as e: + frappe.db.rollback() + message_log = frappe.message_log.pop() if frappe.message_log else str(e) + error_message = get_error_message(message_log) - if closing_entry: - closing_entry.set_status(update=True, status="Submitted") - closing_entry.db_set("error_message", error_message) - raise + if closing_entry: + closing_entry.set_status(update=True, status="Submitted") + closing_entry.db_set("error_message", error_message) + raise - finally: - frappe.db.commit() - frappe.publish_realtime("closing_process_complete", user=frappe.session.user) + finally: + frappe.db.commit() + frappe.publish_realtime("closing_process_complete", user=frappe.session.user) def enqueue_job(job, **kwargs): diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py index 5403b10476c..757860a76c6 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py @@ -3,7 +3,6 @@ import json import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.mode_of_payment.test_mode_of_payment import ( set_default_account_for_mode_of_payment, @@ -19,30 +18,25 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle get_serial_nos_from_bundle, ) from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSInvoiceMergeLog(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - frappe.db.sql("delete from `tabPOS Opening Entry`") - cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0)) - cls.enterClassContext(cls.change_settings("POS Settings", invoice_type="POS Invoice")) - mode_of_payment = frappe.get_doc("Mode of Payment", "Bank Draft") - set_default_account_for_mode_of_payment(mode_of_payment, "_Test Company", "_Test Bank - _TC") - +class TestPOSInvoiceMergeLog(ERPNextTestSuite): def setUp(self): - frappe.db.sql("delete from `tabPOS Invoice`") + mode_of_payment = frappe.get_doc("Mode of Payment", "Bank Draft") + self.test_user, self.pos_profile = init_user_and_profile() + self.opening_entry = create_opening_entry(self.pos_profile, self.test_user.name) - def tearDown(self): - frappe.set_user("Administrator") - frappe.db.sql("delete from `tabPOS Profile`") - frappe.db.sql("delete from `tabPOS Invoice`") + set_default_account_for_mode_of_payment(mode_of_payment, "_Test Company", "_Test Bank - _TC") + frappe.db.set_single_value("POS Settings", "invoice_type", "POS Invoice") + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) + + def make_closing_entry(self): + closing_entry = make_closing_entry_from_opening(self.opening_entry) + closing_entry.insert().submit() + return closing_entry def test_consolidated_invoice_creation(self): - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - pos_inv = create_pos_invoice(rate=300, do_not_submit=1) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.save() @@ -58,9 +52,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): pos_inv3.save() pos_inv3.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() pos_inv.load_from_db() self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice)) @@ -71,9 +63,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): self.assertFalse(pos_inv.consolidated_invoice == pos_inv3.consolidated_invoice) def test_consolidated_credit_note_creation(self): - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - pos_inv = create_pos_invoice(rate=300, do_not_submit=1) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.save() @@ -98,9 +87,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): pos_inv_cn.paid_amount = -300 pos_inv_cn.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() pos_inv.load_from_db() self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice)) @@ -118,9 +105,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): self.assertEqual(consolidated_credit_note.payments[1].amount, -200) def test_consolidated_invoice_item_taxes(self): - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - inv = create_pos_invoice(qty=1, rate=100, do_not_save=True) inv.append( @@ -157,9 +141,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): inv2.save() inv2.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() inv.load_from_db() @@ -207,9 +189,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): qty=10, ) - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - inv = create_pos_invoice(qty=3, rate=10000, do_not_save=True) inv.append( "taxes", @@ -244,9 +223,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): inv2.insert() inv2.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() inv.load_from_db() consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) @@ -264,9 +241,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): qty=10, ) - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - inv = create_pos_invoice(qty=6, rate=10000, do_not_save=True) inv.append( "taxes", @@ -306,16 +280,14 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): inv3.insert() inv3.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() inv.load_from_db() consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) self.assertNotEqual(consolidated_invoice.outstanding_amount, 800) self.assertEqual(consolidated_invoice.status, "Paid") - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "System Settings", {"number_format": "#,###.###", "currency_precision": 3, "float_precision": 3} ) def test_consolidation_round_off_error_3(self): @@ -325,8 +297,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): rate=8000, qty=10, ) - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) item_rates = [69, 59, 29] for _i in [1, 2]: @@ -363,9 +333,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): inv.save() inv.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() inv.load_from_db() consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) @@ -383,9 +351,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): qty=10, ) - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - inv = create_pos_invoice(qty=1, rate=69.5, do_not_save=True) inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 70}) inv.insert() @@ -396,9 +361,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): inv2.insert() inv2.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() inv.load_from_db() consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice) @@ -415,14 +378,12 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): The second and third POS Invoice should be consolidated with a single Merge Log """ + self.load_test_records("Stock Entry") from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item se = make_serialized_item(self) serial_no = get_serial_nos_from_bundle(se.get("items")[0].serial_and_batch_bundle)[0] - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - pos_inv = create_pos_invoice( item_code="_Test Serialized Item With Series", serial_no=[serial_no], @@ -449,9 +410,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): pos_inv2.save() pos_inv2.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() pos_inv.load_from_db() pos_inv2.load_from_db() @@ -470,9 +429,6 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): create_cost_center(cost_center_name="_Test POS Cost Center 1", is_group=0) create_cost_center(cost_center_name="_Test POS Cost Center 2", is_group=0) - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - pos_inv = create_pos_invoice(rate=300, do_not_submit=1) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.cost_center = "_Test POS Cost Center 1 - _TC" @@ -491,9 +447,7 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): pos_inv3.save() pos_inv3.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + self.make_closing_entry() pos_inv.load_from_db() self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice)) @@ -512,17 +466,12 @@ class TestPOSInvoiceMergeLog(IntegrationTestCase): """ Test if the company is fetched from POS Closing Entry """ - test_user, pos_profile = init_user_and_profile() - opening_entry = create_opening_entry(pos_profile, test_user.name) - pos_inv = create_pos_invoice(rate=300, do_not_submit=1) pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 300}) pos_inv.save() pos_inv.submit() - closing_entry = make_closing_entry_from_opening(opening_entry) - closing_entry.insert() - closing_entry.submit() + closing_entry = self.make_closing_entry() self.assertTrue(frappe.db.exists("POS Invoice Merge Log", {"pos_closing_entry": closing_entry.name})) diff --git a/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py b/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py index 2b23f94932f..775a18901c8 100644 --- a/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py +++ b/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py @@ -4,35 +4,21 @@ import unittest import frappe from frappe.core.doctype.user_permission.test_user_permission import create_user -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.pos_invoice.test_pos_invoice import create_pos_invoice from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSOpeningEntry(IntegrationTestCase): - @classmethod - def setUpClass(cls): - frappe.db.sql("delete from `tabPOS Opening Entry`") - cls.enterClassContext(cls.change_settings("POS Settings", {"invoice_type": "POS Invoice"})) - - @classmethod - def tearDownClass(cls): - frappe.db.sql("delete from `tabPOS Opening Entry`") - +class TestPOSOpeningEntry(ERPNextTestSuite): def setUp(self): - # Make stock available for POS Sales - frappe.db.sql("delete from `tabPOS Opening Entry`") + frappe.db.set_single_value("POS Settings", "invoice_type", "POS Invoice") make_stock_entry(target="_Test Warehouse - _TC", qty=2, basic_rate=100) from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile self.init_user_and_profile = init_user_and_profile - def tearDown(self): - frappe.set_user("Administrator") - frappe.db.sql("delete from `tabPOS Profile`") - def test_pos_opening_entry(self): test_user, pos_profile = self.init_user_and_profile() opening_entry = create_opening_entry(pos_profile, test_user.name) @@ -61,7 +47,9 @@ class TestPOSOpeningEntry(IntegrationTestCase): self.assertEqual(opening_entry_1.status, "Open") self.assertEqual(opening_entry_1.user, test_user.name) - cashier_user = create_user("test_cashier@example.com", "Accounts Manager", "Sales Manager") + cashier_user = create_user( + "test_cashier@example.com", "Accounts Manager", "Sales Manager", "Stock User", "System Manager" + ) frappe.set_user(cashier_user.name) pos_profile2 = make_pos_profile(name="_Test POS Profile 2") diff --git a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py index 1f02ba7e0a7..f547de9a97e 100644 --- a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py @@ -3,19 +3,18 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import cint from erpnext.accounts.doctype.pos_profile.pos_profile import ( get_child_nodes, ) from erpnext.stock.get_item_details import get_pos_profile - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"] +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSProfile(IntegrationTestCase): +class TestPOSProfile(ERPNextTestSuite): def test_pos_profile(self): + frappe.set_user("Administrator") make_pos_profile() pos_profile = get_pos_profile("_Test Company") or {} @@ -37,8 +36,6 @@ class TestPOSProfile(IntegrationTestCase): self.assertEqual(len(items), products_count[0][0]) self.assertEqual(len(customers), customers_count[0][0]) - frappe.db.sql("delete from `tabPOS Profile`") - def test_disabled_pos_profile_creation(self): make_pos_profile(name="_Test POS Profile 001", disabled=1) diff --git a/erpnext/accounts/doctype/pos_profile_user/test_pos_profile_user.py b/erpnext/accounts/doctype/pos_profile_user/test_pos_profile_user.py index b9747ff5799..2e3b68eeac5 100644 --- a/erpnext/accounts/doctype/pos_profile_user/test_pos_profile_user.py +++ b/erpnext/accounts/doctype/pos_profile_user/test_pos_profile_user.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSProfileUser(IntegrationTestCase): +class TestPOSProfileUser(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/pos_settings/test_pos_settings.py b/erpnext/accounts/doctype/pos_settings/test_pos_settings.py index 1ae75140714..9335efbed07 100644 --- a/erpnext/accounts/doctype/pos_settings/test_pos_settings.py +++ b/erpnext/accounts/doctype/pos_settings/test_pos_settings.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestPOSSettings(IntegrationTestCase): +class TestPOSSettings(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index aa4cd12afc2..6ff1ed85d55 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -5,7 +5,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice @@ -13,17 +12,15 @@ from erpnext.controllers.sales_and_purchase_return import make_return_doc from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.get_item_details import get_item_details +from erpnext.tests.utils import ERPNextTestSuite -class TestPricingRule(IntegrationTestCase): +class TestPricingRule(ERPNextTestSuite): def setUp(self): delete_existing_pricing_rules() setup_pricing_rule_data() self.enterClassContext(self.change_settings("Selling Settings", validate_selling_price=0)) - def tearDown(self): - delete_existing_pricing_rules() - def test_pricing_rule_for_discount(self): from frappe import MandatoryError @@ -416,6 +413,7 @@ class TestPricingRule(IntegrationTestCase): self.assertEqual(item.discount_amount, 110) self.assertEqual(item.rate, 990) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_pricing_rule_for_product_discount_on_same_item(self): frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule") test_record = { @@ -1191,6 +1189,7 @@ class TestPricingRule(IntegrationTestCase): si.delete() rule.delete() + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_pricing_rule_for_product_free_item_rounded_qty_and_recursion(self): frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule") test_record = { @@ -1236,6 +1235,7 @@ class TestPricingRule(IntegrationTestCase): so.save() self.assertEqual(len(so.items), 1) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_pricing_rule_for_product_free_item_round_free_qty(self): frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule") test_record = { @@ -1522,9 +1522,6 @@ class TestPricingRule(IntegrationTestCase): pi.cancel() -EXTRA_TEST_RECORD_DEPENDENCIES = ["UTM Campaign"] - - def make_pricing_rule(**args): args = frappe._dict(args) diff --git a/erpnext/accounts/doctype/process_deferred_accounting/test_process_deferred_accounting.py b/erpnext/accounts/doctype/process_deferred_accounting/test_process_deferred_accounting.py index 8d35b7fcf85..ef98a010511 100644 --- a/erpnext/accounts/doctype/process_deferred_accounting/test_process_deferred_accounting.py +++ b/erpnext/accounts/doctype/process_deferred_accounting/test_process_deferred_accounting.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import ( @@ -11,9 +10,10 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import ( create_sales_invoice, ) from erpnext.stock.doctype.item.test_item import create_item +from erpnext.tests.utils import ERPNextTestSuite -class TestProcessDeferredAccounting(IntegrationTestCase): +class TestProcessDeferredAccounting(ERPNextTestSuite): def test_creation_of_ledger_entry_on_submit(self): """test creation of gl entries on submission of document""" change_acc_settings(acc_frozen_till_date="2023-05-31", book_deferred_entries_based_on="Months") @@ -53,6 +53,7 @@ class TestProcessDeferredAccounting(IntegrationTestCase): start_date="2023-05-01", end_date="2023-06-30", type="Income", + company="_Test Company", ) process_deferred_accounting.insert() @@ -83,6 +84,7 @@ class TestProcessDeferredAccounting(IntegrationTestCase): start_date="2019-01-01", end_date="2019-01-31", type="Income", + company="_Test Company", ) pda.submit() pda.cancel() diff --git a/erpnext/accounts/doctype/process_payment_reconciliation/test_process_payment_reconciliation.py b/erpnext/accounts/doctype/process_payment_reconciliation/test_process_payment_reconciliation.py index d54ff6f902e..eff49ecadc5 100644 --- a/erpnext/accounts/doctype/process_payment_reconciliation/test_process_payment_reconciliation.py +++ b/erpnext/accounts/doctype/process_payment_reconciliation/test_process_payment_reconciliation.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestProcessPaymentReconciliation(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestProcessPaymentReconciliation(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/process_payment_reconciliation_log/test_process_payment_reconciliation_log.py b/erpnext/accounts/doctype/process_payment_reconciliation_log/test_process_payment_reconciliation_log.py index 66a4dca21e1..26c4b5a4a1c 100644 --- a/erpnext/accounts/doctype/process_payment_reconciliation_log/test_process_payment_reconciliation_log.py +++ b/erpnext/accounts/doctype/process_payment_reconciliation_log/test_process_payment_reconciliation_log.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestProcessPaymentReconciliationLog(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestProcessPaymentReconciliationLog(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/process_period_closing_voucher/test_process_period_closing_voucher.py b/erpnext/accounts/doctype/process_period_closing_voucher/test_process_period_closing_voucher.py index 17ce2c13b09..e695b11bcb5 100644 --- a/erpnext/accounts/doctype/process_period_closing_voucher/test_process_period_closing_voucher.py +++ b/erpnext/accounts/doctype/process_period_closing_voucher/test_process_period_closing_voucher.py @@ -2,19 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class IntegrationTestProcessPeriodClosingVoucher(IntegrationTestCase): - """ - Integration tests for ProcessPeriodClosingVoucher. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/test_process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/test_process_statement_of_accounts.py index 2d599fee1af..c16933c7836 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/test_process_statement_of_accounts.py +++ b/erpnext/accounts/doctype/process_statement_of_accounts/test_process_statement_of_accounts.py @@ -3,7 +3,6 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, getdate, today from erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts import ( @@ -12,26 +11,16 @@ from erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of ) from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestProcessStatementOfAccounts(AccountsTestMixin, IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestProcessStatementOfAccounts(AccountsTestMixin, ERPNextTestSuite): + def setUp(self): + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) letterhead = frappe.get_doc("Letter Head", "Company Letterhead - Grey") letterhead.is_default = 0 letterhead.save() - cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0)) - @classmethod - def tearDownClass(cls): - super().tearDownClass() - letterhead = frappe.get_doc("Letter Head", "Company Letterhead - Grey") - letterhead.is_default = 1 - letterhead.save() - frappe.db.commit() # nosemgrep - - def setUp(self): self.create_company() self.create_customer() self.create_customer(customer_name="Other Customer") @@ -101,9 +90,6 @@ class TestProcessStatementOfAccounts(AccountsTestMixin, IntegrationTestCase): for age_range in expected_ageing: self.assertEqual(expected_ageing[age_range], ageing.get(age_range)) - def tearDown(self): - frappe.db.rollback() - def create_process_soa(**args): args = frappe._dict(args) diff --git a/erpnext/accounts/doctype/process_subscription/test_process_subscription.py b/erpnext/accounts/doctype/process_subscription/test_process_subscription.py index 5ec80641192..8c7604b8f5c 100644 --- a/erpnext/accounts/doctype/process_subscription/test_process_subscription.py +++ b/erpnext/accounts/doctype/process_subscription/test_process_subscription.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestProcessSubscription(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestProcessSubscription(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/promotional_scheme/test_promotional_scheme.py b/erpnext/accounts/doctype/promotional_scheme/test_promotional_scheme.py index 413ce1af792..cebdaa4fca8 100644 --- a/erpnext/accounts/doctype/promotional_scheme/test_promotional_scheme.py +++ b/erpnext/accounts/doctype/promotional_scheme/test_promotional_scheme.py @@ -3,13 +3,13 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.promotional_scheme.promotional_scheme import TransactionExists from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order +from erpnext.tests.utils import ERPNextTestSuite -class TestPromotionalScheme(IntegrationTestCase): +class TestPromotionalScheme(ERPNextTestSuite): def setUp(self): if frappe.db.exists("Promotional Scheme", "_Test Scheme"): frappe.delete_doc("Promotional Scheme", "_Test Scheme") diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index cb771bdc35a..33117c639dc 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -3,7 +3,6 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, cint, flt, getdate, nowdate, today import erpnext @@ -37,24 +36,15 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle ) from erpnext.stock.doctype.stock_entry.test_stock_entry import get_qty_after_transaction from erpnext.stock.tests.test_utils import StockTestMixin - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Cost Center", "Payment Term", "Payment Terms Template"] -IGNORE_TEST_RECORD_DEPENDENCIES = ["Serial No"] +from erpnext.tests.utils import ERPNextTestSuite -class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestPurchaseInvoice(ERPNextTestSuite, StockTestMixin): + def setUp(self): unlink_payment_on_cancel_of_invoice() frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1) - - @classmethod - def tearDownClass(cls): - unlink_payment_on_cancel_of_invoice(0) - - def tearDown(self): - frappe.db.rollback() + self.load_test_records("Purchase Invoice") + self.load_test_records("Journal Entry") def test_purchase_invoice_qty(self): pi = make_purchase_invoice(qty=0, do_not_save=True) @@ -352,6 +342,9 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): self.assertEqual(expected_values[gle.account][1], gle.debit) self.assertEqual(expected_values[gle.account][2], gle.credit) + @ERPNextTestSuite.change_settings( + "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} + ) def test_purchase_invoice_with_exchange_rate_difference(self): from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_invoice as create_purchase_invoice, @@ -375,7 +368,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): # fetching the latest GL Entry with exchange gain and loss account account amount = frappe.db.get_value( - "GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "debit" + "GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "credit" ) discrepancy_caused_by_exchange_rate_diff = abs( pi.items[0].base_net_amount - pr.items[0].base_net_amount @@ -421,14 +414,14 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): # fetching the latest GL Entry with exchange gain and loss account account amount = frappe.db.get_value( - "GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "debit" + "GL Entry", {"account": exchange_gain_loss_account, "voucher_no": pi.name}, "credit" ) discrepancy_caused_by_exchange_rate_diff = abs( pi.items[1].base_net_amount - pr.items[1].base_net_amount ) - self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount) + self.assertEqual(flt(discrepancy_caused_by_exchange_rate_diff, 2), amount) def test_purchase_invoice_change_naming_series(self): pi = frappe.copy_doc(self.globalTestRecords["Purchase Invoice"][1]) @@ -509,9 +502,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): self.assertEqual(tax.tax_amount, expected_values[i][1]) self.assertEqual(tax.total, expected_values[i][2]) - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_purchase_invoice_with_advance(self): jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][1]) jv.insert() @@ -562,9 +553,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): ) ) - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_invoice_with_advance_and_multi_payment_terms(self): jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][1]) jv.insert() @@ -1289,9 +1278,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): acc_settings.submit_journal_entriessubmit_journal_entries = 0 acc_settings.save() - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_gain_loss_with_advance_entry(self): unlink_enabled = frappe.db.get_single_value( "Accounts Settings", "unlink_payment_on_cancellation_of_invoice" @@ -1492,9 +1479,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): ) frappe.db.set_value("Company", "_Test Company", "exchange_gain_loss_account", original_account) - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_purchase_invoice_advance_taxes(self): from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -2160,7 +2145,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): rate = flt(sle.stock_value_difference) / flt(sle.actual_qty) self.assertAlmostEqual(rate, 500) - @IntegrationTestCase.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) def test_payment_allocation_for_payment_terms(self): from erpnext.buying.doctype.purchase_order.test_purchase_order import ( create_pr_against_po, @@ -2287,6 +2272,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): def test_create_purchase_invoice_without_mandatory(self): pi = frappe.new_doc("Purchase Invoice") + pi.company = "_Test Company" pi.flags.ignore_mandatory = True pi.insert(ignore_permissions=True) @@ -2295,7 +2281,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): pi.delete() - @IntegrationTestCase.change_settings("Buying Settings", {"supplier_group": None}) + @ERPNextTestSuite.change_settings("Buying Settings", {"supplier_group": None}) def test_purchase_invoice_without_supplier_group(self): # Create a Supplier test_supplier_name = "_Test Supplier Without Supplier Group" @@ -2415,6 +2401,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): "doctype": "Serial No", "item_code": serial_item, "serial_no": serial_no, + "company": "_Test Company", } ).insert() @@ -2467,11 +2454,6 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): self.assertEqual(row.rejected_serial_no, serial_nos[2]) def test_make_pr_and_pi_from_po(self): - from erpnext.assets.doctype.asset.test_asset import create_asset_category - - if not frappe.db.exists("Asset Category", "Computers"): - create_asset_category() - item = create_item( item_code="_Test_Item", is_stock_item=0, is_fixed_asset=1, asset_category="Computers" ) @@ -2642,7 +2624,7 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): frappe.db.set_single_value("Buying Settings", "maintain_same_rate", 1) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Buying Settings", {"maintain_same_rate": 0, "set_landed_cost_based_on_purchase_invoice_rate": 1} ) def test_pr_status_rate_adjusted_from_pi(self): diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.py b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.py index 80ce28c4ffd..5dbd05a17f6 100644 --- a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.py +++ b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestPurchaseTaxesandChargesTemplate(IntegrationTestCase): +class TestPurchaseTaxesandChargesTemplate(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/repost_accounting_ledger/test_repost_accounting_ledger.py b/erpnext/accounts/doctype/repost_accounting_ledger/test_repost_accounting_ledger.py index cde007d14f6..b60c13fc8b8 100644 --- a/erpnext/accounts/doctype/repost_accounting_ledger/test_repost_accounting_ledger.py +++ b/erpnext/accounts/doctype/repost_accounting_ledger/test_repost_accounting_ledger.py @@ -4,7 +4,6 @@ import frappe from frappe import qb from frappe.query_builder.functions import Sum -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, nowdate, today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -14,23 +13,17 @@ from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.accounts.utils import get_fiscal_year from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries, make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class TestRepostAccountingLedger(AccountsTestMixin, IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0)) - +class TestRepostAccountingLedger(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.create_item() + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) update_repost_settings() - def tearDown(self): - frappe.db.rollback() - def test_01_basic_functions(self): si = create_sales_invoice( item=self.item, @@ -121,7 +114,7 @@ class TestRepostAccountingLedger(AccountsTestMixin, IntegrationTestCase): ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name}) self.assertRaises(frappe.ValidationError, ral.save) - @IntegrationTestCase.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) def test_04_pcv_validation(self): # Clear old GL entries so PCV can be submitted. gl = frappe.qb.DocType("GL Entry") diff --git a/erpnext/accounts/doctype/repost_accounting_ledger_settings/test_repost_accounting_ledger_settings.py b/erpnext/accounts/doctype/repost_accounting_ledger_settings/test_repost_accounting_ledger_settings.py index 2dd4c50ba7e..6a8698e96af 100644 --- a/erpnext/accounts/doctype/repost_accounting_ledger_settings/test_repost_accounting_ledger_settings.py +++ b/erpnext/accounts/doctype/repost_accounting_ledger_settings/test_repost_accounting_ledger_settings.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestRepostAccountingLedgerSettings(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestRepostAccountingLedgerSettings(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/repost_payment_ledger/test_repost_payment_ledger.py b/erpnext/accounts/doctype/repost_payment_ledger/test_repost_payment_ledger.py index a09ba71e27c..8c2b8946121 100644 --- a/erpnext/accounts/doctype/repost_payment_ledger/test_repost_payment_ledger.py +++ b/erpnext/accounts/doctype/repost_payment_ledger/test_repost_payment_ledger.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestRepostPaymentLedger(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestRepostPaymentLedger(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/sales_invoice/test_records.json b/erpnext/accounts/doctype/sales_invoice/test_records.json index 814c6757d38..9aee69cd053 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_records.json +++ b/erpnext/accounts/doctype/sales_invoice/test_records.json @@ -383,5 +383,390 @@ "price_list_currency": "INR", "selling_price_list": "_Test Price List", "territory": "_Test Territory" + }, + { + "company": "_Test Company", + "conversion_rate": 1.0, + "currency": "INR", + "cost_center": "_Test Cost Center - _TC", + "customer": "_Test Customer", + "customer_name": "_Test Customer", + "debit_to": "Debtors - _TC", + "doctype": "Sales Invoice", + "items": [ + { + "amount": 500.0, + "base_amount": 500.0, + "base_rate": 500.0, + "cost_center": "_Test Cost Center - _TC", + "description": "138-CMS Shoe", + "doctype": "Sales Invoice Item", + "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "item_code": "138-CMS Shoe", + "item_name": "138-CMS Shoe", + "parentfield": "items", + "qty": 1.0, + "rate": 500.0, + "uom": "_Test UOM", + "conversion_factor": 1, + "stock_uom": "_Test UOM" + } + ], + "base_grand_total": 561.8, + "grand_total": 561.8, + "is_pos": 0, + "naming_series": "T-SINV-", + "base_net_total": 500.0, + "taxes": [ + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "cost_center": "_Test Cost Center - _TC", + "rate": 6 + }, + { + "account_head": "_Test Account Service Tax - _TC", + "charge_type": "On Net Total", + "description": "Service Tax", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "cost_center": "_Test Cost Center - _TC", + "rate": 6.36 + } + ], + "plc_conversion_rate": 1.0, + "price_list_currency": "INR", + "selling_price_list": "_Test Price List", + "territory": "_Test Territory" + }, + { + "company": "_Test Company", + "conversion_rate": 1.0, + "currency": "INR", + "customer": "_Test Customer", + "customer_name": "_Test Customer", + "debit_to": "Debtors - _TC", + "doctype": "Sales Invoice", + "cost_center": "_Test Cost Center - _TC", + "items": [ + { + "amount": 500.0, + "base_amount": 500.0, + "base_rate": 500.0, + "cost_center": "_Test Cost Center - _TC", + "description": "_Test Item", + "doctype": "Sales Invoice Item", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "income_account": "Sales - _TC", + "item_code": "_Test Item", + "item_name": "_Test Item", + "parentfield": "items", + "price_list_rate": 500.0, + "qty": 1.0, + "uom": "_Test UOM", + "conversion_factor": 1, + "stock_uom": "_Test UOM" + } + ], + "base_grand_total": 630.0, + "grand_total": 630.0, + "is_pos": 0, + "naming_series": "T-SINV-", + "base_net_total": 500.0, + "taxes": [ + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "cost_center": "_Test Cost Center - _TC", + "rate": 16 + }, + { + "account_head": "_Test Account Service Tax - _TC", + "charge_type": "On Net Total", + "description": "Service Tax", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "cost_center": "_Test Cost Center - _TC", + "rate": 10 + } + ], + "plc_conversion_rate": 1.0, + "price_list_currency": "INR", + "selling_price_list": "_Test Price List", + "territory": "_Test Territory" + }, + { + "company": "_Test Company", + "conversion_rate": 1.0, + "currency": "INR", + "customer": "_Test Customer", + "customer_name": "_Test Customer", + "debit_to": "Debtors - _TC", + "doctype": "Sales Invoice", + "cost_center": "_Test Cost Center - _TC", + "items": [ + { + "cost_center": "_Test Cost Center - _TC", + "doctype": "Sales Invoice Item", + "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "item_code": "_Test Item Home Desktop 100", + "item_name": "_Test Item Home Desktop 100", + "item_tax_template": "_Test Account Excise Duty @ 10 - _TC", + "parentfield": "items", + "price_list_rate": 50, + "qty": 10, + "rate": 50, + "uom": "_Test UOM 1", + "conversion_factor": 1, + "stock_uom": "_Test UOM 1" + }, + { + "cost_center": "_Test Cost Center - _TC", + "doctype": "Sales Invoice Item", + "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "item_code": "_Test Item Home Desktop 200", + "item_name": "_Test Item Home Desktop 200", + "parentfield": "items", + "price_list_rate": 150, + "qty": 5, + "uom": "_Test UOM", + "conversion_factor": 1, + "rate": 150, + "stock_uom": "_Test UOM" + } + ], + "grand_total": 0, + "is_pos": 0, + "naming_series": "T-SINV-", + "taxes": [ + { + "account_head": "_Test Account Shipping Charges - _TC", + "charge_type": "Actual", + "cost_center": "_Test Cost Center - _TC", + "description": "Shipping Charges", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "tax_amount": 100 + }, + { + "account_head": "_Test Account Customs Duty - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Customs Duty", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 10 + }, + { + "account_head": "_Test Account Excise Duty - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Excise Duty", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 12 + }, + { + "account_head": "_Test Account Education Cess - _TC", + "charge_type": "On Previous Row Amount", + "cost_center": "_Test Cost Center - _TC", + "description": "Education Cess", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 2, + "row_id": 3 + }, + { + "account_head": "_Test Account S&H Education Cess - _TC", + "charge_type": "On Previous Row Amount", + "cost_center": "_Test Cost Center - _TC", + "description": "S&H Education Cess", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 1, + "row_id": 3 + }, + { + "account_head": "_Test Account CST - _TC", + "charge_type": "On Previous Row Total", + "cost_center": "_Test Cost Center - _TC", + "description": "CST", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 2, + "row_id": 5 + }, + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 12.5 + }, + { + "account_head": "_Test Account Discount - _TC", + "charge_type": "On Previous Row Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Discount", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": -10, + "row_id": 7 + } + ], + "plc_conversion_rate": 1.0, + "price_list_currency": "INR", + "selling_price_list": "_Test Price List", + "territory": "_Test Territory" + }, + { + "company": "_Test Company", + "conversion_rate": 1.0, + "currency": "INR", + "customer": "_Test Customer", + "customer_name": "_Test Customer", + "debit_to": "Debtors - _TC", + "doctype": "Sales Invoice", + "cost_center": "_Test Cost Center - _TC", + "items": [ + { + "cost_center": "_Test Cost Center - _TC", + "doctype": "Sales Invoice Item", + "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "item_code": "_Test Item Home Desktop 100", + "item_name": "_Test Item Home Desktop 100", + "item_tax_template": "_Test Account Excise Duty @ 10 - _TC", + "parentfield": "items", + "price_list_rate": 62.5, + "qty": 10, + "uom": "_Test UOM 1", + "conversion_factor": 1, + "stock_uom": "_Test UOM 1" + }, + { + "cost_center": "_Test Cost Center - _TC", + "doctype": "Sales Invoice Item", + "income_account": "Sales - _TC", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "item_code": "_Test Item Home Desktop 200", + "item_name": "_Test Item Home Desktop 200", + "parentfield": "items", + "price_list_rate": 190.66, + "qty": 5, + "uom": "_Test UOM", + "conversion_factor": 1, + "stock_uom": "_Test UOM" + } + ], + "grand_total": 0, + "is_pos": 0, + "naming_series": "T-SINV-", + "taxes": [ + { + "account_head": "_Test Account Excise Duty - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Excise Duty", + "doctype": "Sales Taxes and Charges", + "idx": 1, + "included_in_print_rate": 1, + "parentfield": "taxes", + "rate": 12 + }, + { + "account_head": "_Test Account Education Cess - _TC", + "charge_type": "On Previous Row Amount", + "cost_center": "_Test Cost Center - _TC", + "description": "Education Cess", + "doctype": "Sales Taxes and Charges", + "idx": 2, + "included_in_print_rate": 1, + "parentfield": "taxes", + "rate": 2, + "row_id": 1 + }, + { + "account_head": "_Test Account S&H Education Cess - _TC", + "charge_type": "On Previous Row Amount", + "cost_center": "_Test Cost Center - _TC", + "description": "S&H Education Cess", + "doctype": "Sales Taxes and Charges", + "idx": 3, + "included_in_print_rate": 1, + "parentfield": "taxes", + "rate": 1, + "row_id": 1 + }, + { + "account_head": "_Test Account CST - _TC", + "charge_type": "On Previous Row Total", + "cost_center": "_Test Cost Center - _TC", + "description": "CST", + "doctype": "Sales Taxes and Charges", + "idx": 4, + "included_in_print_rate": 1, + "parentfield": "taxes", + "rate": 2, + "row_id": 3 + }, + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "idx": 5, + "included_in_print_rate": 1, + "parentfield": "taxes", + "rate": 12.5 + }, + { + "account_head": "_Test Account Customs Duty - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Customs Duty", + "doctype": "Sales Taxes and Charges", + "idx": 6, + "parentfield": "taxes", + "rate": 10 + }, + { + "account_head": "_Test Account Shipping Charges - _TC", + "charge_type": "Actual", + "cost_center": "_Test Cost Center - _TC", + "description": "Shipping Charges", + "doctype": "Sales Taxes and Charges", + "idx": 7, + "parentfield": "taxes", + "tax_amount": 100 + }, + { + "account_head": "_Test Account Discount - _TC", + "charge_type": "On Previous Row Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Discount", + "doctype": "Sales Taxes and Charges", + "idx": 8, + "parentfield": "taxes", + "rate": -10, + "row_id": 7 + } + ], + "plc_conversion_rate": 1.0, + "price_list_currency": "INR", + "selling_price_list": "_Test Price List", + "territory": "_Test Territory" } ] diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 6a0eb0e5014..3616f196bb7 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -7,7 +7,6 @@ import json import frappe from frappe import qb from frappe.model.dynamic_links import get_dynamic_link_map -from frappe.tests import IntegrationTestCase, change_settings from frappe.utils import add_days, cint, flt, format_date, getdate, nowdate, today import erpnext @@ -23,7 +22,7 @@ from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import ( from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_inter_company_transaction from erpnext.accounts.utils import PaymentEntryUnlinkError from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries -from erpnext.assets.doctype.asset.test_asset import create_asset, create_asset_data +from erpnext.assets.doctype.asset.test_asset import create_asset from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( get_depr_schedule, ) @@ -53,6 +52,11 @@ from erpnext.tests.utils import ERPNextTestSuite class TestSalesInvoice(ERPNextTestSuite): def setUp(self): + self.load_test_records("Journal Entry") + self.load_test_records("Stock Entry") + self.load_test_records("Sales Invoice") + unlink_payment_on_cancel_of_invoice() + from erpnext.stock.doctype.stock_ledger_entry.test_stock_ledger_entry import create_items create_items(["_Test Internal Transfer Item"], uoms=[{"uom": "Box", "conversion_factor": 10}]) @@ -65,8 +69,9 @@ class TestSalesInvoice(ERPNextTestSuite): ) for company in frappe.get_all("Company", pluck="name"): frappe.db.set_value("Company", company, "accounts_frozen_till_date", None) + frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0) - @change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"maintain_same_internal_transaction_rate": 1, "maintain_same_rate_action": "Stop"}, ) @@ -86,9 +91,6 @@ class TestSalesInvoice(ERPNextTestSuite): pi.submit() self.assertIn("Rate must be same", str(e.exception)) - def tearDown(self): - frappe.db.rollback() - def make(self): w = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][0]) w.is_pos = 0 @@ -96,18 +98,6 @@ class TestSalesInvoice(ERPNextTestSuite): w.submit() return w - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.enterClassContext(cls.change_settings("Selling Settings", validate_selling_price=0)) - cls.make_employees() - cls.make_sales_person() - unlink_payment_on_cancel_of_invoice() - - @classmethod - def tearDownClass(self): - unlink_payment_on_cancel_of_invoice(0) - def test_sales_invoice_qty(self): si = create_sales_invoice(qty=0, do_not_save=True) with self.assertRaises(InvalidQtyError): @@ -229,9 +219,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertRaises(frappe.LinkExistsError, si.cancel) unlink_payment_on_cancel_of_invoice() - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_payment_entry_unlink_against_standalone_credit_note(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry @@ -273,6 +261,9 @@ class TestSalesInvoice(ERPNextTestSuite): si1.load_from_db() self.assertRaises(PaymentEntryUnlinkError, si1.cancel) + @ERPNextTestSuite.change_settings( + "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} + ) def test_sales_invoice_calculation_export_currency(self): si = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][2]) si.currency = "USD" @@ -536,6 +527,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertTrue(gle) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_tax_calculation_with_multiple_items(self): si = create_sales_invoice(qty=84, rate=4.6, do_not_save=True) item_row = si.get("items")[0] @@ -564,6 +556,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(si.grand_total, 5474.0) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_tax_calculation_with_item_tax_template(self): si = create_sales_invoice(qty=84, rate=4.6, do_not_save=True) item_row = si.get("items")[0] @@ -630,6 +623,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(si.rounding_adjustment, 0.43) self.assertEqual(si.rounded_total, 5676.0) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_tax_calculation_with_multiple_items_and_discount(self): si = create_sales_invoice(qty=1, rate=75, do_not_save=True) item_row = si.get("items")[0] @@ -754,6 +748,9 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(si.base_grand_total, 1622.97) self.assertEqual(si.grand_total, 1622.97) + @ERPNextTestSuite.change_settings( + "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} + ) def test_sales_invoice_calculation_export_currency_with_tax_inclusive_price(self): # prepare si = frappe.copy_doc(self.globalTestRecords["Sales Invoice"][3]) @@ -844,7 +841,7 @@ class TestSalesInvoice(ERPNextTestSuite): w = self.make() self.assertEqual(w.outstanding_amount, w.base_rounded_total) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"add_taxes_from_item_tax_template": 0, "add_taxes_from_taxes_and_charges_template": 0}, ) @@ -1401,9 +1398,7 @@ class TestSalesInvoice(ERPNextTestSuite): dn.submit() return dn - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_sales_invoice_with_advance(self): jv = frappe.copy_doc(self.globalTestRecords["Journal Entry"][0]) jv.insert() @@ -1624,7 +1619,6 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertRaises(frappe.ValidationError, cr_note.save) def test_gle_made_when_asset_is_returned(self): - create_asset_data() asset = create_asset(item_code="Macbook Pro") si = create_sales_invoice(item_code="Macbook Pro", asset=asset.name, qty=1, rate=90000) @@ -2131,17 +2125,21 @@ class TestSalesInvoice(ERPNextTestSuite): si.insert() return si + @ERPNextTestSuite.change_settings("Selling Settings", {"sales_update_frequency": "Each Transaction"}) def test_company_monthly_sales(self): - existing_current_month_sales = frappe.get_cached_value( - "Company", "_Test Company", "total_monthly_sales" - ) + from erpnext.setup.doctype.company.company import update_company_current_month_sales + + company = "_Test Company" + + update_company_current_month_sales(company) + existing_current_month_sales = frappe.db.get_value("Company", company, "total_monthly_sales") si = create_sales_invoice() - current_month_sales = frappe.get_cached_value("Company", "_Test Company", "total_monthly_sales") + current_month_sales = frappe.db.get_value("Company", company, "total_monthly_sales") self.assertEqual(current_month_sales, existing_current_month_sales + si.base_grand_total) si.cancel() - current_month_sales = frappe.get_cached_value("Company", "_Test Company", "total_monthly_sales") + current_month_sales = frappe.db.get_value("Company", company, "total_monthly_sales") self.assertEqual(current_month_sales, existing_current_month_sales) def test_rounding_adjustment(self): @@ -2188,6 +2186,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(expected_values[gle.account][1], gle.debit) self.assertEqual(expected_values[gle.account][2], gle.credit) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_rounding_adjustment_2(self): si = create_sales_invoice(rate=400, do_not_save=True) for rate in [400.25, 600.30, 100.65]: @@ -2245,6 +2244,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(expected_account_values[0], gle.debit) self.assertEqual(expected_account_values[1], gle.credit) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_rounding_adjustment_3(self): from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import create_dimension @@ -2484,7 +2484,7 @@ class TestSalesInvoice(ERPNextTestSuite): for gle in gl_entries: self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"book_deferred_entries_based_on": "Days", "book_deferred_entries_via_journal_entry": 0}, ) @@ -2540,7 +2540,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertRaises(frappe.ValidationError, si.save) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"book_deferred_entries_based_on": "Months", "book_deferred_entries_via_journal_entry": 0}, ) @@ -3005,7 +3005,7 @@ class TestSalesInvoice(ERPNextTestSuite): si.submit() - @IntegrationTestCase.change_settings("Selling Settings", {"enable_discount_accounting": 1}) + @ERPNextTestSuite.change_settings("Selling Settings", {"enable_discount_accounting": 1}) def test_sales_invoice_with_discount_accounting_enabled(self): discount_account = create_account( account_name="Discount Account", @@ -3022,7 +3022,7 @@ class TestSalesInvoice(ERPNextTestSuite): check_gl_entries(self, si.name, expected_gle, add_days(nowdate(), -1)) - @IntegrationTestCase.change_settings("Selling Settings", {"enable_discount_accounting": 1}) + @ERPNextTestSuite.change_settings("Selling Settings", {"enable_discount_accounting": 1}) def test_additional_discount_for_sales_invoice_with_discount_accounting_enabled(self): from erpnext.accounts.doctype.repost_accounting_ledger.test_repost_accounting_ledger import ( update_repost_settings, @@ -3113,7 +3113,6 @@ class TestSalesInvoice(ERPNextTestSuite): Tests if an Asset set to depreciate yearly on June 30, that gets sold on Sept 30, creates an additional depreciation entry on its date of sale. """ - create_asset_data() asset = create_asset(item_code="Macbook Pro", calculate_depreciation=1, submit=1) post_depreciation_entries(getdate("2021-09-30")) @@ -3139,7 +3138,6 @@ class TestSalesInvoice(ERPNextTestSuite): Tests if an Asset set to depreciate yearly on Dec 31, that gets sold on Dec 31 after two years, created an additional depreciation entry on its date of sale. """ - create_asset_data() asset = create_asset( item_code="Macbook Pro", calculate_depreciation=1, @@ -3460,7 +3458,8 @@ class TestSalesInvoice(ERPNextTestSuite): si.submit() frappe.db.set_value("Company", "_Test Company", "accounts_frozen_till_date", None) - @IntegrationTestCase.change_settings("Accounts Settings", {"over_billing_allowance": 0}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"over_billing_allowance": 0}) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_over_billing_case_against_delivery_note(self): """ Test a case where duplicating the item with qty = 1 in the invoice @@ -3486,7 +3485,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertTrue("cannot overbill" in str(err.exception).lower()) dn.cancel() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "book_deferred_entries_via_journal_entry": 1, @@ -3604,9 +3603,7 @@ class TestSalesInvoice(ERPNextTestSuite): account.disabled = 0 account.save() - @IntegrationTestCase.change_settings( - "Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1} - ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1}) def test_gain_loss_with_advance_entry(self): from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry @@ -3769,7 +3766,7 @@ class TestSalesInvoice(ERPNextTestSuite): set_advance_flag(company="_Test Company", flag=0, default_account="") - @IntegrationTestCase.change_settings("Selling Settings", {"customer_group": None, "territory": None}) + @ERPNextTestSuite.change_settings("Selling Settings", {"customer_group": None, "territory": None}) def test_sales_invoice_without_customer_group_and_territory(self): # create a customer if not frappe.db.exists("Customer", "_Test Simple Customer"): @@ -3787,7 +3784,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(si.customer_group, None) self.assertEqual(si.territory, None) - @IntegrationTestCase.change_settings("Selling Settings", {"allow_negative_rates_for_items": 0}) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_negative_rates_for_items": 0}) def test_sales_return_negative_rate(self): si = create_sales_invoice(is_return=1, qty=-2, rate=-10, do_not_save=True) self.assertRaises(frappe.ValidationError, si.save) @@ -3884,19 +3881,18 @@ class TestSalesInvoice(ERPNextTestSuite): def test_loyalty_points_redemption_with_shopping_cart(self): from erpnext.accounts.doctype.loyalty_program.test_loyalty_program import ( - create_records, create_sales_invoice_record, ) from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order # Set up loyalty program - create_records() - frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Single Loyalty") + loyalty_customer = frappe.get_doc("Customer", {"customer_name": "Test Loyalty Customer"}).name + frappe.db.set_value("Customer", loyalty_customer, "loyalty_program", "Test Single Loyalty") create_sales_invoice_record(10).insert().submit() # Create a sales order - so = make_sales_order(qty=10, do_not_save=True, customer="Test Loyalty Customer") + so = make_sales_order(qty=10, do_not_save=True, customer=loyalty_customer) so.name = "_T-Sales Order LP-0001" so.order_type = "Shopping Cart" so.loyalty_points = 50 @@ -4174,12 +4170,14 @@ class TestSalesInvoice(ERPNextTestSuite): si.save() return si + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_rounding_validation_for_opening_with_inclusive_tax(self): si = self._create_opening_invoice_with_inclusive_tax() # 'Round Off for Opening' not set in Company master # Ledger level validation must be thrown self.assertRaises(frappe.ValidationError, si.submit) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_ledger_entries_on_opening_invoice_with_rounding_loss_by_inclusive_tax(self): si = self._create_opening_invoice_with_inclusive_tax() # 'Round Off for Opening' is set in Company master @@ -4201,7 +4199,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertEqual(len(actual), 4) self.assertEqual(expected, actual) - @IntegrationTestCase.change_settings("Accounts Settings", {"enable_common_party_accounting": True}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"enable_common_party_accounting": True}) def test_common_party_with_foreign_currency_jv(self): from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import ( @@ -4283,7 +4281,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertTrue(jv) self.assertEqual(jv[0], si.grand_total) - @IntegrationTestCase.change_settings("Accounts Settings", {"enable_common_party_accounting": True}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"enable_common_party_accounting": True}) def test_common_party_with_different_currency_in_debtor_and_creditor(self): from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import ( @@ -4392,6 +4390,7 @@ class TestSalesInvoice(ERPNextTestSuite): self.assertTrue(all([x == "Credit Note" for x in gl_entries])) + @ERPNextTestSuite.change_settings("Selling Settings", {"sales_update_frequency": "Each Transaction"}) def test_total_billed_amount(self): si = create_sales_invoice(do_not_submit=True) @@ -4407,6 +4406,8 @@ class TestSalesInvoice(ERPNextTestSuite): doc = frappe.get_doc("Project", project.name) self.assertEqual(doc.total_billed_amount, si.grand_total) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) + @ERPNextTestSuite.change_settings("Selling Settings", {"sales_update_frequency": "Each Transaction"}) def test_total_billed_amount_with_different_projects(self): # This test case is for checking the scenario where project is set at document level and for **some** child items only, not all from copy import copy @@ -4745,7 +4746,7 @@ class TestSalesInvoice(ERPNextTestSuite): doc.db_set("do_not_use_batchwise_valuation", original_value) - @change_settings("Selling Settings", {"set_zero_rate_for_expired_batch": True}) + @ERPNextTestSuite.change_settings("Selling Settings", {"set_zero_rate_for_expired_batch": True}) def test_zero_valuation_for_standalone_credit_note_with_expired_batch(self): item_code = "_Test Item for Expiry Batch Zero Valuation" make_item_for_si( @@ -5016,9 +5017,6 @@ def create_sales_invoice_against_cost_center(**args): return si -EXTRA_TEST_RECORD_DEPENDENCIES = ["Journal Entry", "Contact", "Address"] - - def get_outstanding_amount(against_voucher_type, against_voucher, account, party, party_type): bal = flt( frappe.db.sql( diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_records.json b/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_records.json deleted file mode 100644 index 74db08d5b86..00000000000 --- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_records.json +++ /dev/null @@ -1,209 +0,0 @@ -[ - { - "company": "_Test Company", - "doctype": "Sales Taxes and Charges Template", - "taxes": [ - { - "account_head": "_Test Account VAT - _TC", - "charge_type": "On Net Total", - "description": "VAT", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 6 - }, - { - "account_head": "_Test Account Service Tax - _TC", - "charge_type": "On Net Total", - "description": "Service Tax", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 6.36 - } - ], - "title": "_Test Sales Taxes and Charges Template" - }, - { - "company": "_Test Company", - "doctype": "Sales Taxes and Charges Template", - "taxes": [ - { - "account_head": "_Test Account Shipping Charges - _TC", - "charge_type": "Actual", - "cost_center": "_Test Cost Center - _TC", - "description": "Shipping Charges", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "tax_amount": 100 - }, - { - "account_head": "_Test Account Customs Duty - _TC", - "charge_type": "On Net Total", - "cost_center": "_Test Cost Center - _TC", - "description": "Customs Duty", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 10 - }, - { - "account_head": "_Test Account Excise Duty - _TC", - "charge_type": "On Net Total", - "cost_center": "_Test Cost Center - _TC", - "description": "Excise Duty", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 12 - }, - { - "account_head": "_Test Account Education Cess - _TC", - "charge_type": "On Previous Row Amount", - "cost_center": "_Test Cost Center - _TC", - "description": "Education Cess", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 2, - "row_id": 3 - }, - { - "account_head": "_Test Account S&H Education Cess - _TC", - "charge_type": "On Previous Row Amount", - "cost_center": "_Test Cost Center - _TC", - "description": "S&H Education Cess", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 1, - "row_id": 3 - }, - { - "account_head": "_Test Account CST - _TC", - "charge_type": "On Previous Row Total", - "cost_center": "_Test Cost Center - _TC", - "description": "CST", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 2, - "row_id": 5 - }, - { - "account_head": "_Test Account VAT - _TC", - "charge_type": "On Net Total", - "cost_center": "_Test Cost Center - _TC", - "description": "VAT", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": 12.5 - }, - { - "account_head": "_Test Account Discount - _TC", - "charge_type": "On Previous Row Total", - "cost_center": "_Test Cost Center - _TC", - "description": "Discount", - "doctype": "Sales Taxes and Charges", - "parentfield": "taxes", - "rate": -10, - "row_id": 7 - } - ], - "title": "_Test India Tax Master" - }, - { - "company": "_Test Company", - "doctype": "Sales Taxes and Charges Template", - "taxes": [ - { - "account_head": "_Test Account VAT - _TC", - "charge_type": "On Net Total", - "description": "VAT", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 12 - }, - { - "account_head": "_Test Account Service Tax - _TC", - "charge_type": "On Net Total", - "description": "Service Tax", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 4 - } - ], - "title": "_Test Sales Taxes and Charges Template - Rest of the World" - }, - { - "company": "_Test Company", - "doctype": "Sales Taxes and Charges Template", - "taxes": [ - { - "account_head": "_Test Account VAT - _TC", - "charge_type": "On Net Total", - "description": "VAT", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 12 - }, - { - "account_head": "_Test Account Service Tax - _TC", - "charge_type": "On Net Total", - "description": "Service Tax", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 4 - } - ], - "title": "_Test Sales Taxes and Charges Template 1" - }, - { - "company": "_Test Company", - "doctype": "Sales Taxes and Charges Template", - "taxes": [ - { - "account_head": "_Test Account VAT - _TC", - "charge_type": "On Net Total", - "description": "VAT", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 12 - }, - { - "account_head": "_Test Account Service Tax - _TC", - "charge_type": "On Net Total", - "description": "Service Tax", - "doctype": "Sales Taxes and Charges", - "cost_center": "Main - _TC", - "parentfield": "taxes", - "rate": 4 - } - ], - "title": "_Test Sales Taxes and Charges Template 2" - }, - { - "doctype" : "Sales Taxes and Charges Template", - "title": "_Test Tax 1", - "company": "_Test Company", - "taxes":[{ - "charge_type": "Actual", - "account_head": "Sales Expenses - _TC", - "cost_center": "Main - _TC", - "description": "Test Shopping cart taxes with Tax Rule", - "tax_amount": 1000 - }] - }, - { - "doctype" : "Sales Taxes and Charges Template", - "title": "_Test Tax 2", - "company": "_Test Company", - "taxes":[{ - "charge_type": "Actual", - "account_head": "Sales Expenses - _TC", - "cost_center": "Main - _TC", - "description": "Test Shopping cart taxes with Tax Rule", - "tax_amount": 200 - }] - } -] diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.py b/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.py index 1684ca82cbd..6c9c1d8c206 100644 --- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.py +++ b/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.py @@ -2,9 +2,8 @@ # See license.txt import unittest -import frappe -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesTaxesandChargesTemplate(IntegrationTestCase): +class TestSalesTaxesandChargesTemplate(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/share_transfer/test_share_transfer.py b/erpnext/accounts/doctype/share_transfer/test_share_transfer.py index 7cd76cc6b47..a227a9f3059 100644 --- a/erpnext/accounts/doctype/share_transfer/test_share_transfer.py +++ b/erpnext/accounts/doctype/share_transfer/test_share_transfer.py @@ -3,14 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.share_transfer.share_transfer import ShareDontExists - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Share Type", "Shareholder"] +from erpnext.tests.utils import ERPNextTestSuite -class TestShareTransfer(IntegrationTestCase): +class TestShareTransfer(ERPNextTestSuite): def setUp(self): frappe.db.sql("delete from `tabShare Transfer`") frappe.db.sql("delete from `tabShare Balance`") diff --git a/erpnext/accounts/doctype/share_type/test_records.json b/erpnext/accounts/doctype/share_type/test_records.json deleted file mode 100644 index 88cb8c056fe..00000000000 --- a/erpnext/accounts/doctype/share_type/test_records.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "doctype": "Share Type", - "title": "Class A" - }, - { - "doctype": "Share Type", - "title": "Class B" - } -] \ No newline at end of file diff --git a/erpnext/accounts/doctype/share_type/test_share_type.py b/erpnext/accounts/doctype/share_type/test_share_type.py index e6f1f71f4bb..3aa79f53018 100644 --- a/erpnext/accounts/doctype/share_type/test_share_type.py +++ b/erpnext/accounts/doctype/share_type/test_share_type.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestShareType(IntegrationTestCase): +class TestShareType(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/shareholder/test_records.json b/erpnext/accounts/doctype/shareholder/test_records.json deleted file mode 100644 index 39b72d47770..00000000000 --- a/erpnext/accounts/doctype/shareholder/test_records.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "doctype": "Shareholder", - "naming_series": "SH-", - "title": "Iron Man", - "company": "_Test Company" - }, - { - "doctype": "Shareholder", - "naming_series": "SH-", - "title": "Thor", - "company": "_Test Company" - }, - { - "doctype": "Shareholder", - "naming_series": "SH-", - "title": "Hulk", - "company": "_Test Company" - } -] \ No newline at end of file diff --git a/erpnext/accounts/doctype/shareholder/test_shareholder.py b/erpnext/accounts/doctype/shareholder/test_shareholder.py index 3c0f34858f9..4c4cc0b789e 100644 --- a/erpnext/accounts/doctype/shareholder/test_shareholder.py +++ b/erpnext/accounts/doctype/shareholder/test_shareholder.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestShareholder(IntegrationTestCase): +class TestShareholder(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py b/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py index be05f5662db..62d9c7805b1 100644 --- a/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py +++ b/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py @@ -3,16 +3,19 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.shipping_rule.shipping_rule import ( FromGreaterThanToError, ManyBlankToValuesError, OverlappingConditionError, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestShippingRule(IntegrationTestCase): +class TestShippingRule(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Shipping Rule") + def test_from_greater_than_to(self): shipping_rule = frappe.copy_doc(self.globalTestRecords["Shipping Rule"][0]) shipping_rule.name = self.globalTestRecords["Shipping Rule"][0].get("name") diff --git a/erpnext/accounts/doctype/subscription/test_subscription.py b/erpnext/accounts/doctype/subscription/test_subscription.py index 2f1c1742d0b..dbec8be72c6 100644 --- a/erpnext/accounts/doctype/subscription/test_subscription.py +++ b/erpnext/accounts/doctype/subscription/test_subscription.py @@ -3,7 +3,6 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils.data import ( add_days, add_months, @@ -19,20 +18,16 @@ from frappe.utils.data import ( from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.subscription.subscription import get_prorata_factor - -EXTRA_TEST_RECORD_DEPENDENCIES = ("UOM", "Item Group", "Item") +from erpnext.tests.utils import ERPNextTestSuite -class TestSubscription(IntegrationTestCase): +class TestSubscription(ERPNextTestSuite): def setUp(self): make_plans() create_parties() reset_settings() frappe.db.set_value("Company", "_Test Company", "accounts_frozen_till_date", None) - def tearDown(self): - frappe.db.rollback() - def test_create_subscription_with_trial_with_correct_period(self): subscription = create_subscription( trial_period_start=nowdate(), trial_period_end=add_months(nowdate(), 1) @@ -472,7 +467,7 @@ class TestSubscription(IntegrationTestCase): currency = frappe.db.get_value("Sales Invoice", subscription.invoices[0].name, "currency") self.assertEqual(currency, "USD") - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1}, ) diff --git a/erpnext/accounts/doctype/subscription_invoice/test_subscription_invoice.py b/erpnext/accounts/doctype/subscription_invoice/test_subscription_invoice.py index a176a99a9b8..983526fc297 100644 --- a/erpnext/accounts/doctype/subscription_invoice/test_subscription_invoice.py +++ b/erpnext/accounts/doctype/subscription_invoice/test_subscription_invoice.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSubscriptionInvoice(IntegrationTestCase): +class TestSubscriptionInvoice(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/subscription_plan/test_subscription_plan.py b/erpnext/accounts/doctype/subscription_plan/test_subscription_plan.py index 19b9285b1d8..f2ae2ce85b8 100644 --- a/erpnext/accounts/doctype/subscription_plan/test_subscription_plan.py +++ b/erpnext/accounts/doctype/subscription_plan/test_subscription_plan.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSubscriptionPlan(IntegrationTestCase): +class TestSubscriptionPlan(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/subscription_settings/test_subscription_settings.py b/erpnext/accounts/doctype/subscription_settings/test_subscription_settings.py index 5d6607cb0cd..ce9193e1130 100644 --- a/erpnext/accounts/doctype/subscription_settings/test_subscription_settings.py +++ b/erpnext/accounts/doctype/subscription_settings/test_subscription_settings.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSubscriptionSettings(IntegrationTestCase): +class TestSubscriptionSettings(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/tax_category/test_records.json b/erpnext/accounts/doctype/tax_category/test_records.json deleted file mode 100644 index 1bb7f5ed876..00000000000 --- a/erpnext/accounts/doctype/tax_category/test_records.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "doctype": "Tax Category", - "title": "_Test Tax Category 1" - }, - { - "doctype": "Tax Category", - "title": "_Test Tax Category 2" - }, - { - "doctype": "Tax Category", - "title": "_Test Tax Category 3" - } -] diff --git a/erpnext/accounts/doctype/tax_category/test_tax_category.py b/erpnext/accounts/doctype/tax_category/test_tax_category.py index fbe654999f1..3eba2808ddb 100644 --- a/erpnext/accounts/doctype/tax_category/test_tax_category.py +++ b/erpnext/accounts/doctype/tax_category/test_tax_category.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxCategory(IntegrationTestCase): +class TestTaxCategory(ERPNextTestSuite): pass diff --git a/erpnext/accounts/doctype/tax_rule/test_records.json b/erpnext/accounts/doctype/tax_rule/test_records.json deleted file mode 100644 index e80b12f73ea..00000000000 --- a/erpnext/accounts/doctype/tax_rule/test_records.json +++ /dev/null @@ -1,28 +0,0 @@ -[ - { - "doctype": "Tax Rule", - "tax_type" : "Sales", - "sales_tax_template": "_Test Tax 1 - _TC", - "use_for_shopping_cart": 1, - "billing_city": "_Test City", - "billing_state": "Test State", - "billing_country": "India", - "shipping_city": "_Test City", - "shipping_country": "India", - "priority": 1, - "company": "_Test Company" - }, - { - "doctype": "Tax Rule", - "tax_type" : "Sales", - "sales_tax_template": "_Test Tax 2 - _TC", - "use_for_shopping_cart": 0, - "billing_city": "_Test City", - "billing_country": "India", - "shipping_city": "_Test City", - "shipping_state": "Test State", - "shipping_country": "India", - "priority": 2, - "company": "_Test Company" - } -] \ No newline at end of file diff --git a/erpnext/accounts/doctype/tax_rule/test_tax_rule.py b/erpnext/accounts/doctype/tax_rule/test_tax_rule.py index 2602ea14861..ed3d004cc7e 100644 --- a/erpnext/accounts/doctype/tax_rule/test_tax_rule.py +++ b/erpnext/accounts/doctype/tax_rule/test_tax_rule.py @@ -3,25 +3,16 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.tax_rule.tax_rule import ConflictingTaxRule, get_tax_template from erpnext.crm.doctype.opportunity.opportunity import make_quotation from erpnext.crm.doctype.opportunity.test_opportunity import make_opportunity +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxRule(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - frappe.db.set_single_value("Shopping Cart Settings", "enabled", 0) - - @classmethod - def tearDownClass(cls): - frappe.db.sql("delete from `tabTax Rule`") - +class TestTaxRule(ERPNextTestSuite): def setUp(self): - frappe.db.sql("delete from `tabTax Rule`") + frappe.db.set_single_value("Shopping Cart Settings", "enabled", 0) def test_conflict(self): tax_rule1 = make_tax_rule( diff --git a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py index a9773ceae60..66dc090f7c7 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py @@ -5,28 +5,21 @@ import datetime import frappe from frappe.custom.doctype.custom_field.custom_field import create_custom_fields -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_months, today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.utils import get_fiscal_year from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_invoice - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Supplier Group", "Customer Group"] +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxWithholdingCategory(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestTaxWithholdingCategory(ERPNextTestSuite): + def setUp(self): # create relevant supplier, etc create_records() create_tax_withholding_category_records() make_pan_no_field() - def tearDown(self): - frappe.db.rollback() - def validate_tax_withholding_entries(self, doctype, docname, expected_entries): """Validate tax withholding entries for a document""" entries = frappe.get_all( @@ -1036,6 +1029,7 @@ class TestTaxWithholdingCategory(IntegrationTestCase): self.cleanup_invoices(invoices) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_multiple_items": 1}) def test_tds_calculation_on_net_total_partial_tds(self): self.setup_party_with_category("Supplier", "Test TDS Supplier4", "Cumulative Threshold TDS") invoices = [] @@ -2049,7 +2043,7 @@ class TestTaxWithholdingCategory(IntegrationTestCase): self.assertEqual(pi2.taxes, []) self.assertEqual(payment.taxes[0].tax_amount, 6000) - @IntegrationTestCase.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) def test_tds_payment_entry_cancellation(self): """ Test payment entry cancellation clears withholding references from matched entries @@ -2227,7 +2221,7 @@ class TestTaxWithholdingCategory(IntegrationTestCase): self.validate_tax_withholding_entries("Purchase Invoice", pi1.name, expected_entries) self.cleanup_invoices(invoices) - @IntegrationTestCase.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1}) def test_tds_purchase_invoice_cancellation(self): """ Test that after cancellation, new documents get automatically adjusted against remaining entries diff --git a/erpnext/accounts/doctype/tax_withholding_entry/test_tax_withholding_entry.py b/erpnext/accounts/doctype/tax_withholding_entry/test_tax_withholding_entry.py index 8a09f46e079..3f52eb77ee5 100644 --- a/erpnext/accounts/doctype/tax_withholding_entry/test_tax_withholding_entry.py +++ b/erpnext/accounts/doctype/tax_withholding_entry/test_tax_withholding_entry.py @@ -1,17 +1,10 @@ # Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -# import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] +from erpnext.tests.utils import ERPNextTestSuite -class IntegrationTestTaxWithholdingEntry(IntegrationTestCase): +class IntegrationTestTaxWithholdingEntry(ERPNextTestSuite): """ Integration tests for TaxWithholdingEntry. Use this class for testing interactions between multiple components. diff --git a/erpnext/accounts/doctype/tax_withholding_group/test_tax_withholding_group.py b/erpnext/accounts/doctype/tax_withholding_group/test_tax_withholding_group.py index 268febe3d7e..eacdf7f36fc 100644 --- a/erpnext/accounts/doctype/tax_withholding_group/test_tax_withholding_group.py +++ b/erpnext/accounts/doctype/tax_withholding_group/test_tax_withholding_group.py @@ -1,17 +1,10 @@ # Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -# import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] +from erpnext.tests.utils import ERPNextTestSuite -class IntegrationTestTaxWithholdingGroup(IntegrationTestCase): +class IntegrationTestTaxWithholdingGroup(ERPNextTestSuite): """ Integration tests for TaxWithholdingGroup. Use this class for testing interactions between multiple components. diff --git a/erpnext/accounts/doctype/unreconcile_payment/test_unreconcile_payment.py b/erpnext/accounts/doctype/unreconcile_payment/test_unreconcile_payment.py index acd30cc47b7..7f931b7556e 100644 --- a/erpnext/accounts/doctype/unreconcile_payment/test_unreconcile_payment.py +++ b/erpnext/accounts/doctype/unreconcile_payment/test_unreconcile_payment.py @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry @@ -12,9 +11,10 @@ from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order +from erpnext.tests.utils import ERPNextTestSuite -class TestUnreconcilePayment(AccountsTestMixin, IntegrationTestCase): +class TestUnreconcilePayment(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() @@ -23,9 +23,6 @@ class TestUnreconcilePayment(AccountsTestMixin, IntegrationTestCase): self.create_item() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_sales_invoice(self, do_not_submit=False): si = create_sales_invoice( item=self.item, diff --git a/erpnext/accounts/report/account_balance/test_account_balance.py b/erpnext/accounts/report/account_balance/test_account_balance.py index 37d6f292fb6..f166421b0de 100644 --- a/erpnext/accounts/report/account_balance/test_account_balance.py +++ b/erpnext/accounts/report/account_balance/test_account_balance.py @@ -1,14 +1,14 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import getdate from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.account_balance.account_balance import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountBalance(IntegrationTestCase): +class TestAccountBalance(ERPNextTestSuite): def test_account_balance(self): frappe.db.sql("delete from `tabSales Invoice` where company='_Test Company 2'") frappe.db.sql("delete from `tabGL Entry` where company='_Test Company 2'") diff --git a/erpnext/accounts/report/accounts_payable/test_accounts_payable.py b/erpnext/accounts/report/accounts_payable/test_accounts_payable.py index 8da40ea3aa4..87a4b989661 100644 --- a/erpnext/accounts/report/accounts_payable/test_accounts_payable.py +++ b/erpnext/accounts/report/accounts_payable/test_accounts_payable.py @@ -1,13 +1,13 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, today from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.report.accounts_payable.accounts_payable import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountsPayable(AccountsTestMixin, IntegrationTestCase): +class TestAccountsPayable(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() @@ -15,9 +15,6 @@ class TestAccountsPayable(AccountsTestMixin, IntegrationTestCase): self.create_supplier(currency="USD", supplier_name="Test Supplier2") self.create_usd_payable_account() - def tearDown(self): - frappe.db.rollback() - def test_accounts_payable_for_foreign_currency_supplier(self): pi = self.create_purchase_invoice(do_not_submit=True) pi.currency = "USD" diff --git a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py index 907840e8ff4..d38ce924cf0 100644 --- a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py @@ -1,6 +1,5 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, flt, getdate, today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -8,9 +7,10 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sal from erpnext.accounts.report.accounts_receivable.accounts_receivable import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): +class TestAccountsReceivable(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() @@ -18,9 +18,6 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): self.create_usd_receivable_account() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_sales_invoice(self, no_payment_schedule=False, do_not_submit=False, **args): frappe.set_user("Administrator") si = create_sales_invoice( @@ -199,7 +196,7 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): row = report[1] self.assertTrue(len(row) == 0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1}, ) @@ -448,7 +445,7 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): ], ) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, ) diff --git a/erpnext/accounts/report/accounts_receivable_summary/test_accounts_receivable_summary.py b/erpnext/accounts/report/accounts_receivable_summary/test_accounts_receivable_summary.py index d357c0d6273..96fa4ae8b64 100644 --- a/erpnext/accounts/report/accounts_receivable_summary/test_accounts_receivable_summary.py +++ b/erpnext/accounts/report/accounts_receivable_summary/test_accounts_receivable_summary.py @@ -1,14 +1,14 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.accounts_receivable_summary.accounts_receivable_summary import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): +class TestAccountsReceivable(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.maxDiff = None self.create_company() @@ -16,9 +16,6 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): self.create_item() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def test_01_receivable_summary_output(self): """ Test for Invoices, Paid, Advance and Outstanding @@ -112,7 +109,7 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): self.assertEqual(len(rpt_output), 1) self.assertDictEqual(rpt_output[0], expected_data) - @IntegrationTestCase.change_settings("Selling Settings", {"cust_master_name": "Naming Series"}) + @ERPNextTestSuite.change_settings("Selling Settings", {"cust_master_name": "Naming Series"}) def test_02_various_filters_and_output(self): filters = { "company": self.company, diff --git a/erpnext/accounts/report/balance_sheet/test_balance_sheet.py b/erpnext/accounts/report/balance_sheet/test_balance_sheet.py index cf225ba39da..dce9d8ab0fa 100644 --- a/erpnext/accounts/report/balance_sheet/test_balance_sheet.py +++ b/erpnext/accounts/report/balance_sheet/test_balance_sheet.py @@ -2,18 +2,16 @@ # MIT License. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils.data import today from erpnext.accounts.report.balance_sheet.balance_sheet import execute +from erpnext.tests.utils import ERPNextTestSuite COMPANY = "_Test Company 6" COMPANY_SHORT_NAME = "_TC6" -EXTRA_TEST_RECORD_DEPENDENCIES = ["Company"] - -class TestBalanceSheet(IntegrationTestCase): +class TestBalanceSheet(ERPNextTestSuite): def test_balance_sheet(self): frappe.db.sql(f"delete from `tabJournal Entry` where company='{COMPANY}'") frappe.db.sql(f"delete from `tabGL Entry` where company='{COMPANY}'") diff --git a/erpnext/accounts/report/bank_reconciliation_statement/test_bank_reconciliation_statement.py b/erpnext/accounts/report/bank_reconciliation_statement/test_bank_reconciliation_statement.py index 1fed7a43f7d..2e73a001107 100644 --- a/erpnext/accounts/report/bank_reconciliation_statement/test_bank_reconciliation_statement.py +++ b/erpnext/accounts/report/bank_reconciliation_statement/test_bank_reconciliation_statement.py @@ -2,15 +2,14 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.report.bank_reconciliation_statement.bank_reconciliation_statement import ( execute, ) -from erpnext.tests.utils import if_lending_app_installed +from erpnext.tests.utils import ERPNextTestSuite, if_lending_app_installed -class TestBankReconciliationStatement(IntegrationTestCase): +class TestBankReconciliationStatement(ERPNextTestSuite): @if_lending_app_installed def test_loan_entries_in_bank_reco_statement(self): from lending.loan_management.doctype.loan.test_loan import create_loan_accounts diff --git a/erpnext/accounts/report/consolidated_trial_balance/test_consolidated_trial_balance.py b/erpnext/accounts/report/consolidated_trial_balance/test_consolidated_trial_balance.py index d9d74f483b0..3166abf4061 100644 --- a/erpnext/accounts/report/consolidated_trial_balance/test_consolidated_trial_balance.py +++ b/erpnext/accounts/report/consolidated_trial_balance/test_consolidated_trial_balance.py @@ -3,36 +3,21 @@ import frappe from frappe import _ -from frappe.tests import IntegrationTestCase from frappe.utils import flt, today from erpnext.accounts.report.consolidated_trial_balance.consolidated_trial_balance import execute from erpnext.setup.utils import get_exchange_rate +from erpnext.tests.utils import ERPNextTestSuite class ForeignCurrencyTranslationReserveNotFoundError(frappe.ValidationError): pass -class TestConsolidatedTrialBalance(IntegrationTestCase): - @classmethod - def setUpClass(cls): - from erpnext.accounts.report.trial_balance.test_trial_balance import create_company +class TestConsolidatedTrialBalance(ERPNextTestSuite): + def setUp(self): from erpnext.accounts.utils import get_fiscal_year - # Group Company - create_company(company_name="Parent Group Company India", is_group=1) - - create_company(company_name="Child Company India", parent_company="Parent Group Company India") - - # Child Company with different currency - create_company( - company_name="Child Company US", - country="United States", - currency="USD", - parent_company="Parent Group Company India", - ) - create_journal_entry( company="Parent Group Company India", acc1="Marketing Expenses - PGCI", @@ -48,7 +33,7 @@ class TestConsolidatedTrialBalance(IntegrationTestCase): company="Child Company US", acc1="Marketing Expenses - CCU", acc2="Cash - CCU", amount=1000 ) - cls.fiscal_year = get_fiscal_year(today(), company="Parent Group Company India")[0] + self.fiscal_year = get_fiscal_year(today(), company="Parent Group Company India")[0] def test_single_company_report(self): filters = frappe._dict({"company": ["Parent Group Company India"], "fiscal_year": self.fiscal_year}) diff --git a/erpnext/accounts/report/customer_ledger_summary/test_customer_ledger_summary.py b/erpnext/accounts/report/customer_ledger_summary/test_customer_ledger_summary.py index 14e88afca39..0b114dd96d2 100644 --- a/erpnext/accounts/report/customer_ledger_summary/test_customer_ledger_summary.py +++ b/erpnext/accounts/report/customer_ledger_summary/test_customer_ledger_summary.py @@ -1,25 +1,22 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase -from frappe.utils import add_days, flt, getdate, today +from frappe.utils import today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.customer_ledger_summary.customer_ledger_summary import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.controllers.sales_and_purchase_return import make_return_doc +from erpnext.tests.utils import ERPNextTestSuite -class TestCustomerLedgerSummary(AccountsTestMixin, IntegrationTestCase): +class TestCustomerLedgerSummary(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.create_item() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_sales_invoice(self, do_not_submit=False, **args): si = create_sales_invoice( item=self.item, diff --git a/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py b/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py index fcd9075a30f..15e216e333a 100644 --- a/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py +++ b/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py @@ -1,6 +1,5 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate from erpnext.accounts.doctype.account.test_account import create_account @@ -11,9 +10,10 @@ from erpnext.accounts.report.deferred_revenue_and_expense.deferred_revenue_and_e ) from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.accounts.utils import get_fiscal_year +from erpnext.tests.utils import ERPNextTestSuite -class TestDeferredRevenueAndExpense(IntegrationTestCase, AccountsTestMixin): +class TestDeferredRevenueAndExpense(ERPNextTestSuite, AccountsTestMixin): maxDiff = None def clear_old_entries(self): @@ -67,10 +67,7 @@ class TestDeferredRevenueAndExpense(IntegrationTestCase, AccountsTestMixin): self.setup_deferred_accounts_and_items() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - - @IntegrationTestCase.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) def test_deferred_revenue(self): self.create_item("_Test Internet Subscription", 0, self.warehouse, self.company) item = frappe.get_doc("Item", self.item) @@ -137,7 +134,7 @@ class TestDeferredRevenueAndExpense(IntegrationTestCase, AccountsTestMixin): ] self.assertEqual(report.period_total, expected) - @IntegrationTestCase.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) def test_deferred_expense(self): self.create_item("_Test Office Desk", 0, self.warehouse, self.company) item = frappe.get_doc("Item", self.item) @@ -207,7 +204,7 @@ class TestDeferredRevenueAndExpense(IntegrationTestCase, AccountsTestMixin): ] self.assertEqual(report.period_total, expected) - @IntegrationTestCase.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"}) def test_zero_months(self): self.create_item("_Test Internet Subscription", 0, self.warehouse, self.company) item = frappe.get_doc("Item", self.item) @@ -272,7 +269,7 @@ class TestDeferredRevenueAndExpense(IntegrationTestCase, AccountsTestMixin): ] self.assertEqual(report.period_total, expected) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"book_deferred_entries_based_on": "Months", "book_deferred_entries_via_journal_entry": 0}, ) diff --git a/erpnext/accounts/report/general_and_payment_ledger_comparison/test_general_and_payment_ledger_comparison.py b/erpnext/accounts/report/general_and_payment_ledger_comparison/test_general_and_payment_ledger_comparison.py index 8c33bc90965..dd836a6891e 100644 --- a/erpnext/accounts/report/general_and_payment_ledger_comparison/test_general_and_payment_ledger_comparison.py +++ b/erpnext/accounts/report/general_and_payment_ledger_comparison/test_general_and_payment_ledger_comparison.py @@ -1,6 +1,5 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice @@ -8,16 +7,14 @@ from erpnext.accounts.report.general_and_payment_ledger_comparison.general_and_p execute, ) from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestGeneralAndPaymentLedger(IntegrationTestCase, AccountsTestMixin): +class TestGeneralAndPaymentLedger(ERPNextTestSuite, AccountsTestMixin): def setUp(self): self.create_company() self.cleanup() - def tearDown(self): - frappe.db.rollback() - def cleanup(self): doctypes = [] doctypes.append(qb.DocType("GL Entry")) diff --git a/erpnext/accounts/report/general_ledger/test_general_ledger.py b/erpnext/accounts/report/general_ledger/test_general_ledger.py index 24280d4d620..8f558467192 100644 --- a/erpnext/accounts/report/general_ledger/test_general_ledger.py +++ b/erpnext/accounts/report/general_ledger/test_general_ledger.py @@ -3,15 +3,15 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import flt, today from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.general_ledger.general_ledger import execute from erpnext.controllers.sales_and_purchase_return import make_return_doc +from erpnext.tests.utils import ERPNextTestSuite -class TestGeneralLedger(IntegrationTestCase): +class TestGeneralLedger(ERPNextTestSuite): def setUp(self): self.company = "_Test Company" self.clear_old_entries() diff --git a/erpnext/accounts/report/gross_profit/test_gross_profit.py b/erpnext/accounts/report/gross_profit/test_gross_profit.py index bf52e127544..ac1ca89b5e4 100644 --- a/erpnext/accounts/report/gross_profit/test_gross_profit.py +++ b/erpnext/accounts/report/gross_profit/test_gross_profit.py @@ -1,6 +1,5 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, flt, get_first_day, get_last_day, nowdate from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_delivery_note, make_sales_return @@ -10,9 +9,10 @@ from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestGrossProfit(IntegrationTestCase): +class TestGrossProfit(ERPNextTestSuite): def setUp(self): self.create_company() self.create_item() @@ -21,9 +21,6 @@ class TestGrossProfit(IntegrationTestCase): self.create_sales_invoice() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_company(self): company_name = "_Test Gross Profit" abbr = "_GP" @@ -391,6 +388,7 @@ class TestGrossProfit(IntegrationTestCase): report_output = {k: v for k, v in gp_entry[0].items() if k in expected_entry} self.assertEqual(report_output, expected_entry) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": True}) def test_crnote_against_invoice_with_multiple_instances_of_same_item(self): """ Item Qty for Sales Invoices with multiple instances of same item go in the -ve. Ideally, the credit noteshould cancel out the invoice items. diff --git a/erpnext/accounts/report/item_wise_purchase_register/test_item_wise_purchase_register.py b/erpnext/accounts/report/item_wise_purchase_register/test_item_wise_purchase_register.py index 5a2fe7e23ce..eed45ea60bb 100644 --- a/erpnext/accounts/report/item_wise_purchase_register/test_item_wise_purchase_register.py +++ b/erpnext/accounts/report/item_wise_purchase_register/test_item_wise_purchase_register.py @@ -1,21 +1,18 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import getdate, today from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.report.item_wise_purchase_register.item_wise_purchase_register import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestItemWisePurchaseRegister(AccountsTestMixin, IntegrationTestCase): +class TestItemWisePurchaseRegister(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_supplier() self.create_item() - def tearDown(self): - frappe.db.rollback() - def create_purchase_invoice(self, do_not_submit=False): pi = make_purchase_invoice( item=self.item, diff --git a/erpnext/accounts/report/item_wise_sales_register/test_item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/test_item_wise_sales_register.py index 09a2b4a46d6..689edeac1c4 100644 --- a/erpnext/accounts/report/item_wise_sales_register/test_item_wise_sales_register.py +++ b/erpnext/accounts/report/item_wise_sales_register/test_item_wise_sales_register.py @@ -1,21 +1,18 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import getdate, today from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.item_wise_sales_register.item_wise_sales_register import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestItemWiseSalesRegister(AccountsTestMixin, IntegrationTestCase): +class TestItemWiseSalesRegister(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.create_item() - def tearDown(self): - frappe.db.rollback() - def create_sales_invoice(self, item=None, taxes=None, do_not_submit=False): si = create_sales_invoice( item=item or self.item, @@ -79,9 +76,13 @@ class TestItemWiseSalesRegister(AccountsTestMixin, IntegrationTestCase): self.assertDictEqual(report_output, expected_result) def test_grouped_report_handles_different_tax_descriptions(self): - self.create_item(item_name="_Test Item Tax Description A") + self.create_item( + item_name="_Test Item Tax Description A", company="_Test Company", warehouse="Stores - _TC" + ) first_item = self.item - self.create_item(item_name="_Test Item Tax Description B") + self.create_item( + item_name="_Test Item Tax Description B", company="_Test Company", warehouse="Stores - _TC" + ) second_item = self.item first_tax_description = "Tax Description A" diff --git a/erpnext/accounts/report/payment_ledger/test_payment_ledger.py b/erpnext/accounts/report/payment_ledger/test_payment_ledger.py index 1225fb70101..00206059672 100644 --- a/erpnext/accounts/report/payment_ledger/test_payment_ledger.py +++ b/erpnext/accounts/report/payment_ledger/test_payment_ledger.py @@ -1,13 +1,13 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.payment_ledger.payment_ledger import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentLedger(IntegrationTestCase): +class TestPaymentLedger(ERPNextTestSuite): def setUp(self): self.create_company() self.cleanup() diff --git a/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py index 4f1a08370a4..90d28033f19 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py +++ b/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py @@ -3,24 +3,21 @@ import frappe from frappe.desk.query_report import export_query -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, getdate, today from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.financial_statements import get_period_list from erpnext.accounts.report.profit_and_loss_statement.profit_and_loss_statement import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestProfitAndLossStatement(AccountsTestMixin, IntegrationTestCase): +class TestProfitAndLossStatement(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.create_item() - def tearDown(self): - frappe.db.rollback() - def create_sales_invoice(self, qty=1, rate=150, no_payment_schedule=False, do_not_submit=False): frappe.set_user("Administrator") si = create_sales_invoice( diff --git a/erpnext/accounts/report/purchase_register/test_purchase_register.py b/erpnext/accounts/report/purchase_register/test_purchase_register.py index 6f61c44db02..400ee899fa1 100644 --- a/erpnext/accounts/report/purchase_register/test_purchase_register.py +++ b/erpnext/accounts/report/purchase_register/test_purchase_register.py @@ -2,13 +2,13 @@ # MIT License. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_months, today from erpnext.accounts.report.purchase_register.purchase_register import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestPurchaseRegister(IntegrationTestCase): +class TestPurchaseRegister(ERPNextTestSuite): def test_purchase_register(self): frappe.db.sql("delete from `tabPurchase Invoice` where company='_Test Company 6'") frappe.db.sql("delete from `tabGL Entry` where company='_Test Company 6'") diff --git a/erpnext/accounts/report/sales_payment_summary/test_sales_payment_summary.py b/erpnext/accounts/report/sales_payment_summary/test_sales_payment_summary.py index 481e9381ff1..da4b78f6987 100644 --- a/erpnext/accounts/report/sales_payment_summary/test_sales_payment_summary.py +++ b/erpnext/accounts/report/sales_payment_summary/test_sales_payment_summary.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -11,25 +10,10 @@ from erpnext.accounts.report.sales_payment_summary.sales_payment_summary import get_mode_of_payment_details, get_mode_of_payments, ) - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Sales Invoice"] +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesPaymentSummary(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - create_records() - pes = frappe.get_all("Payment Entry") - jes = frappe.get_all("Journal Entry") - sis = frappe.get_all("Sales Invoice") - for pe in pes: - frappe.db.set_value("Payment Entry", pe.name, "docstatus", 2) - for je in jes: - frappe.db.set_value("Journal Entry", je.name, "docstatus", 2) - for si in sis: - frappe.db.set_value("Sales Invoice", si.name, "docstatus", 2) - +class TestSalesPaymentSummary(ERPNextTestSuite): def test_get_mode_of_payments(self): filters = get_filters() @@ -95,6 +79,7 @@ class TestSalesPaymentSummary(IntegrationTestCase): mopd = get_mode_of_payment_details(filters) mopd_values = next(iter(mopd.values())) + cc_init_amount = 0 for mopd_value in mopd_values: if mopd_value[0] == "Credit Card": cc_init_amount = mopd_value[1] @@ -111,6 +96,7 @@ class TestSalesPaymentSummary(IntegrationTestCase): mopd = get_mode_of_payment_details(filters) mopd_values = next(iter(mopd.values())) + cc_final_amount = 0 for mopd_value in mopd_values: if mopd_value[0] == "Credit Card": cc_final_amount = mopd_value[1] @@ -148,41 +134,3 @@ def create_sales_invoice_record(qty=1): ], } ) - - -def create_records(): - if frappe.db.exists("Customer", "Prestiga-Biz"): - return - - # customer - frappe.get_doc( - { - "customer_group": "_Test Customer Group", - "customer_name": "Prestiga-Biz", - "customer_type": "Company", - "doctype": "Customer", - "territory": "_Test Territory", - } - ).insert() - - # item - item = frappe.get_doc( - { - "doctype": "Item", - "item_code": "Consulting", - "item_name": "Consulting", - "item_group": "All Item Groups", - "company": "_Test Company", - "is_stock_item": 0, - } - ).insert() - - # item price - frappe.get_doc( - { - "doctype": "Item Price", - "price_list": "Standard Selling", - "item_code": item.item_code, - "price_list_rate": 10000, - } - ).insert() diff --git a/erpnext/accounts/report/sales_register/test_sales_register.py b/erpnext/accounts/report/sales_register/test_sales_register.py index 50f12e52e33..ca284cc636c 100644 --- a/erpnext/accounts/report/sales_register/test_sales_register.py +++ b/erpnext/accounts/report/sales_register/test_sales_register.py @@ -1,22 +1,19 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import getdate, today from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.sales_register.sales_register import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestItemWiseSalesRegister(AccountsTestMixin, IntegrationTestCase): +class TestItemWiseSalesRegister(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() self.create_item() self.create_child_cost_center() - def tearDown(self): - frappe.db.rollback() - def create_child_cost_center(self): cc_name = "South Wing" if frappe.db.exists("Cost Center", cc_name): diff --git a/erpnext/accounts/report/supplier_ledger_summary/test_supplier_ledger_summary.py b/erpnext/accounts/report/supplier_ledger_summary/test_supplier_ledger_summary.py index 376495b5cc9..418d86abb66 100644 --- a/erpnext/accounts/report/supplier_ledger_summary/test_supplier_ledger_summary.py +++ b/erpnext/accounts/report/supplier_ledger_summary/test_supplier_ledger_summary.py @@ -1,22 +1,19 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.report.supplier_ledger_summary.supplier_ledger_summary import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierLedgerSummary(AccountsTestMixin, IntegrationTestCase): +class TestSupplierLedgerSummary(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_supplier() self.create_item() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def create_purchase_invoice(self, do_not_submit=False): frappe.set_user("Administrator") pi = make_purchase_invoice( diff --git a/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py b/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py index 30a5df3fcb2..a2a732e8de6 100644 --- a/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py +++ b/erpnext/accounts/report/tax_withholding_details/test_tax_withholding_details.py @@ -2,7 +2,6 @@ # MIT License. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_to_date, today from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry @@ -14,9 +13,10 @@ from erpnext.accounts.doctype.tax_withholding_category.test_tax_withholding_cate from erpnext.accounts.report.tax_withholding_details.tax_withholding_details import execute from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.accounts.utils import get_fiscal_year +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxWithholdingDetails(AccountsTestMixin, IntegrationTestCase): +class TestTaxWithholdingDetails(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.clear_old_entries() @@ -126,9 +126,6 @@ class TestTaxWithholdingDetails(AccountsTestMixin, IntegrationTestCase): ) self.assertSequenceEqual(voucher_actual_values, voucher_expected_values) - def tearDown(self): - self.clear_old_entries() - def create_tax_accounts(): account_names = ["TCS", "TDS"] diff --git a/erpnext/accounts/report/trial_balance/test_trial_balance.py b/erpnext/accounts/report/trial_balance/test_trial_balance.py index a7922b716e7..42cf62af0a0 100644 --- a/erpnext/accounts/report/trial_balance/test_trial_balance.py +++ b/erpnext/accounts/report/trial_balance/test_trial_balance.py @@ -2,13 +2,13 @@ # MIT License. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.accounts.report.trial_balance.trial_balance import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestTrialBalance(IntegrationTestCase): +class TestTrialBalance(ERPNextTestSuite): def setUp(self): from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center @@ -62,10 +62,6 @@ class TestTrialBalance(IntegrationTestCase): total_row = execute(filters)[1][-1] self.assertEqual(total_row["debit"], total_row["credit"]) - def tearDown(self): - clear_dimension_defaults("Branch") - disable_dimension() - def create_company(**args): args = frappe._dict(args) diff --git a/erpnext/accounts/test/test_reports.py b/erpnext/accounts/test/test_reports.py index c58269dde23..8c27452264c 100644 --- a/erpnext/accounts/test/test_reports.py +++ b/erpnext/accounts/test/test_reports.py @@ -1,8 +1,4 @@ -import unittest - -from frappe.tests import IntegrationTestCase - -from erpnext.tests.utils import ReportFilters, ReportName, execute_script_report +from erpnext.tests.utils import ERPNextTestSuite, ReportFilters, ReportName, execute_script_report DEFAULT_FILTERS = { "company": "_Test Company", @@ -36,7 +32,7 @@ REPORT_FILTER_TEST_CASES: list[tuple[ReportName, ReportFilters]] = [ OPTIONAL_FILTERS = {} -class TestReports(IntegrationTestCase): +class TestReports(ERPNextTestSuite): def test_execute_all_accounts_reports(self): """Test that all script report in stock modules are executable with supported filters""" for report, filter in REPORT_FILTER_TEST_CASES: diff --git a/erpnext/accounts/test/test_utils.py b/erpnext/accounts/test/test_utils.py index fd2dc61096e..eddd30b68b6 100644 --- a/erpnext/accounts/test/test_utils.py +++ b/erpnext/accounts/test/test_utils.py @@ -2,7 +2,6 @@ import unittest import frappe from frappe.test_runner import make_test_objects -from frappe.tests import IntegrationTestCase from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice @@ -16,18 +15,10 @@ from erpnext.accounts.utils import ( from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestUtils(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - make_test_objects("Address", ADDRESS_RECORDS) - - @classmethod - def tearDownClass(cls): - frappe.db.rollback() - +class TestUtils(ERPNextTestSuite): def test_get_party_shipping_address(self): address = get_party_shipping_address("Customer", "_Test Customer 1") self.assertEqual(address, "_Test Billing Address 2 Title-Billing") @@ -162,45 +153,3 @@ class TestUtils(IntegrationTestCase): self.assertEqual(get_zero_cutoff(None), 0.005) self.assertEqual(get_zero_cutoff("EUR"), 0.005) self.assertEqual(get_zero_cutoff("BHD"), 0.0005) - - -ADDRESS_RECORDS = [ - { - "doctype": "Address", - "address_type": "Billing", - "address_line1": "Address line 1", - "address_title": "_Test Billing Address Title", - "city": "Lagos", - "country": "Nigeria", - "links": [{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}], - }, - { - "doctype": "Address", - "address_type": "Shipping", - "address_line1": "Address line 2", - "address_title": "_Test Shipping Address 1 Title", - "city": "Lagos", - "country": "Nigeria", - "links": [{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}], - }, - { - "doctype": "Address", - "address_type": "Shipping", - "address_line1": "Address line 3", - "address_title": "_Test Shipping Address 2 Title", - "city": "Lagos", - "country": "Nigeria", - "is_shipping_address": "1", - "links": [{"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"}], - }, - { - "doctype": "Address", - "address_type": "Billing", - "address_line1": "Address line 4", - "address_title": "_Test Billing Address 2 Title", - "city": "Lagos", - "country": "Nigeria", - "is_shipping_address": "1", - "links": [{"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"}], - }, -] diff --git a/erpnext/accounts/test_party.py b/erpnext/accounts/test_party.py index 986a5b5d680..0f477103da4 100644 --- a/erpnext/accounts/test_party.py +++ b/erpnext/accounts/test_party.py @@ -1,10 +1,10 @@ import frappe -from frappe.tests import IntegrationTestCase from erpnext.accounts.party import get_default_price_list +from erpnext.tests.utils import ERPNextTestSuite -class PartyTestCase(IntegrationTestCase): +class PartyTestCase(ERPNextTestSuite): def test_get_default_price_list_should_return_none_for_invalid_group(self): customer = frappe.get_doc( { diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 62e532f322f..852a28f9948 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import ( add_days, add_months, @@ -37,21 +36,14 @@ from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_invoice as make_invoice, ) from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class AssetSetup(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class AssetSetup(ERPNextTestSuite): + def setUp(self): set_depreciation_settings_in_company() - create_asset_data() enable_cwip_accounting("Computers") make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location") - frappe.db.sql("delete from `tabTax Rule`") - - @classmethod - def tearDownClass(cls): - frappe.db.rollback() class TestAsset(AssetSetup): @@ -826,18 +818,9 @@ class TestAsset(AssetSetup): class TestDepreciationMethods(AssetSetup): - @classmethod - def setUpClass(cls): - super().setUpClass() - - cls._old_float_precision = frappe.db.get_single_value("System Settings", "float_precision") + def setUp(self): frappe.db.set_single_value("System Settings", "float_precision", 2) - @classmethod - def tearDownClass(cls): - frappe.db.set_single_value("System Settings", "float_precision", cls._old_float_precision) - super().tearDownClass() - def test_schedule_for_straight_line_method(self): asset = create_asset( calculate_depreciation=1, @@ -1906,31 +1889,9 @@ def get_gl_entries(doctype, docname): ) -def create_asset_data(): - if not frappe.db.exists("Asset Category", "Computers"): - create_asset_category() - - if not frappe.db.exists("Item", "Macbook Pro"): - create_fixed_asset_item() - - if not frappe.db.exists("Location", "Test Location"): - frappe.get_doc({"doctype": "Location", "location_name": "Test Location"}).insert() - - if not frappe.db.exists("Finance Book", "Test Finance Book 1"): - frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 1"}).insert() - - if not frappe.db.exists("Finance Book", "Test Finance Book 2"): - frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 2"}).insert() - - if not frappe.db.exists("Finance Book", "Test Finance Book 3"): - frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 3"}).insert() - - def create_asset(**args): args = frappe._dict(args) - create_asset_data() - asset = frappe.get_doc( { "doctype": "Asset", diff --git a/erpnext/assets/doctype/asset_activity/test_asset_activity.py b/erpnext/assets/doctype/asset_activity/test_asset_activity.py index 1c7d472c88b..0344c7d984b 100644 --- a/erpnext/assets/doctype/asset_activity/test_asset_activity.py +++ b/erpnext/assets/doctype/asset_activity/test_asset_activity.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestAssetActivity(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestAssetActivity(ERPNextTestSuite): pass diff --git a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py index 914b87b728f..f245ac4f0a2 100644 --- a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py +++ b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py @@ -3,13 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase -from frappe.utils import cint, flt, getdate, now_datetime +from frappe.utils import cint, flt, now_datetime from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries from erpnext.assets.doctype.asset.test_asset import ( create_asset, - create_asset_data, create_fixed_asset_item, set_depreciation_settings_in_company, ) @@ -21,12 +19,12 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_pu from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle import ( make_serial_batch_bundle, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetCapitalization(IntegrationTestCase): +class TestAssetCapitalization(ERPNextTestSuite): def setUp(self): set_depreciation_settings_in_company() - create_asset_data() create_asset_capitalization_data() frappe.db.sql("delete from `tabTax Rule`") diff --git a/erpnext/assets/doctype/asset_category/test_asset_category.py b/erpnext/assets/doctype/asset_category/test_asset_category.py index 0f903c7f03a..9f1e6821b43 100644 --- a/erpnext/assets/doctype/asset_category/test_asset_category.py +++ b/erpnext/assets/doctype/asset_category/test_asset_category.py @@ -3,10 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.assets.doctype.asset.test_asset import create_asset +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetCategory(IntegrationTestCase): +class TestAssetCategory(ERPNextTestSuite): def test_mandatory_fields(self): asset_category = frappe.new_doc("Asset Category") asset_category.asset_category_name = "Computers" diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py index 824c7cbba1f..449f6091d01 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/test_asset_depreciation_schedule.py @@ -2,14 +2,13 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase -from frappe.utils import cstr, date_diff, flt, getdate +from frappe.utils import cstr, flt, getdate from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.assets.doctype.asset.depreciation import ( post_depreciation_entries, ) -from erpnext.assets.doctype.asset.test_asset import create_asset, create_asset_data +from erpnext.assets.doctype.asset.test_asset import create_asset from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( get_asset_depr_schedule_doc, get_depr_schedule, @@ -18,12 +17,10 @@ from erpnext.assets.doctype.asset_repair.test_asset_repair import create_asset_r from erpnext.assets.doctype.asset_value_adjustment.test_asset_value_adjustment import ( make_asset_value_adjustment, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetDepreciationSchedule(IntegrationTestCase): - def setUp(self): - create_asset_data() - +class TestAssetDepreciationSchedule(ERPNextTestSuite): def test_throw_error_if_another_asset_depr_schedule_exist(self): asset = create_asset(item_code="Macbook Pro", calculate_depreciation=1, submit=1) @@ -815,7 +812,6 @@ class TestAssetDepreciationSchedule(IntegrationTestCase): def test_depreciation_on_return_of_sold_asset(self): from erpnext.controllers.sales_and_purchase_return import make_return_doc - create_asset_data() asset = create_asset(item_code="Macbook Pro", calculate_depreciation=1, submit=1) post_depreciation_entries(getdate("2021-09-30")) diff --git a/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py b/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py index 391872c8438..7077789e387 100644 --- a/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py +++ b/erpnext/assets/doctype/asset_maintenance/test_asset_maintenance.py @@ -3,14 +3,14 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, get_last_day, nowdate from erpnext.assets.doctype.asset_maintenance.asset_maintenance import calculate_next_due_date from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetMaintenance(IntegrationTestCase): +class TestAssetMaintenance(ERPNextTestSuite): def setUp(self): set_depreciation_settings_in_company() self.pr = make_purchase_receipt( diff --git a/erpnext/assets/doctype/asset_maintenance/test_records.json b/erpnext/assets/doctype/asset_maintenance/test_records.json deleted file mode 100644 index 8306fad6cba..00000000000 --- a/erpnext/assets/doctype/asset_maintenance/test_records.json +++ /dev/null @@ -1,68 +0,0 @@ -[ - { - "doctype": "Asset Category", - "asset_category_name": "Equipment", - "total_number_of_depreciations": 3, - "frequency_of_depreciation": 3, - "accounts": [ - { - "company_name": "_Test Company", - "fixed_asset_account": "_Test Fixed Asset - _TC", - "accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC", - "depreciation_expense_account": "_Test Depreciations - _TC" - } - ] - }, - { - "doctype": "Location", - "location_name": "Test Location" - }, - { - "doctype": "Role", - "role_name": "Technician" - }, - { - "doctype": "User", - "email": "marcus@abc.com", - "first_name": "marcus@abc.com", - "new_password": "password", - "roles": [{"doctype": "Has Role", "role": "Technician"}] - }, - { - "doctype": "User", - "email": "thalia@abc.com", - "first_name": "thalia@abc.com", - "new_password": "password", - "roles": [{"doctype": "Has Role", "role": "Technician"}] - }, - { - "doctype": "User", - "email": "mathias@abc.com", - "first_name": "mathias@abc.com", - "new_password": "password", - "roles": [{"doctype": "Has Role", "role": "Technician"}] - }, - { - "doctype": "Asset Maintenance Team", - "maintenance_manager": "marcus@abc.com", - "maintenance_team_name": "Team Awesome", - "company": "_Test Company", - "maintenance_team_members": [ - {"team_member": "marcus@abc.com", "full_name": "marcus@abc.com", "maintenance_role": "Technician"}, - {"team_member": "thalia@abc.com", "full_name": "thalia@abc.com", "maintenance_role": "Technician"}, - {"team_member": "mathias@abc.com", "full_name": "mathias@abc.com", "maintenance_role": "Technician"} - ] - }, - { - "doctype": "Item", - "item_code": "Photocopier", - "item_name": "Photocopier", - "item_group": "All Item Groups", - "company": "_Test Company", - "is_fixed_asset": 1, - "is_stock_item": 0, - "asset_category": "Equipment", - "auto_create_assets": 1, - "asset_naming_series": "ABC.###" - } -] diff --git a/erpnext/assets/doctype/asset_maintenance_log/test_asset_maintenance_log.py b/erpnext/assets/doctype/asset_maintenance_log/test_asset_maintenance_log.py index 6d19f5b17d9..e5f421c94ed 100644 --- a/erpnext/assets/doctype/asset_maintenance_log/test_asset_maintenance_log.py +++ b/erpnext/assets/doctype/asset_maintenance_log/test_asset_maintenance_log.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetMaintenanceLog(IntegrationTestCase): +class TestAssetMaintenanceLog(ERPNextTestSuite): pass diff --git a/erpnext/assets/doctype/asset_maintenance_team/test_asset_maintenance_team.py b/erpnext/assets/doctype/asset_maintenance_team/test_asset_maintenance_team.py index 00441a8368a..6def5ed28b9 100644 --- a/erpnext/assets/doctype/asset_maintenance_team/test_asset_maintenance_team.py +++ b/erpnext/assets/doctype/asset_maintenance_team/test_asset_maintenance_team.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetMaintenanceTeam(IntegrationTestCase): +class TestAssetMaintenanceTeam(ERPNextTestSuite): pass diff --git a/erpnext/assets/doctype/asset_movement/test_asset_movement.py b/erpnext/assets/doctype/asset_movement/test_asset_movement.py index 0cceb011a25..88dd93a93cb 100644 --- a/erpnext/assets/doctype/asset_movement/test_asset_movement.py +++ b/erpnext/assets/doctype/asset_movement/test_asset_movement.py @@ -3,20 +3,19 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, now -from erpnext.assets.doctype.asset.test_asset import create_asset, create_asset_data +from erpnext.assets.doctype.asset.test_asset import create_asset from erpnext.setup.doctype.employee.test_employee import make_employee from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetMovement(IntegrationTestCase): +class TestAssetMovement(ERPNextTestSuite): def setUp(self): frappe.db.set_value( "Company", "_Test Company", "capital_work_in_progress_account", "CWIP Account - _TC" ) - create_asset_data() make_location() def test_movement(self): diff --git a/erpnext/assets/doctype/asset_repair/test_asset_repair.py b/erpnext/assets/doctype/asset_repair/test_asset_repair.py index c56622d6665..1f158e1ea8b 100644 --- a/erpnext/assets/doctype/asset_repair/test_asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/test_asset_repair.py @@ -5,7 +5,6 @@ import unittest import frappe from frappe import qb from frappe.query_builder.functions import Sum -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_months, flt, get_first_day, nowdate, nowtime, today from erpnext.assets.doctype.asset.asset import ( @@ -15,7 +14,6 @@ from erpnext.assets.doctype.asset.asset import ( ) from erpnext.assets.doctype.asset.test_asset import ( create_asset, - create_asset_data, set_depreciation_settings_in_company, ) from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( @@ -26,16 +24,14 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle get_serial_nos_from_bundle, make_serial_batch_bundle, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetRepair(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestAssetRepair(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Stock Entry") set_depreciation_settings_in_company() - create_asset_data() create_item("_Test Stock Item") - frappe.db.sql("delete from `tabTax Rule`") def test_asset_status(self): date = nowdate() diff --git a/erpnext/assets/doctype/asset_shift_allocation/test_asset_shift_allocation.py b/erpnext/assets/doctype/asset_shift_allocation/test_asset_shift_allocation.py index 2764a2cc373..5b1cdaf0277 100644 --- a/erpnext/assets/doctype/asset_shift_allocation/test_asset_shift_allocation.py +++ b/erpnext/assets/doctype/asset_shift_allocation/test_asset_shift_allocation.py @@ -2,25 +2,19 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import cstr from erpnext.assets.doctype.asset.test_asset import create_asset from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( get_depr_schedule, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetShiftAllocation(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class TestAssetShiftAllocation(ERPNextTestSuite): + def setUp(self): create_asset_shift_factors() - @classmethod - def tearDownClass(cls): - frappe.db.rollback() - def test_asset_shift_allocation(self): asset = create_asset( calculate_depreciation=1, diff --git a/erpnext/assets/doctype/asset_shift_factor/test_asset_shift_factor.py b/erpnext/assets/doctype/asset_shift_factor/test_asset_shift_factor.py index 12d68b02c5f..7470e55b6fb 100644 --- a/erpnext/assets/doctype/asset_shift_factor/test_asset_shift_factor.py +++ b/erpnext/assets/doctype/asset_shift_factor/test_asset_shift_factor.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestAssetShiftFactor(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestAssetShiftFactor(ERPNextTestSuite): pass diff --git a/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py b/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py index 1425bb9aa78..4fb9b0a67f6 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py +++ b/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py @@ -3,22 +3,20 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, cstr, get_last_day, getdate, nowdate from erpnext.assets.doctype.asset.asset import get_asset_value_after_depreciation from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries -from erpnext.assets.doctype.asset.test_asset import create_asset_data from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( get_asset_depr_schedule_doc, ) from erpnext.assets.doctype.asset_repair.test_asset_repair import create_asset_repair from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class TestAssetValueAdjustment(IntegrationTestCase): +class TestAssetValueAdjustment(ERPNextTestSuite): def setUp(self): - create_asset_data() frappe.db.set_value( "Company", "_Test Company", "capital_work_in_progress_account", "CWIP Account - _TC" ) diff --git a/erpnext/assets/doctype/location/location.py b/erpnext/assets/doctype/location/location.py index 03d0980b03f..684a15860cd 100644 --- a/erpnext/assets/doctype/location/location.py +++ b/erpnext/assets/doctype/location/location.py @@ -77,7 +77,7 @@ class Location(NestedSet): location = json.loads(self.location) location["features"] = features - self.db_set("location", json.dumps(location), commit=True) + self.db_set("location", json.dumps(location)) def update_ancestor_location_features(self): self_features = set(self.add_child_property()) @@ -105,7 +105,7 @@ class Location(NestedSet): ancestor_features[index] = json.loads(feature) ancestor_doc.set_location_features(features=ancestor_features) - ancestor_doc.db_set("area", ancestor_doc.area + self.area_difference, commit=True) + ancestor_doc.db_set("area", ancestor_doc.area + self.area_difference) def remove_ancestor_location_features(self): for ancestor in self.get_ancestors(): @@ -116,7 +116,7 @@ class Location(NestedSet): ancestor_features[index] = json.loads(feature) ancestor_doc.set_location_features(features=ancestor_features) - ancestor_doc.db_set("area", ancestor_doc.area - self.area, commit=True) + ancestor_doc.db_set("area", ancestor_doc.area - self.area) def add_child_property(self): features = self.get_location_features() diff --git a/erpnext/assets/doctype/location/test_location.py b/erpnext/assets/doctype/location/test_location.py index 8de97138f7b..1222def606e 100644 --- a/erpnext/assets/doctype/location/test_location.py +++ b/erpnext/assets/doctype/location/test_location.py @@ -4,11 +4,12 @@ import json import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestLocation(IntegrationTestCase): - def runTest(self): +class TestLocation(ERPNextTestSuite): + def test_location_features(self): locations = ["Basil Farm", "Division 1", "Field 1", "Block 1"] area = 0 formatted_locations = [] diff --git a/erpnext/assets/doctype/location/test_records.json b/erpnext/assets/doctype/location/test_records.json deleted file mode 100644 index 8a89cf8bdd3..00000000000 --- a/erpnext/assets/doctype/location/test_records.json +++ /dev/null @@ -1,44 +0,0 @@ -[ - { - "doctype": "Location", - "location_name": "Test Location Area", - "is_group": 1, - "is_container": 1 - }, - { - "doctype": "Location", - "location_name": "Basil Farm", - "location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"point_type\":\"circle\",\"radius\":884.5625420736483},\"geometry\":{\"type\":\"Point\",\"coordinates\":[72.875834,19.100566]}}]}", - "parent_location": "Test Location Area", - "parent": "Test Location Area", - "is_group": 1, - "is_container": 1 - }, - { - "doctype": "Location", - "location_name": "Division 1", - "location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"point_type\":\"circle\",\"radius\":542.3424997060739},\"geometry\":{\"type\":\"Point\",\"coordinates\":[72.852359,19.11557]}}]}", - "parent_location": "Basil Farm", - "parent": "Basil Farm", - "is_group": 1, - "is_container": 1 - }, - { - "doctype": "Location", - "location_name": "Field 1", - "location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[72.846758,19.118287],[72.846758,19.121206],[72.850535,19.121206],[72.850535,19.118287],[72.846758,19.118287]]]}}]}", - "parent_location": "Division 1", - "parent": "Division 1", - "is_group": 1, - "is_container": 1 - }, - { - "doctype": "Location", - "location_name": "Block 1", - "location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[72.921495,19.073313],[72.924929,19.068121],[72.934713,19.06585],[72.929392,19.05579],[72.94158,19.056926],[72.951365,19.095213],[72.921495,19.073313]]]}}]}", - "parent_location": "Field 1", - "parent": "Field 1", - "is_group": 0, - "is_container": 1 - } -] \ No newline at end of file diff --git a/erpnext/assets/doctype/maintenance_team_member/test_maintenance_team_member.py b/erpnext/assets/doctype/maintenance_team_member/test_maintenance_team_member.py index a4795c54a56..b53649b822d 100644 --- a/erpnext/assets/doctype/maintenance_team_member/test_maintenance_team_member.py +++ b/erpnext/assets/doctype/maintenance_team_member/test_maintenance_team_member.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestMaintenanceTeamMember(IntegrationTestCase): +class TestMaintenanceTeamMember(ERPNextTestSuite): pass diff --git a/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py b/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py index 66e6456d103..e3909ea619a 100644 --- a/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestBulkTransactionLog(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestBulkTransactionLog(ERPNextTestSuite): pass diff --git a/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/test_bulk_transaction_log_detail.py b/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/test_bulk_transaction_log_detail.py index 6b9b4637ab4..ae35c697c31 100644 --- a/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/test_bulk_transaction_log_detail.py +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/test_bulk_transaction_log_detail.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestBulkTransactionLogDetail(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestBulkTransactionLogDetail(ERPNextTestSuite): pass diff --git a/erpnext/buying/doctype/buying_settings/test_buying_settings.py b/erpnext/buying/doctype/buying_settings/test_buying_settings.py index 04f95dbe745..c583ad6875e 100644 --- a/erpnext/buying/doctype/buying_settings/test_buying_settings.py +++ b/erpnext/buying/doctype/buying_settings/test_buying_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestBuyingSettings(IntegrationTestCase): +class TestBuyingSettings(ERPNextTestSuite): pass diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index f533af61b9e..fe4bb12c3db 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -5,7 +5,7 @@ import json import frappe -from frappe.tests import IntegrationTestCase, change_settings +from frappe.tests import change_settings from frappe.utils import add_days, flt, getdate, nowdate from frappe.utils.data import today @@ -26,9 +26,11 @@ from erpnext.stock.doctype.material_request.test_material_request import make_ma from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_invoice as make_pi_from_pr, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestPurchaseOrder(IntegrationTestCase): +class TestPurchaseOrder(ERPNextTestSuite): + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_multiple_items": 1}) def test_purchase_order_qty(self): po = create_purchase_order(qty=1, do_not_save=True) @@ -540,7 +542,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertRaises(frappe.ValidationError, pr.submit) self.assertRaises(frappe.ValidationError, pi.submit) - @IntegrationTestCase.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) def test_make_purchase_invoice_with_terms(self): po = create_purchase_order(do_not_save=True) @@ -712,7 +714,7 @@ class TestPurchaseOrder(IntegrationTestCase): ) self.assertEqual(due_date, "2023-03-31") - @IntegrationTestCase.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 0}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 0}) def test_terms_are_not_copied_if_automatically_fetch_payment_terms_is_unchecked(self): po = create_purchase_order(do_not_save=1) po.payment_terms_template = "_Test Payment Term Template" @@ -737,7 +739,7 @@ class TestPurchaseOrder(IntegrationTestCase): pi.insert() self.assertTrue(pi.get("payment_schedule")) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"unlink_advance_payment_on_cancelation_of_order": 1} ) def test_advance_payment_entry_unlink_against_purchase_order(self): @@ -785,6 +787,7 @@ class TestPurchaseOrder(IntegrationTestCase): Test "Advance Paid" on Purchase Order, when "Book Advance Payments in Separate Party Account" is enabled and the payment entry linked to the Order is allocated to Purchase Invoice. """ + frappe.flags.is_reverse_depr_entry = False supplier = "_Test Supplier" company = "_Test Company" @@ -810,12 +813,13 @@ class TestPurchaseOrder(IntegrationTestCase): company_doc.book_advance_payments_in_separate_party_account = False company_doc.save() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"unlink_advance_payment_on_cancelation_of_order": 1} ) def test_advance_paid_upon_payment_entry_cancellation(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry + frappe.flags.is_reverse_depr_entry = False supplier = "_Test Supplier USD" company = "_Test Company" @@ -850,6 +854,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertEqual(po_doc.advance_paid, 0) self.assertEqual(po_doc.party_account_currency, "USD") + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_multiple_items": 1}) def test_schedule_date(self): po = create_purchase_order(do_not_submit=True) po.schedule_date = None @@ -906,7 +911,7 @@ class TestPurchaseOrder(IntegrationTestCase): bo.load_from_db() self.assertEqual(bo.items[0].ordered_qty, 5) - @IntegrationTestCase.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) def test_payment_terms_are_fetched_when_creating_purchase_invoice(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import ( create_payment_terms_template, @@ -1145,7 +1150,7 @@ class TestPurchaseOrder(IntegrationTestCase): # Test - 8: Since this PO is now fully subcontracted, creating a new SCO from it should throw error self.assertRaises(frappe.ValidationError, make_subcontracting_order, po.name) - @IntegrationTestCase.change_settings("Buying Settings", {"auto_create_subcontracting_order": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"auto_create_subcontracting_order": 1}) def test_auto_create_subcontracting_order(self): from erpnext.controllers.tests.test_subcontracting_controller import ( make_bom_for_subcontracted_items, @@ -1178,6 +1183,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertTrue(frappe.db.get_value("Subcontracting Order", {"purchase_order": po.name})) def test_purchase_order_advance_payment_status(self): + frappe.flags.is_reverse_depr_entry = False from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request @@ -1237,7 +1243,7 @@ class TestPurchaseOrder(IntegrationTestCase): po.reload() self.assertEqual(po.per_billed, 100) - @IntegrationTestCase.change_settings("Buying Settings", {"allow_zero_qty_in_purchase_order": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_zero_qty_in_purchase_order": 1}) def test_receive_zero_qty_purchase_order(self): """ Test the flow of a Unit Price PO and PR creation against it until completion. @@ -1286,7 +1292,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertEqual(po.per_received, 100.0) self.assertEqual(po.status, "To Bill") - @IntegrationTestCase.change_settings("Buying Settings", {"allow_zero_qty_in_purchase_order": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_zero_qty_in_purchase_order": 1}) def test_bill_zero_qty_purchase_order(self): po = create_purchase_order(qty=0) @@ -1311,7 +1317,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertFalse(po.per_billed) self.assertEqual(po.status, "To Receive and Bill") - @IntegrationTestCase.change_settings("Buying Settings", {"maintain_same_rate": 0}) + @ERPNextTestSuite.change_settings("Buying Settings", {"maintain_same_rate": 0}) def test_purchase_invoice_creation_with_partial_qty(self): po = create_purchase_order(qty=100, rate=10) @@ -1331,6 +1337,7 @@ class TestPurchaseOrder(IntegrationTestCase): self.assertEqual(pi.items[0].qty, 50) def test_multiple_advances_against_purchase_order_are_allocated_across_partial_purchase_invoices(self): + frappe.flags.is_reverse_depr_entry = False # step - 1: create PO po = create_purchase_order(qty=10, rate=10) @@ -1560,6 +1567,3 @@ def get_ordered_qty(item_code="_Test Item", warehouse="_Test Warehouse - _TC"): def get_requested_qty(item_code="_Test Item", warehouse="_Test Warehouse - _TC"): return flt(frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse}, "indented_qty")) - - -EXTRA_TEST_RECORD_DEPENDENCIES = ["BOM", "Item Price", "Warehouse"] diff --git a/erpnext/buying/doctype/purchase_order/test_records.json b/erpnext/buying/doctype/purchase_order/test_records.json deleted file mode 100644 index 4df994a68c6..00000000000 --- a/erpnext/buying/doctype/purchase_order/test_records.json +++ /dev/null @@ -1,36 +0,0 @@ -[ - { - "advance_paid": 0.0, - "buying_price_list": "_Test Price List", - "company": "_Test Company", - "conversion_rate": 1.0, - "currency": "INR", - "doctype": "Purchase Order", - "base_grand_total": 5000.0, - "grand_total": 5000.0, - "is_subcontracted": 0, - "naming_series": "_T-Purchase Order-", - "base_net_total": 5000.0, - "items": [ - { - "base_amount": 5000.0, - "conversion_factor": 1.0, - "description": "_Test Item", - "doctype": "Purchase Order Item", - "item_code": "_Test Item", - "item_name": "_Test Item", - "parentfield": "items", - "qty": 10.0, - "rate": 500.0, - "schedule_date": "2013-03-01", - "stock_uom": "_Test UOM", - "uom": "_Test UOM", - "warehouse": "_Test Warehouse - _TC" - } - ], - "supplier": "_Test Supplier", - "supplier_name": "_Test Supplier", - "transaction_date": "2013-02-12", - "schedule_date": "2013-02-13" - } -] diff --git a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py index 425d172629d..9201f6c4f2d 100644 --- a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py @@ -5,7 +5,7 @@ from urllib.parse import urlparse import frappe -from frappe.tests import IntegrationTestCase, change_settings +from frappe.tests import change_settings from frappe.utils import nowdate from erpnext.buying.doctype.request_for_quotation.request_for_quotation import ( @@ -19,9 +19,10 @@ from erpnext.crm.doctype.opportunity.opportunity import make_request_for_quotati from erpnext.crm.doctype.opportunity.test_opportunity import make_opportunity from erpnext.stock.doctype.item.test_item import make_item from erpnext.templates.pages.rfq import check_supplier_has_docname_access +from erpnext.tests.utils import ERPNextTestSuite -class TestRequestforQuotation(IntegrationTestCase): +class TestRequestforQuotation(ERPNextTestSuite): def test_rfq_qty(self): rfq = make_request_for_quotation(qty=0, do_not_save=True) with self.assertRaises(InvalidQtyError): @@ -222,7 +223,7 @@ class TestRequestforQuotation(IntegrationTestCase): supplier_doc.reload() self.assertTrue(supplier_doc.portal_users[0].user) - @IntegrationTestCase.change_settings("Buying Settings", {"allow_zero_qty_in_request_for_quotation": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_zero_qty_in_request_for_quotation": 1}) def test_supplier_quotation_from_zero_qty_rfq(self): rfq = make_request_for_quotation(qty=0) sq = make_supplier_quotation_from_rfq(rfq.name, for_supplier=rfq.get("suppliers")[0].supplier) @@ -231,7 +232,7 @@ class TestRequestforQuotation(IntegrationTestCase): self.assertEqual(sq.items[0].qty, 0) self.assertEqual(sq.items[0].item_code, rfq.items[0].item_code) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Buying Settings", { "allow_zero_qty_in_request_for_quotation": 1, diff --git a/erpnext/buying/doctype/supplier/test_records.json b/erpnext/buying/doctype/supplier/test_records.json deleted file mode 100644 index 1bb9899cc85..00000000000 --- a/erpnext/buying/doctype/supplier/test_records.json +++ /dev/null @@ -1,50 +0,0 @@ -[ - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier With Template 1", - "supplier_group": "_Test Supplier Group", - "payment_terms": "_Test Payment Term Template 3" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier P", - "supplier_group": "_Test Supplier Group" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier with Country", - "supplier_group": "_Test Supplier Group", - "country": "Greece" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier", - "supplier_group": "_Test Supplier Group" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier 1", - "supplier_group": "_Test Supplier Group" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier 2", - "supplier_group": "_Test Supplier Group" - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier USD", - "supplier_group": "_Test Supplier Group", - "default_currency": "USD", - "accounts": [{ - "company": "_Test Company", - "account": "_Test Payable USD - _TC" - }] - }, - { - "doctype": "Supplier", - "supplier_name": "_Test Supplier With Tax Category", - "supplier_group": "_Test Supplier Group", - "tax_category": "_Test Tax Category 1" - } -] diff --git a/erpnext/buying/doctype/supplier/test_supplier.py b/erpnext/buying/doctype/supplier/test_supplier.py index f3f0ede3e17..663a7b48e46 100644 --- a/erpnext/buying/doctype/supplier/test_supplier.py +++ b/erpnext/buying/doctype/supplier/test_supplier.py @@ -3,18 +3,15 @@ import frappe +from frappe.tests import UnitTestCase from erpnext.accounts.party import get_due_date from erpnext.controllers.website_list_for_contact import get_customers_suppliers from erpnext.exceptions import PartyDisabled - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Payment Term", "Payment Terms Template"] +from erpnext.tests.utils import ERPNextTestSuite -from frappe.tests import IntegrationTestCase - - -class TestSupplier(IntegrationTestCase): +class TestSupplier(ERPNextTestSuite): def test_get_supplier_group_details(self): doc = frappe.new_doc("Supplier Group") doc.supplier_group_name = "_Testing Supplier Group" @@ -175,7 +172,10 @@ def create_supplier(**args): return doc -class TestSupplierPortal(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestSupplierPortal(ERPNextTestSuite): def test_portal_user_can_access_supplier_data(self): supplier = create_supplier() diff --git a/erpnext/buying/doctype/supplier_quotation/test_records.json b/erpnext/buying/doctype/supplier_quotation/test_records.json index 8acac3210d5..1b9b922e3c9 100644 --- a/erpnext/buying/doctype/supplier_quotation/test_records.json +++ b/erpnext/buying/doctype/supplier_quotation/test_records.json @@ -1,31 +1,31 @@ [ { - "buying_price_list": "_Test Price List", - "company": "_Test Company", - "conversion_rate": 1.0, - "currency": "INR", - "doctype": "Supplier Quotation", - "base_grand_total": 5000.0, - "grand_total": 5000.0, - "is_subcontracted": 0, - "naming_series": "_T-Supplier Quotation-", - "base_net_total": 5000.0, + "buying_price_list": "_Test Price List", + "company": "_Test Company", + "conversion_rate": 1.0, + "currency": "INR", + "doctype": "Supplier Quotation", + "base_grand_total": 5000.0, + "grand_total": 5000.0, + "is_subcontracted": 0, + "naming_series": "_T-Supplier Quotation-", + "base_net_total": 5000.0, "items": [ { - "base_amount": 5000.0, - "description": "_Test FG Item", - "doctype": "Supplier Quotation Item", - "item_code": "_Test FG Item", - "item_name": "_Test FG Item", - "parentfield": "items", - "qty": 10.0, - "rate": 500.0, - "uom": "_Test UOM", + "base_amount": 5000.0, + "description": "_Test FG Item", + "doctype": "Supplier Quotation Item", + "item_code": "_Test FG Item", + "item_name": "_Test FG Item", + "parentfield": "items", + "qty": 10.0, + "rate": 500.0, + "uom": "_Test UOM", "warehouse": "_Test Warehouse - _TC" } - ], - "supplier": "_Test Supplier", - "supplier_name": "_Test Supplier", + ], + "supplier": "_Test Supplier", + "supplier_name": "_Test Supplier", "transaction_date": "2013-02-12" } -] \ No newline at end of file +] diff --git a/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py b/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py index 7c2714ba671..c271d34b35d 100644 --- a/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py +++ b/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py @@ -5,14 +5,18 @@ import json import frappe -from frappe.tests import IntegrationTestCase, change_settings +from frappe.tests import change_settings from frappe.utils import add_days, today from erpnext.buying.doctype.supplier_quotation.supplier_quotation import make_purchase_order from erpnext.controllers.accounts_controller import InvalidQtyError, update_child_qty_rate +from erpnext.tests.utils import ERPNextTestSuite -class TestPurchaseOrder(IntegrationTestCase): +class TestPurchaseOrder(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Supplier Quotation") + def test_update_child_supplier_quotation_add_item(self): sq = frappe.copy_doc(self.globalTestRecords["Supplier Quotation"][0]) sq.submit() @@ -166,7 +170,7 @@ class TestPurchaseOrder(IntegrationTestCase): po.insert() - @IntegrationTestCase.change_settings("Buying Settings", {"allow_zero_qty_in_supplier_quotation": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_zero_qty_in_supplier_quotation": 1}) def test_map_purchase_order_from_zero_qty_supplier_quotation(self): sq = frappe.copy_doc(self.globalTestRecords["Supplier Quotation"][0]) sq.items[0].qty = 0 diff --git a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py index a1142715e2c..b42a260d017 100644 --- a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py +++ b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.py @@ -266,8 +266,8 @@ def get_scorecard_date(period, start_date): return end_date -def make_default_records(): - install_variable_docs = [ +def get_default_scorecard_variables(): + return [ { "param_name": "total_accepted_items", "variable_label": "Total Accepted Items", @@ -374,7 +374,10 @@ def make_default_records(): "path": "get_invoiced_qty", }, ] - install_standing_docs = [ + + +def get_default_scorecard_standing(): + return [ { "min_grade": 0.0, "prevent_rfqs": 1, @@ -425,12 +428,17 @@ def make_default_records(): }, ] + +def make_default_records(): + install_variable_docs = get_default_scorecard_variables() for d in install_variable_docs: try: d["doctype"] = "Supplier Scorecard Variable" frappe.get_doc(d).insert() except frappe.NameError: pass + + install_standing_docs = get_default_scorecard_standing() for d in install_standing_docs: try: d["doctype"] = "Supplier Scorecard Standing" diff --git a/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py b/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py index c65ebe2086f..a1d1dfc4709 100644 --- a/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py +++ b/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py @@ -3,10 +3,11 @@ import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierScorecard(IntegrationTestCase): +class TestSupplierScorecard(ERPNextTestSuite): def test_create_scorecard(self): doc = make_supplier_scorecard().insert() self.assertEqual(doc.name, valid_scorecard[0].get("supplier")) diff --git a/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py b/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py index 114ff2b56b3..951d33ed901 100644 --- a/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py +++ b/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py @@ -3,10 +3,11 @@ import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierScorecardCriteria(IntegrationTestCase): +class TestSupplierScorecardCriteria(ERPNextTestSuite): def test_variables_exist(self): delete_test_scorecards() for d in test_good_criteria: diff --git a/erpnext/buying/doctype/supplier_scorecard_period/test_supplier_scorecard_period.py b/erpnext/buying/doctype/supplier_scorecard_period/test_supplier_scorecard_period.py index 2b124dede99..6fd2bc3b0cc 100644 --- a/erpnext/buying/doctype/supplier_scorecard_period/test_supplier_scorecard_period.py +++ b/erpnext/buying/doctype/supplier_scorecard_period/test_supplier_scorecard_period.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierScorecardPeriod(IntegrationTestCase): +class TestSupplierScorecardPeriod(ERPNextTestSuite): pass diff --git a/erpnext/buying/doctype/supplier_scorecard_standing/test_supplier_scorecard_standing.py b/erpnext/buying/doctype/supplier_scorecard_standing/test_supplier_scorecard_standing.py index 32581538b03..8cc89e941fb 100644 --- a/erpnext/buying/doctype/supplier_scorecard_standing/test_supplier_scorecard_standing.py +++ b/erpnext/buying/doctype/supplier_scorecard_standing/test_supplier_scorecard_standing.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierScorecardStanding(IntegrationTestCase): +class TestSupplierScorecardStanding(ERPNextTestSuite): pass diff --git a/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py b/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py index 8f4b2f4ecdf..f390eefcc65 100644 --- a/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py +++ b/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py @@ -3,14 +3,14 @@ import frappe -from frappe.tests import IntegrationTestCase from erpnext.buying.doctype.supplier_scorecard_variable.supplier_scorecard_variable import ( VariablePathNotFound, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestSupplierScorecardVariable(IntegrationTestCase): +class TestSupplierScorecardVariable(ERPNextTestSuite): def test_variable_exist(self): for d in test_existing_variables: my_doc = frappe.get_doc("Supplier Scorecard Variable", d.get("name")) diff --git a/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py b/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py index f344730a7fa..1577bf2cbf6 100644 --- a/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py +++ b/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py @@ -2,8 +2,8 @@ # For license information, please see license.txt -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestProcurementTracker(IntegrationTestCase): +class TestProcurementTracker(ERPNextTestSuite): pass diff --git a/erpnext/buying/report/requested_items_to_order_and_receive/test_requested_items_to_order_and_receive.py b/erpnext/buying/report/requested_items_to_order_and_receive/test_requested_items_to_order_and_receive.py index ca0b1abad0c..38f2d7426ff 100644 --- a/erpnext/buying/report/requested_items_to_order_and_receive/test_requested_items_to_order_and_receive.py +++ b/erpnext/buying/report/requested_items_to_order_and_receive/test_requested_items_to_order_and_receive.py @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, today from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt @@ -11,11 +10,14 @@ from erpnext.buying.report.requested_items_to_order_and_receive.requested_items_ ) from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.material_request.material_request import make_purchase_order +from erpnext.tests.utils import ERPNextTestSuite -class TestRequestedItemsToOrderAndReceive(IntegrationTestCase): +class TestRequestedItemsToOrderAndReceive(ERPNextTestSuite): def setUp(self) -> None: create_item("Test MR Report Item") + self.load_test_records("Material Request") + frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1) self.setup_material_request() # to order and receive self.setup_material_request(order=True, days=1) # to receive (ordered) self.setup_material_request(order=True, receive=True, days=2) # complete (ordered & received) @@ -27,9 +29,6 @@ class TestRequestedItemsToOrderAndReceive(IntegrationTestCase): item_code="Test MR Report Item", ) - def tearDown(self) -> None: - frappe.db.rollback() - def test_date_range(self): data = get_data(self.filters) self.assertEqual(len(data), 2) # MRs today should be fetched diff --git a/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py b/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py index 5a4c8ec6ba0..1b6bf653a77 100644 --- a/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py +++ b/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py @@ -7,7 +7,6 @@ import copy import frappe -from frappe.tests import IntegrationTestCase from erpnext.buying.report.subcontracted_item_to_be_received.subcontracted_item_to_be_received import ( execute, @@ -22,9 +21,10 @@ from erpnext.controllers.tests.test_subcontracting_controller import ( from erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order import ( make_subcontracting_receipt, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestSubcontractedItemToBeReceived(IntegrationTestCase): +class TestSubcontractedItemToBeReceived(ERPNextTestSuite): def test_pending_and_received_qty(self): make_service_item("Subcontracted Service Item 1") service_items = [ diff --git a/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py b/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py index 3553906ae63..ee76c50261d 100644 --- a/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py +++ b/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py @@ -4,7 +4,6 @@ # Decompiled by https://python-decompiler.com import frappe -from frappe.tests import IntegrationTestCase from erpnext.buying.report.subcontracted_raw_materials_to_be_transferred.subcontracted_raw_materials_to_be_transferred import ( execute, @@ -15,9 +14,10 @@ from erpnext.controllers.tests.test_subcontracting_controller import ( make_service_item, ) from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestSubcontractedItemToBeTransferred(IntegrationTestCase): +class TestSubcontractedItemToBeTransferred(ERPNextTestSuite): def test_pending_and_transferred_qty(self): make_service_item("Subcontracted Service Item 1") service_items = [ diff --git a/erpnext/controllers/tests/test_accounts_controller.py b/erpnext/controllers/tests/test_accounts_controller.py index 553a7246fea..6bb9b2f91fc 100644 --- a/erpnext/controllers/tests/test_accounts_controller.py +++ b/erpnext/controllers/tests/test_accounts_controller.py @@ -5,7 +5,6 @@ import frappe from frappe import qb from frappe.query_builder.functions import Sum -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, getdate, nowdate from frappe.utils.data import getdate as convert_to_date @@ -20,6 +19,7 @@ from erpnext.buying.doctype.purchase_order.test_purchase_order import ( ) from erpnext.projects.doctype.project.test_project import make_project from erpnext.stock.doctype.item.test_item import create_item +from erpnext.tests.utils import ERPNextTestSuite def make_customer(customer_name, currency=None): @@ -51,7 +51,7 @@ def make_supplier(supplier_name, currency=None): return supplier_name -class TestAccountsController(IntegrationTestCase): +class TestAccountsController(ERPNextTestSuite): """ Test Exchange Gain/Loss booking on various scenarios. Test Cases are numbered for better organization @@ -72,9 +72,7 @@ class TestAccountsController(IntegrationTestCase): self.create_item() self.create_parties() self.clear_old_entries() - - def tearDown(self): - frappe.db.rollback() + frappe.flags.is_reverse_depr_entry = False def create_company(self): company_name = "_Test Company" @@ -810,9 +808,7 @@ class TestAccountsController(IntegrationTestCase): self.assertEqual(exc_je_for_si, []) self.assertEqual(exc_je_for_pe, []) - @IntegrationTestCase.change_settings( - "Stock Settings", {"allow_internal_transfer_at_arms_length_price": 1} - ) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_internal_transfer_at_arms_length_price": 1}) def test_16_internal_transfer_at_arms_length_price(self): from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_inter_company_purchase_invoice from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse @@ -873,7 +869,7 @@ class TestAccountsController(IntegrationTestCase): self.assertEqual(pi.items[0].rate, arms_length_price) self.assertEqual(pi.items[0].valuation_rate, 100) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"exchange_gain_loss_posting_date": "Reconciliation Date"} ) def test_17_gain_loss_posting_date_for_normal_payment(self): @@ -936,9 +932,9 @@ class TestAccountsController(IntegrationTestCase): self.assertEqual(exc_je_for_si, []) self.assertEqual(exc_je_for_pe, []) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", - {"add_taxes_from_item_tax_template": 0, "add_taxes_from_taxes_and_charges_template": 1}, + {"add_taxes_from_taxes_and_charges_template": 1, "add_taxes_from_item_tax_template": 0}, ) def test_18_fetch_taxes_based_on_taxes_and_charges_template(self): # Create a Sales Taxes and Charges Template @@ -968,7 +964,7 @@ class TestAccountsController(IntegrationTestCase): self.assertEqual(sinv.total_taxes_and_charges, 4.5) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"add_taxes_from_item_tax_template": 1, "add_taxes_from_taxes_and_charges_template": 0}, ) @@ -2479,7 +2475,7 @@ class TestAccountsController(IntegrationTestCase): po.items[0].delivered_by_supplier = 1 po.save() - @IntegrationTestCase.change_settings("Global Defaults", {"use_posting_datetime_for_naming_documents": 1}) + @ERPNextTestSuite.change_settings("Global Defaults", {"use_posting_datetime_for_naming_documents": 1}) def test_document_naming_rule_based_on_posting_date(self): frappe.new_doc( "Document Naming Rule", document_type="Sales Invoice", prefix="SI-.MM.-.YYYY.-" diff --git a/erpnext/controllers/tests/test_distributed_discount.py b/erpnext/controllers/tests/test_distributed_discount.py index 05db1496da8..4f4911c8537 100644 --- a/erpnext/controllers/tests/test_distributed_discount.py +++ b/erpnext/controllers/tests/test_distributed_discount.py @@ -1,11 +1,11 @@ -from frappe.tests import IntegrationTestCase - from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxesAndTotals(AccountsTestMixin, IntegrationTestCase): +class TestTaxesAndTotals(AccountsTestMixin, ERPNextTestSuite): + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_distributed_discount_amount(self): so = make_sales_order(do_not_save=1) so.apply_discount_on = "Net Total" @@ -27,6 +27,7 @@ class TestTaxesAndTotals(AccountsTestMixin, IntegrationTestCase): self.assertEqual(so.net_total, 1400) self.assertEqual(so.grand_total, 1400) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_distributed_discount_amount_with_taxes(self): so = make_sales_order(do_not_save=1) so.apply_discount_on = "Grand Total" diff --git a/erpnext/controllers/tests/test_item_variant.py b/erpnext/controllers/tests/test_item_variant.py index 585a63ca798..e5c9d05d4db 100644 --- a/erpnext/controllers/tests/test_item_variant.py +++ b/erpnext/controllers/tests/test_item_variant.py @@ -2,16 +2,16 @@ import json import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.controllers.item_variant import copy_attributes_to_variant, make_variant_item_code from erpnext.stock.doctype.item.test_item import set_item_variant_settings from erpnext.stock.doctype.quality_inspection.test_quality_inspection import ( create_quality_inspection_parameter, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestItemVariant(IntegrationTestCase): +class TestItemVariant(ERPNextTestSuite): def test_tables_in_template_copied_to_variant(self): fields = [{"field_name": "quality_inspection_template"}] set_item_variant_settings(fields) diff --git a/erpnext/controllers/tests/test_item_wise_inventory_account.py b/erpnext/controllers/tests/test_item_wise_inventory_account.py index e8b2c1343e7..398a8388865 100644 --- a/erpnext/controllers/tests/test_item_wise_inventory_account.py +++ b/erpnext/controllers/tests/test_item_wise_inventory_account.py @@ -5,8 +5,7 @@ import copy from collections import defaultdict import frappe -from frappe.tests import IntegrationTestCase -from frappe.utils import add_days, cint, today +from frappe.utils import add_days, today from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record @@ -14,9 +13,10 @@ from erpnext.manufacturing.doctype.work_order.work_order import make_stock_entry from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class TestItemWiseInventoryAccount(IntegrationTestCase): +class TestItemWiseInventoryAccount(ERPNextTestSuite): def setUp(self): self.company = make_company() self.company_abbr = frappe.db.get_value("Company", self.company, "abbr") @@ -275,7 +275,7 @@ class TestItemWiseInventoryAccount(IntegrationTestCase): } for row in items: - self.make_item_group(items[row]["item_group"]) + self._make_item_group(items[row]["item_group"]) inventory_account_dict = frappe._dict() for item_name, item_data in items.items(): @@ -359,7 +359,7 @@ class TestItemWiseInventoryAccount(IntegrationTestCase): } for row in items: - self.make_item_group(items[row]["item_group"]) + self._make_item_group(items[row]["item_group"]) inventory_account_dict = frappe._dict() for item_name, item_data in items.items(): @@ -453,7 +453,7 @@ class TestItemWiseInventoryAccount(IntegrationTestCase): self.assertEqual(sle_value[0].value, gl_value, f"GL Entry not created for {item_code} correctly") - def make_item_group(self, item_name): + def _make_item_group(self, item_name): if not frappe.db.exists("Item Group", item_name): item_group = frappe.get_doc( { diff --git a/erpnext/controllers/tests/test_item_wise_tax_details.py b/erpnext/controllers/tests/test_item_wise_tax_details.py index 7628f77f7e3..f6d94c61eca 100644 --- a/erpnext/controllers/tests/test_item_wise_tax_details.py +++ b/erpnext/controllers/tests/test_item_wise_tax_details.py @@ -1,12 +1,12 @@ import json import frappe -from frappe.tests.utils import FrappeTestCase from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals +from erpnext.tests.utils import ERPNextTestSuite -class TestTaxesAndTotals(FrappeTestCase): +class TestTaxesAndTotals(ERPNextTestSuite): def setUp(self): self.doc = frappe.get_doc( { diff --git a/erpnext/controllers/tests/test_mapper.py b/erpnext/controllers/tests/test_mapper.py index 53eb75058ec..a54fff65706 100644 --- a/erpnext/controllers/tests/test_mapper.py +++ b/erpnext/controllers/tests/test_mapper.py @@ -4,13 +4,15 @@ import unittest import frappe import frappe.utils from frappe.model import mapper -from frappe.tests import IntegrationTestCase from frappe.utils import add_months, nowdate -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"] +from erpnext.tests.utils import ERPNextTestSuite -class TestMapper(IntegrationTestCase): +class TestMapper(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Sales Order") + def test_map_docs(self): """Test mapping of multiple source docs on a single target doc""" @@ -38,6 +40,7 @@ class TestMapper(IntegrationTestCase): "order_type": "Sales", "transaction_date": nowdate(), "valid_till": add_months(nowdate(), 1), + "company": "_Test Company", } ) for item in item_list: @@ -64,6 +67,6 @@ class TestMapper(IntegrationTestCase): "uom": "_Test UOM", } ) - so = frappe.get_doc(frappe.get_test_records("Sales Order")[0]) + so = frappe.get_doc(self.globalTestRecords["Sales Order"][0]) so.insert(ignore_permissions=True) return so, [item.item_code] diff --git a/erpnext/controllers/tests/test_qty_based_taxes.py b/erpnext/controllers/tests/test_qty_based_taxes.py index d2fefa5b3b6..e3ddb0d1e1b 100644 --- a/erpnext/controllers/tests/test_qty_based_taxes.py +++ b/erpnext/controllers/tests/test_qty_based_taxes.py @@ -2,14 +2,15 @@ import unittest from uuid import uuid4 as _uuid4 import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite def uuid4(): return str(_uuid4()) -class TestTaxes(IntegrationTestCase): +class TestTaxes(ERPNextTestSuite): def setUp(self): self.company = frappe.get_doc( { @@ -125,12 +126,3 @@ class TestTaxes(IntegrationTestCase): doc.insert() self.assertEqual(doc.taxes[0].tax_amount, 600) self.created_docs.append(doc) - - def tearDown(self): - for doc in self.created_docs: - doc.delete() - self.item.delete() - self.item_group.delete() - self.item_tax_template.delete() - self.account.delete() - self.company.delete() diff --git a/erpnext/controllers/tests/test_queries.py b/erpnext/controllers/tests/test_queries.py index f7129a240b6..29f7ea1ea9f 100644 --- a/erpnext/controllers/tests/test_queries.py +++ b/erpnext/controllers/tests/test_queries.py @@ -14,19 +14,7 @@ def add_default_params(func, doctype): return partial(func, doctype=doctype, txt="", searchfield="name", start=0, page_len=20, filters=None) -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "BOM", "Account"] - - class TestQueries(ERPNextTestSuite): - # All tests are based on self.globalTestRecords[doctype] - - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.make_employees() - cls.make_leads() - cls.make_projects() - def assert_nested_in(self, item, container): self.assertIn(item, [vals for tuples in container for vals in tuples]) @@ -97,6 +85,8 @@ class TestQueries(ERPNextTestSuite): self.assertGreaterEqual(frappe.db.count("UOM", {"enabled": 1}), 10) def test_employee_query_with_user_permissions(self): + employee = frappe.db.get_all("Employee", {"first_name": "_Test Employee"})[0].name + # party field is a dynamic link field in Payment Entry doctype with ignore_user_permissions=0 ps = make_property_setter( doctype="Payment Entry", @@ -111,7 +101,7 @@ class TestQueries(ERPNextTestSuite): { "user": user.name, "doctype": "Employee", - "docname": self.employees[0].name, + "docname": employee, "is_default": 1, "apply_to_all_doctypes": 1, "applicable_doctypes": [], @@ -119,7 +109,7 @@ class TestQueries(ERPNextTestSuite): } ) - with self.set_user(user.name): + with ERPNextTestSuite.set_user(self, user.name): params = { "doctype": "Employee", "txt": "", diff --git a/erpnext/controllers/tests/test_reactivity.py b/erpnext/controllers/tests/test_reactivity.py index b6baad2fab2..fa3007087e1 100644 --- a/erpnext/controllers/tests/test_reactivity.py +++ b/erpnext/controllers/tests/test_reactivity.py @@ -1,13 +1,13 @@ import frappe from frappe import qb -from frappe.tests import IntegrationTestCase -from frappe.utils import getdate, today +from frappe.utils import today from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import disable_dimension from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestReactivity(AccountsTestMixin, IntegrationTestCase): +class TestReactivity(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_company() self.create_customer() @@ -16,9 +16,6 @@ class TestReactivity(AccountsTestMixin, IntegrationTestCase): self.create_price_list() self.clear_old_entries() - def tearDown(self): - frappe.db.rollback() - def disable_dimensions(self): res = frappe.db.get_all("Accounting Dimension", filters={"disabled": False}) for x in res: diff --git a/erpnext/controllers/tests/test_subcontracting_controller.py b/erpnext/controllers/tests/test_subcontracting_controller.py index b6c21fa0b45..465b318d09b 100644 --- a/erpnext/controllers/tests/test_subcontracting_controller.py +++ b/erpnext/controllers/tests/test_subcontracting_controller.py @@ -5,8 +5,7 @@ import copy from collections import defaultdict import frappe -from frappe.tests import IntegrationTestCase -from frappe.utils import cint +from frappe.utils import cint, flt from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.controllers.subcontracting_controller import ( @@ -23,9 +22,10 @@ from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry from erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order import ( make_subcontracting_receipt, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestSubcontractingController(IntegrationTestCase): +class TestSubcontractingController(ERPNextTestSuite): def setUp(self): make_subcontracted_items() make_raw_materials() @@ -75,6 +75,7 @@ class TestSubcontractingController(IntegrationTestCase): sco.create_raw_materials_supplied_or_received() self.assertIsNotNone(sco.supplied_items) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_multiple_items": 1}) def test_sco_with_bom(self): """ - Set backflush based on BOM. @@ -741,6 +742,7 @@ class TestSubcontractingController(IntegrationTestCase): "doctype": "Serial No", "item_code": "Subcontracted SRM Item 2", "serial_no": serial_no, + "company": "_Test Company", } ).insert() @@ -1512,7 +1514,7 @@ def make_subcontracted_item(**args): }, ) - args.raw_materials = ["_Test FG Item", "Test Extra Item 1"] + args.raw_materials = ["_Test Extra Item 1", "Test Extra Item 2"] if not frappe.db.get_value("BOM", {"item": args.item_code}, "name"): make_bom(item=args.item_code, raw_materials=args.get("raw_materials")) diff --git a/erpnext/controllers/tests/test_transaction_base.py b/erpnext/controllers/tests/test_transaction_base.py index cfb2dffabb6..4d0542053f7 100644 --- a/erpnext/controllers/tests/test_transaction_base.py +++ b/erpnext/controllers/tests/test_transaction_base.py @@ -1,10 +1,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestUtils(IntegrationTestCase): +class TestUtils(ERPNextTestSuite): def test_reset_default_field_value(self): doc = frappe.get_doc( { diff --git a/erpnext/crm/doctype/appointment/test_appointment.py b/erpnext/crm/doctype/appointment/test_appointment.py index e88a3dc67e5..24974ecf472 100644 --- a/erpnext/crm/doctype/appointment/test_appointment.py +++ b/erpnext/crm/doctype/appointment/test_appointment.py @@ -4,7 +4,8 @@ import datetime import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite LEAD_EMAIL = "test_appointment_lead@example.com" @@ -26,13 +27,9 @@ def create_test_appointment(): return test_appointment -class TestAppointment(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - frappe.db.delete("Lead", {"email_id": LEAD_EMAIL}) - +class TestAppointment(ERPNextTestSuite): def setUp(self): + frappe.db.delete("Lead", {"email_id": LEAD_EMAIL}) self.test_appointment = create_test_appointment() self.test_appointment.set_verified(self.test_appointment.customer_email) diff --git a/erpnext/crm/doctype/appointment_booking_settings/test_appointment_booking_settings.py b/erpnext/crm/doctype/appointment_booking_settings/test_appointment_booking_settings.py index 0fca8a59da3..96d86a224ed 100644 --- a/erpnext/crm/doctype/appointment_booking_settings/test_appointment_booking_settings.py +++ b/erpnext/crm/doctype/appointment_booking_settings/test_appointment_booking_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestAppointmentBookingSettings(IntegrationTestCase): +class TestAppointmentBookingSettings(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/campaign/test_campaign.py b/erpnext/crm/doctype/campaign/test_campaign.py index 878c18664ad..b84fc2815ca 100644 --- a/erpnext/crm/doctype/campaign/test_campaign.py +++ b/erpnext/crm/doctype/campaign/test_campaign.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCampaign(IntegrationTestCase): +class TestCampaign(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/competitor/test_competitor.py b/erpnext/crm/doctype/competitor/test_competitor.py index 2fbe068e8a7..664af74f3f6 100644 --- a/erpnext/crm/doctype/competitor/test_competitor.py +++ b/erpnext/crm/doctype/competitor/test_competitor.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCompetitor(IntegrationTestCase): +class TestCompetitor(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/contract/test_contract.py b/erpnext/crm/doctype/contract/test_contract.py index 2ea083834ce..f6aa0ef0979 100644 --- a/erpnext/crm/doctype/contract/test_contract.py +++ b/erpnext/crm/doctype/contract/test_contract.py @@ -3,11 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, nowdate +from erpnext.tests.utils import ERPNextTestSuite -class TestContract(IntegrationTestCase): + +class TestContract(ERPNextTestSuite): def setUp(self): frappe.db.sql("delete from `tabContract`") self.contract_doc = get_contract() diff --git a/erpnext/crm/doctype/contract_fulfilment_checklist/test_contract_fulfilment_checklist.py b/erpnext/crm/doctype/contract_fulfilment_checklist/test_contract_fulfilment_checklist.py index becb1674190..33f74f3e543 100644 --- a/erpnext/crm/doctype/contract_fulfilment_checklist/test_contract_fulfilment_checklist.py +++ b/erpnext/crm/doctype/contract_fulfilment_checklist/test_contract_fulfilment_checklist.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestContractFulfilmentChecklist(IntegrationTestCase): +class TestContractFulfilmentChecklist(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/contract_template/test_contract_template.py b/erpnext/crm/doctype/contract_template/test_contract_template.py index 4b2911945d0..aff3c8a9171 100644 --- a/erpnext/crm/doctype/contract_template/test_contract_template.py +++ b/erpnext/crm/doctype/contract_template/test_contract_template.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestContractTemplate(IntegrationTestCase): +class TestContractTemplate(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/crm_settings/test_crm_settings.py b/erpnext/crm/doctype/crm_settings/test_crm_settings.py index 22109d960dd..12fa43f8e1d 100644 --- a/erpnext/crm/doctype/crm_settings/test_crm_settings.py +++ b/erpnext/crm/doctype/crm_settings/test_crm_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCRMSettings(IntegrationTestCase): +class TestCRMSettings(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/email_campaign/test_email_campaign.py b/erpnext/crm/doctype/email_campaign/test_email_campaign.py index b94a41e7820..7d7d445b4be 100644 --- a/erpnext/crm/doctype/email_campaign/test_email_campaign.py +++ b/erpnext/crm/doctype/email_campaign/test_email_campaign.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestEmailCampaign(IntegrationTestCase): +class TestEmailCampaign(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/lead/test_lead.py b/erpnext/crm/doctype/lead/test_lead.py index b1b4e162b32..5da10ff9ea2 100644 --- a/erpnext/crm/doctype/lead/test_lead.py +++ b/erpnext/crm/doctype/lead/test_lead.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import random_string, today from erpnext.crm.doctype.lead.lead import make_opportunity @@ -12,19 +11,16 @@ from erpnext.tests.utils import ERPNextTestSuite class TestLead(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.make_leads() - def test_make_customer(self): from erpnext.crm.doctype.lead.lead import make_customer + lead = frappe.db.get_all("Lead", {"lead_name": "_Test Lead"})[0].name + frappe.delete_doc_if_exists("Customer", "_Test Lead") - customer = make_customer(self.leads[0].name) + customer = make_customer(lead) self.assertEqual(customer.doctype, "Customer") - self.assertEqual(customer.lead_name, self.leads[0].name) + self.assertEqual(customer.lead_name, lead) customer.company = "_Test Company" customer.customer_group = "_Test Customer Group" @@ -48,9 +44,10 @@ class TestLead(ERPNextTestSuite): def test_make_customer_from_organization(self): from erpnext.crm.doctype.lead.lead import make_customer - customer = make_customer(self.leads[1].name) + lead = frappe.db.get_all("Lead", {"lead_name": "_Test Lead 1"})[0].name + customer = make_customer(lead) self.assertEqual(customer.doctype, "Customer") - self.assertEqual(customer.lead_name, self.leads[1].name) + self.assertEqual(customer.lead_name, lead) customer.company = "_Test Company" customer.customer_group = "_Test Customer Group" @@ -127,6 +124,7 @@ class TestLead(ERPNextTestSuite): create_todo("followup", "Lead", lead.name) opportunity = make_opportunity(lead.name) + opportunity.company = "_Test Company" opportunity.save() self.assertEqual(opportunity.get("party_name"), lead.name) diff --git a/erpnext/crm/doctype/market_segment/test_market_segment.py b/erpnext/crm/doctype/market_segment/test_market_segment.py index 4f42f704309..5821bae063a 100644 --- a/erpnext/crm/doctype/market_segment/test_market_segment.py +++ b/erpnext/crm/doctype/market_segment/test_market_segment.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestMarketSegment(IntegrationTestCase): +class TestMarketSegment(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index db9866d9b89..caf94a044cb 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import now_datetime, random_string, today from erpnext.crm.doctype.lead.lead import make_customer @@ -14,14 +13,6 @@ from erpnext.tests.utils import ERPNextTestSuite class TestOpportunity(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - # Only first lead is required - # TODO: dynamically generate limited test records - cls.make_leads() - cls.make_opportunities() - @classmethod def make_opportunities(cls): records = [ @@ -31,6 +22,7 @@ class TestOpportunity(ERPNextTestSuite): "opportunity_from": "Lead", "enquiry_type": "Sales", "party_name": cls.leads[0].name, + "company": cls.companies[0].name, "transaction_date": "2013-12-12", "items": [ {"item_name": "Test Item", "description": "Some description", "qty": 5, "rate": 100} @@ -57,7 +49,7 @@ class TestOpportunity(ERPNextTestSuite): self.assertEqual(doc.status, "Quotation") def test_make_new_lead_if_required(self): - opp_doc = make_opportunity_from_lead() + opp_doc = make_opportunity_from_lead("_Test Company") self.assertTrue(opp_doc.party_name) self.assertEqual(opp_doc.opportunity_from, "Lead") @@ -101,7 +93,7 @@ class TestOpportunity(ERPNextTestSuite): create_communication(opp_doc.doctype, opp_doc.name, opp_doc.contact_email) -def make_opportunity_from_lead(): +def make_opportunity_from_lead(company): new_lead_email_id = f"new{random_string(5)}@example.com" args = { "doctype": "Opportunity", @@ -109,6 +101,7 @@ def make_opportunity_from_lead(): "opportunity_type": "Sales", "with_items": 0, "transaction_date": today(), + "company": company, } # new lead should be created against the new.opportunity@example.com opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) diff --git a/erpnext/crm/doctype/opportunity_type/test_opportunity_type.py b/erpnext/crm/doctype/opportunity_type/test_opportunity_type.py index 91bbd0d7095..1015ac8effa 100644 --- a/erpnext/crm/doctype/opportunity_type/test_opportunity_type.py +++ b/erpnext/crm/doctype/opportunity_type/test_opportunity_type.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestOpportunityType(IntegrationTestCase): +class TestOpportunityType(ERPNextTestSuite): pass diff --git a/erpnext/crm/doctype/prospect/test_prospect.py b/erpnext/crm/doctype/prospect/test_prospect.py index d66f3d5a494..594269dd084 100644 --- a/erpnext/crm/doctype/prospect/test_prospect.py +++ b/erpnext/crm/doctype/prospect/test_prospect.py @@ -3,20 +3,21 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import random_string from erpnext.crm.doctype.lead.lead import add_lead_to_prospect from erpnext.crm.doctype.lead.test_lead import make_lead +from erpnext.tests.utils import ERPNextTestSuite -class TestProspect(IntegrationTestCase): +class TestProspect(ERPNextTestSuite): def test_add_lead_to_prospect_and_address_linking(self): + company = "_Test Company" lead_doc = make_lead() address_doc = make_address(address_title=lead_doc.name) address_doc.append("links", {"link_doctype": lead_doc.doctype, "link_name": lead_doc.name}) address_doc.save() - prospect_doc = make_prospect() + prospect_doc = make_prospect(company=company, company_name=company) add_lead_to_prospect(lead_doc.name, prospect_doc.name) prospect_doc.reload() lead_exists_in_prosoect = False @@ -37,6 +38,7 @@ class TestProspect(IntegrationTestCase): "doctype": "Prospect", "company_name": "_Test Prospect", "customer_group": "_Test Customer Group", + "company": "_Test Company", } ) prospect.insert() @@ -58,6 +60,7 @@ def make_prospect(**args): { "doctype": "Prospect", "company_name": args.company_name or f"_Test Company {random_string(3)}", + "company": args.company, } ).insert() diff --git a/erpnext/crm/doctype/sales_stage/test_sales_stage.py b/erpnext/crm/doctype/sales_stage/test_sales_stage.py index 24da6ce48f6..9633ca17c14 100644 --- a/erpnext/crm/doctype/sales_stage/test_sales_stage.py +++ b/erpnext/crm/doctype/sales_stage/test_sales_stage.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesStage(IntegrationTestCase): +class TestSalesStage(ERPNextTestSuite): pass diff --git a/erpnext/crm/report/opportunity_summary_by_sales_stage/test_opportunity_summary_by_sales_stage.py b/erpnext/crm/report/opportunity_summary_by_sales_stage/test_opportunity_summary_by_sales_stage.py index 63d6cae3b00..4d5ba1dc9a2 100644 --- a/erpnext/crm/report/opportunity_summary_by_sales_stage/test_opportunity_summary_by_sales_stage.py +++ b/erpnext/crm/report/opportunity_summary_by_sales_stage/test_opportunity_summary_by_sales_stage.py @@ -1,24 +1,14 @@ -import unittest - -import frappe -from frappe.tests import IntegrationTestCase - from erpnext.crm.report.opportunity_summary_by_sales_stage.opportunity_summary_by_sales_stage import ( execute, ) from erpnext.crm.report.sales_pipeline_analytics.test_sales_pipeline_analytics import ( - create_company, - create_customer, create_opportunity, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestOpportunitySummaryBySalesStage(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - create_company() - create_customer() +class TestOpportunitySummaryBySalesStage(ERPNextTestSuite): + def setUp(self): create_opportunity() def test_opportunity_summary_by_sales_stage(self): diff --git a/erpnext/crm/report/sales_pipeline_analytics/test_sales_pipeline_analytics.py b/erpnext/crm/report/sales_pipeline_analytics/test_sales_pipeline_analytics.py index b29668fa030..893218c37ea 100644 --- a/erpnext/crm/report/sales_pipeline_analytics/test_sales_pipeline_analytics.py +++ b/erpnext/crm/report/sales_pipeline_analytics/test_sales_pipeline_analytics.py @@ -1,15 +1,13 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.crm.report.sales_pipeline_analytics.sales_pipeline_analytics import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesPipelineAnalytics(IntegrationTestCase): +class TestSalesPipelineAnalytics(ERPNextTestSuite): def setUp(self): - create_company() - create_customer() create_opportunity() def test_sales_pipeline_analytics(self): @@ -181,23 +179,6 @@ class TestSalesPipelineAnalytics(IntegrationTestCase): self.assertEqual(expected_data, report[1]) -def create_company(): - doc = frappe.db.exists("Company", "Best Test") - if not doc: - doc = frappe.new_doc("Company") - doc.company_name = "Best Test" - doc.default_currency = "INR" - doc.insert() - - -def create_customer(): - doc = frappe.db.exists("Customer", "_Test NC") - if not doc: - doc = frappe.new_doc("Customer") - doc.customer_name = "_Test NC" - doc.insert() - - def create_opportunity(): doc = frappe.db.exists({"doctype": "Opportunity", "party_name": "_Test NC"}) if not doc: diff --git a/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py b/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py index 891a6bd10df..6cc09e6d2a7 100644 --- a/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py +++ b/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py @@ -4,7 +4,6 @@ import json import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils.response import json_handler from erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings import ( @@ -14,22 +13,10 @@ from erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings import ( get_plaid_configuration, new_bank_transaction, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestPlaidSettings(IntegrationTestCase): - def setUp(self): - pass - - def tearDown(self): - for bt in frappe.get_all("Bank Transaction"): - doc = frappe.get_doc("Bank Transaction", bt.name) - doc.cancel() - doc.delete() - - for doctype in ("Bank Account", "Bank Account Type", "Bank Account Subtype"): - for d in frappe.get_all(doctype): - frappe.delete_doc(doctype, d.name, force=True) - +class TestPlaidSettings(ERPNextTestSuite): def test_plaid_disabled(self): frappe.db.set_single_value("Plaid Settings", "enabled", 0) self.assertTrue(get_plaid_configuration() == "disabled") @@ -69,7 +56,7 @@ class TestPlaidSettings(IntegrationTestCase): } bank = json.dumps(frappe.get_doc("Bank", "Citi").as_dict(), default=json_handler) - company = frappe.db.get_single_value("Global Defaults", "default_company") + company = "_Test Company" add_bank_accounts(bank_accounts, bank, company) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 962fe3e98aa..c997443b41d 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -63,7 +63,6 @@ welcome_email = "erpnext.setup.utils.welcome_email" setup_wizard_requires = "assets/erpnext/js/setup_wizard.js" setup_wizard_stages = "erpnext.setup.setup_wizard.setup_wizard.get_setup_stages" setup_wizard_complete = "erpnext.setup.setup_wizard.setup_wizard.setup_demo" -setup_wizard_test = "erpnext.setup.setup_wizard.test_setup_wizard.run_setup_wizard_test" after_install = "erpnext.setup.install.after_install" @@ -320,8 +319,6 @@ has_website_permission = { "Project": "erpnext.controllers.website_list_for_contact.has_website_permission", } -before_tests = "erpnext.setup.utils.before_tests" - period_closing_doctypes = [ "Sales Invoice", diff --git a/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py b/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py index 206c9687c31..b10873663c7 100644 --- a/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py +++ b/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import format_date from frappe.utils.data import add_days, formatdate, today @@ -13,13 +12,12 @@ from erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule impor ) from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item +from erpnext.tests.utils import ERPNextTestSuite -class TestMaintenanceSchedule(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.make_sales_person() +class TestMaintenanceSchedule(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Stock Entry") @classmethod def make_sales_person(cls): @@ -143,8 +141,6 @@ class TestMaintenanceSchedule(IntegrationTestCase): serial_nos = get_serial_nos_from_schedule(mvi.item_name, ms.name) self.assertEqual(serial_nos, ["TEST001", "TEST002"]) - frappe.db.rollback() - def test_schedule_with_serials(self): # Checks whether serials are automatically updated when changing in items table. # Also checks if other fields trigger generate schdeule if changed in items table. @@ -160,7 +156,7 @@ class TestMaintenanceSchedule(IntegrationTestCase): self.assertFalse(ms.validate_items_table_change()) # After Save ms.items[0].serial_no = "TEST001" - ms.items[0].sales_person = self.sales_person[0].name + ms.items[0].sales_person = "_Test Sales Person" ms.items[0].no_of_visits = 2 self.assertTrue(ms.validate_items_table_change()) ms.save() @@ -173,8 +169,6 @@ class TestMaintenanceSchedule(IntegrationTestCase): ms.save() self.assertEqual(len(ms.schedules), 2) - frappe.db.rollback() - def make_serial_item_with_serial(self, item_code): serial_item_doc = create_item(item_code, is_stock_item=1) diff --git a/erpnext/maintenance/doctype/maintenance_visit/test_maintenance_visit.py b/erpnext/maintenance/doctype/maintenance_visit/test_maintenance_visit.py index 51a27983269..ffc49296a4c 100644 --- a/erpnext/maintenance/doctype/maintenance_visit/test_maintenance_visit.py +++ b/erpnext/maintenance/doctype/maintenance_visit/test_maintenance_visit.py @@ -3,11 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils.data import today +from erpnext.tests.utils import ERPNextTestSuite -class TestMaintenanceVisit(IntegrationTestCase): + +class TestMaintenanceVisit(ERPNextTestSuite): pass diff --git a/erpnext/maintenance/doctype/maintenance_visit/test_records.json b/erpnext/maintenance/doctype/maintenance_visit/test_records.json deleted file mode 100644 index 0d4f101c7a3..00000000000 --- a/erpnext/maintenance/doctype/maintenance_visit/test_records.json +++ /dev/null @@ -1,2 +0,0 @@ -[ -] diff --git a/erpnext/manufacturing/doctype/blanket_order/test_blanket_order.py b/erpnext/manufacturing/doctype/blanket_order/test_blanket_order.py index 169197e04ca..ac7c860dd1b 100644 --- a/erpnext/manufacturing/doctype/blanket_order/test_blanket_order.py +++ b/erpnext/manufacturing/doctype/blanket_order/test_blanket_order.py @@ -1,16 +1,16 @@ # Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_months, today from erpnext import get_company_currency from erpnext.stock.doctype.item.test_item import make_item +from erpnext.tests.utils import ERPNextTestSuite from .blanket_order import make_order -class TestBlanketOrder(IntegrationTestCase): +class TestBlanketOrder(ERPNextTestSuite): def setUp(self): frappe.flags.args = frappe._dict() diff --git a/erpnext/manufacturing/doctype/bom/test_bom.py b/erpnext/manufacturing/doctype/bom/test_bom.py index 000b4723e59..69b55e6d1d8 100644 --- a/erpnext/manufacturing/doctype/bom/test_bom.py +++ b/erpnext/manufacturing/doctype/bom/test_bom.py @@ -6,7 +6,7 @@ from collections import deque from functools import partial import frappe -from frappe.tests import IntegrationTestCase, timeout +from frappe.tests import timeout from frappe.utils import cstr, flt from erpnext.controllers.tests.test_subcontracting_controller import ( @@ -20,11 +20,13 @@ from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ( create_stock_reconciliation, ) - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Quality Inspection Template"] +from erpnext.tests.utils import ERPNextTestSuite -class TestBOM(IntegrationTestCase): +class TestBOM(ERPNextTestSuite): + def setUp(self): + self.load_test_records("BOM") + @timeout def test_get_items(self): from erpnext.manufacturing.doctype.bom.bom import get_bom_items_as_dict @@ -390,6 +392,7 @@ class TestBOM(IntegrationTestCase): item_code = make_item(properties={"is_stock_item": 1}).name bom = frappe.new_doc("BOM") + bom.company = "_Test Company" bom.item = item_code bom.append("items", frappe._dict(item_code=item_code)) bom.save() @@ -403,11 +406,13 @@ class TestBOM(IntegrationTestCase): item2 = make_item(properties={"is_stock_item": 1}).name bom1 = frappe.new_doc("BOM") + bom1.company = "_Test Company" bom1.item = item1 bom1.append("items", frappe._dict(item_code=item2)) bom1.save() bom2 = frappe.new_doc("BOM") + bom2.company = "_Test Company" bom2.item = item2 bom2.append("items", frappe._dict(item_code=item1)) bom2.save() @@ -565,6 +570,7 @@ class TestBOM(IntegrationTestCase): @timeout def test_clear_inpection_quality(self): bom = frappe.copy_doc(self.globalTestRecords["BOM"][2], ignore_no_copy=True) + bom.company = "_Test Company" bom.docstatus = 0 bom.is_default = 0 bom.quality_inspection_template = "_Test Quality Inspection Template" @@ -610,6 +616,7 @@ class TestBOM(IntegrationTestCase): # Step 1: Create BOM bom = frappe.new_doc("BOM") + bom.company = "_Test Company" bom.item = fg_item.item_code bom.quantity = 1 bom.append( @@ -647,7 +654,7 @@ class TestBOM(IntegrationTestCase): from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom - bom = make_bom(item=fg_item, raw_materials=[rm_item], do_not_save=True) + bom = make_bom(item=fg_item, raw_materials=[rm_item], currency="INR", do_not_save=True) bom.rm_cost_as_per = "Last Purchase Rate" bom.save() @@ -860,11 +867,12 @@ def reset_item_valuation_rate(item_code, warehouse_list=None, qty=None, rate=Non def create_bom_with_process_loss_item( - fg_item, bom_item, scrap_qty=0, scrap_rate=0, fg_qty=2, process_loss_percentage=0 + fg_item, bom_item, scrap_qty=0, scrap_rate=0, fg_qty=2, process_loss_percentage=0, company=None ): bom_doc = frappe.new_doc("BOM") bom_doc.item = fg_item.item_code bom_doc.quantity = fg_qty + bom_doc.company = company bom_doc.append( "items", { diff --git a/erpnext/manufacturing/doctype/bom/test_records.json b/erpnext/manufacturing/doctype/bom/test_records.json index e9cbdfe638a..27752d85119 100644 --- a/erpnext/manufacturing/doctype/bom/test_records.json +++ b/erpnext/manufacturing/doctype/bom/test_records.json @@ -79,6 +79,7 @@ "is_default": 1, "currency": "USD", "item": "_Test FG Item", + "company": "_Test Company", "quantity": 1.0 }, { @@ -161,6 +162,7 @@ "currency": "USD", "item": "_Test Variant Item", "quantity": 1.0, + "company": "_Test Company", "with_operations": 1 }, { @@ -187,6 +189,7 @@ "quantity": 1.0, "with_operations": 0, "fg_based_operating_cost": 1, + "company": "_Test Company", "operating_cost_per_bom_quantity": 140 } ] diff --git a/erpnext/manufacturing/doctype/bom_creator/test_bom_creator.py b/erpnext/manufacturing/doctype/bom_creator/test_bom_creator.py index b277ca3c483..f7e7623b471 100644 --- a/erpnext/manufacturing/doctype/bom_creator/test_bom_creator.py +++ b/erpnext/manufacturing/doctype/bom_creator/test_bom_creator.py @@ -4,16 +4,16 @@ import random import frappe -from frappe.tests import IntegrationTestCase from erpnext.manufacturing.doctype.bom_creator.bom_creator import ( add_item, add_sub_assembly, ) from erpnext.stock.doctype.item.test_item import make_item +from erpnext.tests.utils import ERPNextTestSuite -class TestBOMCreator(IntegrationTestCase): +class TestBOMCreator(ERPNextTestSuite): def setUp(self) -> None: create_items() diff --git a/erpnext/manufacturing/doctype/bom_update_log/test_bom_update_log.py b/erpnext/manufacturing/doctype/bom_update_log/test_bom_update_log.py index 815d5599ef0..ea2f8df8cc6 100644 --- a/erpnext/manufacturing/doctype/bom_update_log/test_bom_update_log.py +++ b/erpnext/manufacturing/doctype/bom_update_log/test_bom_update_log.py @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from erpnext.manufacturing.doctype.bom_update_log.bom_update_log import ( BOMMissingError, @@ -12,14 +11,14 @@ from erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool import ( enqueue_replace_bom, enqueue_update_cost, ) - -EXTRA_TEST_RECORD_DEPENDENCIES = ["BOM"] +from erpnext.tests.utils import ERPNextTestSuite -class TestBOMUpdateLog(IntegrationTestCase): +class TestBOMUpdateLog(ERPNextTestSuite): "Test BOM Update Tool Operations via BOM Update Log." def setUp(self): + self.load_test_records("BOM") bom_doc = frappe.copy_doc(self.globalTestRecords["BOM"][0]) bom_doc.items[1].item_code = "_Test Item" bom_doc.insert() @@ -31,9 +30,6 @@ class TestBOMUpdateLog(IntegrationTestCase): self.new_bom_doc = bom_doc - def tearDown(self): - frappe.db.rollback() - def test_bom_update_log_validate(self): """ 1) Test if BOM presence is validated. diff --git a/erpnext/manufacturing/doctype/bom_update_tool/test_bom_update_tool.py b/erpnext/manufacturing/doctype/bom_update_tool/test_bom_update_tool.py index 05bf252bedf..c035dccd06c 100644 --- a/erpnext/manufacturing/doctype/bom_update_tool/test_bom_update_tool.py +++ b/erpnext/manufacturing/doctype/bom_update_tool/test_bom_update_tool.py @@ -2,7 +2,7 @@ # License: GNU General Public License v3. See license.txt import frappe -from frappe.tests import IntegrationTestCase, timeout +from frappe.tests import timeout from erpnext.manufacturing.doctype.bom_update_log.test_bom_update_log import ( update_cost_in_all_boms_in_test, @@ -10,15 +10,14 @@ from erpnext.manufacturing.doctype.bom_update_log.test_bom_update_log import ( from erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool import enqueue_replace_bom from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom from erpnext.stock.doctype.item.test_item import create_item - -EXTRA_TEST_RECORD_DEPENDENCIES = ["BOM"] +from erpnext.tests.utils import ERPNextTestSuite -class TestBOMUpdateTool(IntegrationTestCase): +class TestBOMUpdateTool(ERPNextTestSuite): "Test major functions run via BOM Update Tool." - def tearDown(self): - frappe.db.rollback() + def setUp(self): + self.load_test_records("BOM") @timeout def test_replace_bom(self): diff --git a/erpnext/manufacturing/doctype/downtime_entry/test_downtime_entry.py b/erpnext/manufacturing/doctype/downtime_entry/test_downtime_entry.py index b59b336c657..88fcade6920 100644 --- a/erpnext/manufacturing/doctype/downtime_entry/test_downtime_entry.py +++ b/erpnext/manufacturing/doctype/downtime_entry/test_downtime_entry.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestDowntimeEntry(IntegrationTestCase): +class TestDowntimeEntry(ERPNextTestSuite): pass diff --git a/erpnext/manufacturing/doctype/job_card/test_job_card.py b/erpnext/manufacturing/doctype/job_card/test_job_card.py index bcda8913238..cb05acb9433 100644 --- a/erpnext/manufacturing/doctype/job_card/test_job_card.py +++ b/erpnext/manufacturing/doctype/job_card/test_job_card.py @@ -5,8 +5,7 @@ from typing import Literal import frappe -from frappe.tests import IntegrationTestCase -from frappe.utils import random_string +from frappe.utils import flt, random_string from frappe.utils.data import add_to_date, now, today from erpnext.manufacturing.doctype.job_card.job_card import ( @@ -26,16 +25,10 @@ from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.tests.utils import ERPNextTestSuite -EXTRA_TEST_RECORD_DEPENDENCIES = ["UOM"] - class TestJobCard(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - def setUp(self): - self.make_employees() # used in job card time log + self.load_test_records("BOM") self.make_bom_for_jc_tests() self.transfer_material_against: Literal["Work Order", "Job Card"] = "Work Order" self.source_warehouse = None @@ -71,9 +64,6 @@ class TestJobCard(ERPNextTestSuite): basic_rate=100, ) - def tearDown(self): - frappe.db.rollback() - def test_quality_inspection_mandatory_check(self): from erpnext.manufacturing.doctype.operation.test_operation import make_operation @@ -91,7 +81,12 @@ class TestJobCard(ERPNextTestSuite): cut_bom = create_semi_fg_bom(cut_fg.name, raw.name, inspection_required=1) stitch_bom = create_semi_fg_bom(stitch_fg.name, cut_fg.name, inspection_required=0) final_bom = frappe.new_doc( - "BOM", item=final.name, quantity=1, with_operations=1, track_semi_finished_goods=1 + "BOM", + item=final.name, + quantity=1, + with_operations=1, + track_semi_finished_goods=1, + company="_Test Company", ) final_bom.append("items", {"item_code": raw.name, "qty": 1}) final_bom.append( @@ -125,9 +120,10 @@ class TestJobCard(ERPNextTestSuite): final_bom.append("items", {"item_code": stitch_fg.name, "qty": 1, "operation_row_id": 3}) final_bom.submit() work_order = make_work_order(final_bom.name, final.name, 1, variant_items=[], use_multi_level_bom=0) - work_order.wip_warehouse = "Work In Progress - WP" - work_order.fg_warehouse = "Finished Goods - WP" - work_order.scrap_warehouse = "All Warehouses - WP" + work_order.company = "_Test Company" + work_order.wip_warehouse = "Work In Progress - _TC" + work_order.fg_warehouse = "Finished Goods - _TC" + work_order.scrap_warehouse = "All Warehouses - _TC" for operation in work_order.operations: operation.time_in_mins = 60 @@ -190,7 +186,7 @@ class TestJobCard(ERPNextTestSuite): jc1 = frappe.get_last_doc("Job Card", {"work_order": self.work_order.name}) jc2 = frappe.get_last_doc("Job Card", {"work_order": wo2.name}) - employee = self.employees[0].name + employee = frappe.db.get_all("Employee", {"first_name": "_Test Employee"})[0].name jc1.append( "time_logs", @@ -284,7 +280,7 @@ class TestJobCard(ERPNextTestSuite): # transfer was made for 2 fg qty in first transfer Stock Entry self.assertEqual(transfer_entry_2.fg_completed_qty, 0) - @IntegrationTestCase.change_settings("Manufacturing Settings", {"job_card_excess_transfer": 1}) + @ERPNextTestSuite.change_settings("Manufacturing Settings", {"job_card_excess_transfer": 1}) def test_job_card_excess_material_transfer(self): "Test transferring more than required RM against Job Card." self.transfer_material_against = "Job Card" @@ -327,7 +323,7 @@ class TestJobCard(ERPNextTestSuite): # JC is Completed with excess transfer self.assertEqual(job_card.status, "Completed") - @IntegrationTestCase.change_settings("Manufacturing Settings", {"job_card_excess_transfer": 0}) + @ERPNextTestSuite.change_settings("Manufacturing Settings", {"job_card_excess_transfer": 0}) def test_job_card_excess_material_transfer_block(self): self.transfer_material_against = "Job Card" self.source_warehouse = "Stores - _TC" @@ -350,7 +346,7 @@ class TestJobCard(ERPNextTestSuite): transfer_entry_2.insert() self.assertRaises(JobCardOverTransferError, transfer_entry_2.submit) - @IntegrationTestCase.change_settings("Manufacturing Settings", {"job_card_excess_transfer": 0}) + @ERPNextTestSuite.change_settings("Manufacturing Settings", {"job_card_excess_transfer": 0}) def test_job_card_excess_material_transfer_with_no_reference(self): self.transfer_material_against = "Job Card" self.source_warehouse = "Stores - _TC" @@ -458,7 +454,7 @@ class TestJobCard(ERPNextTestSuite): self.assertEqual(transfer_entry.items[0].item_code, "_Test Item") self.assertEqual(transfer_entry.items[0].qty, 2) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Manufacturing Settings", {"add_corrective_operation_cost_in_finished_good_valuation": 1} ) def test_corrective_costing(self): @@ -502,7 +498,7 @@ class TestJobCard(ERPNextTestSuite): cost_after_cancel = self.work_order.total_operating_cost self.assertEqual(cost_after_cancel, original_cost) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Manufacturing Settings", {"add_corrective_operation_cost_in_finished_good_valuation": 1} ) def test_if_corrective_jc_ops_cost_is_added_to_manufacture_stock_entry(self): @@ -938,6 +934,7 @@ def make_wo_with_transfer_against_jc(): def create_semi_fg_bom(semi_fg_item, raw_item, inspection_required): bom = frappe.new_doc("BOM") + bom.company = "Wind Power LLC" bom.item = semi_fg_item bom.quantity = 1 bom.inspection_required = inspection_required diff --git a/erpnext/manufacturing/doctype/manufacturing_settings/test_manufacturing_settings.py b/erpnext/manufacturing/doctype/manufacturing_settings/test_manufacturing_settings.py index 050b5d7d0f2..a9661480b95 100644 --- a/erpnext/manufacturing/doctype/manufacturing_settings/test_manufacturing_settings.py +++ b/erpnext/manufacturing/doctype/manufacturing_settings/test_manufacturing_settings.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestManufacturingSettings(IntegrationTestCase): +class TestManufacturingSettings(ERPNextTestSuite): pass diff --git a/erpnext/manufacturing/doctype/master_production_schedule/test_master_production_schedule.py b/erpnext/manufacturing/doctype/master_production_schedule/test_master_production_schedule.py index 1263fc583b5..e695b11bcb5 100644 --- a/erpnext/manufacturing/doctype/master_production_schedule/test_master_production_schedule.py +++ b/erpnext/manufacturing/doctype/master_production_schedule/test_master_production_schedule.py @@ -2,19 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class IntegrationTestMasterProductionSchedule(IntegrationTestCase): - """ - Integration tests for MasterProductionSchedule. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/manufacturing/doctype/material_request_plan_item/test_material_request_plan_item.py b/erpnext/manufacturing/doctype/material_request_plan_item/test_material_request_plan_item.py index f903d2dce2d..ee7bb6ec0b2 100644 --- a/erpnext/manufacturing/doctype/material_request_plan_item/test_material_request_plan_item.py +++ b/erpnext/manufacturing/doctype/material_request_plan_item/test_material_request_plan_item.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestMaterialRequestPlanItem(IntegrationTestCase): +class TestMaterialRequestPlanItem(ERPNextTestSuite): pass diff --git a/erpnext/manufacturing/doctype/operation/test_operation.py b/erpnext/manufacturing/doctype/operation/test_operation.py index d9867e74557..e00b85d7e94 100644 --- a/erpnext/manufacturing/doctype/operation/test_operation.py +++ b/erpnext/manufacturing/doctype/operation/test_operation.py @@ -3,10 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestOperation(IntegrationTestCase): +class TestOperation(ERPNextTestSuite): pass diff --git a/erpnext/manufacturing/doctype/operation/test_records.json b/erpnext/manufacturing/doctype/operation/test_records.json deleted file mode 100644 index 5a24d440653..00000000000 --- a/erpnext/manufacturing/doctype/operation/test_records.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "doctype": "Operation", - "name": "_Test Operation 1", - "workstation": "_Test Workstation 1" - } -] diff --git a/erpnext/manufacturing/doctype/plant_floor/test_plant_floor.py b/erpnext/manufacturing/doctype/plant_floor/test_plant_floor.py index 78a8662e1fc..c2cbd97d0d1 100644 --- a/erpnext/manufacturing/doctype/plant_floor/test_plant_floor.py +++ b/erpnext/manufacturing/doctype/plant_floor/test_plant_floor.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestPlantFloor(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestPlantFloor(ERPNextTestSuite): pass diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py index 08249de49fb..4612c427714 100644 --- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py @@ -1,7 +1,6 @@ # Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_to_date, flt, getdate, now_datetime, nowdate from erpnext.controllers.item_variant import create_variant @@ -25,9 +24,10 @@ from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import create_stock_reconciliation, ) from erpnext.stock.doctype.stock_reservation_entry.stock_reservation_entry import StockReservation +from erpnext.tests.utils import ERPNextTestSuite -class TestProductionPlan(IntegrationTestCase): +class TestProductionPlan(ERPNextTestSuite): def setUp(self): for item in [ "Test Production Item 1", @@ -56,9 +56,6 @@ class TestProductionPlan(IntegrationTestCase): if not frappe.db.get_value("BOM", {"item": item}): make_bom(item=item, raw_materials=raw_materials) - def tearDown(self) -> None: - frappe.db.rollback() - def test_production_plan_mr_creation(self): "Test if MRs are created for unavailable raw materials." pln = create_production_plan(item_code="Test Production Item 1") @@ -549,7 +546,9 @@ class TestProductionPlan(IntegrationTestCase): make_rm_stock_entry(sco.name) scr = make_subcontracting_receipt(sco.name) scr.submit() - scr_make_purchase_receipt(scr.name).submit() + doc = scr_make_purchase_receipt(scr.name) + doc.currency = "INR" + doc.submit() fg_item = "Test Motherboard 1" bom_tree_1 = {"Test Laptop 1": {fg_item: {"Test Motherboard Wires 1": {}}}} @@ -970,8 +969,6 @@ class TestProductionPlan(IntegrationTestCase): self.assertEqual(pln.po_items[0].item_code, "PIV-RED") self.assertEqual(pln.po_items[0].bom_no, parent_bom.name) - frappe.db.rollback() - def test_get_sales_order_items_for_product_bundle(self): """Testing the Planned Qty for Product Bundle Item""" from erpnext.manufacturing.doctype.work_order.test_work_order import ( diff --git a/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/test_production_plan_material_request_warehouse.py b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/test_production_plan_material_request_warehouse.py index bab30fa6a92..01a3465156c 100644 --- a/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/test_production_plan_material_request_warehouse.py +++ b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/test_production_plan_material_request_warehouse.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestProductionPlanMaterialRequestWarehouse(IntegrationTestCase): +class TestProductionPlanMaterialRequestWarehouse(ERPNextTestSuite): pass diff --git a/erpnext/manufacturing/doctype/routing/test_routing.py b/erpnext/manufacturing/doctype/routing/test_routing.py index 4c6e8df5752..4575c1d1d57 100644 --- a/erpnext/manufacturing/doctype/routing/test_routing.py +++ b/erpnext/manufacturing/doctype/routing/test_routing.py @@ -1,24 +1,16 @@ # Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt import frappe -from frappe.tests import IntegrationTestCase from erpnext.manufacturing.doctype.job_card.job_card import OperationSequenceError from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record from erpnext.stock.doctype.item.test_item import make_item - -EXTRA_TEST_RECORD_DEPENDENCIES = ["UOM"] +from erpnext.tests.utils import ERPNextTestSuite -class TestRouting(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.item_code = "Test Routing Item - A" - - @classmethod - def tearDownClass(cls): - frappe.db.sql("delete from tabBOM where item=%s", cls.item_code) +class TestRouting(ERPNextTestSuite): + def setUp(self): + self.item_code = "Test Routing Item - A" def test_sequence_id(self): operations = [ diff --git a/erpnext/manufacturing/doctype/sales_forecast/test_sales_forecast.py b/erpnext/manufacturing/doctype/sales_forecast/test_sales_forecast.py index 3f95a82d5f0..e695b11bcb5 100644 --- a/erpnext/manufacturing/doctype/sales_forecast/test_sales_forecast.py +++ b/erpnext/manufacturing/doctype/sales_forecast/test_sales_forecast.py @@ -2,19 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class IntegrationTestSalesForecast(IntegrationTestCase): - """ - Integration tests for SalesForecast. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/manufacturing/doctype/sub_operation/test_sub_operation.py b/erpnext/manufacturing/doctype/sub_operation/test_sub_operation.py index 05486e98777..45a79e974ca 100644 --- a/erpnext/manufacturing/doctype/sub_operation/test_sub_operation.py +++ b/erpnext/manufacturing/doctype/sub_operation/test_sub_operation.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSubOperation(IntegrationTestCase): +class TestSubOperation(ERPNextTestSuite): pass diff --git a/erpnext/manufacturing/doctype/work_order/test_records.json b/erpnext/manufacturing/doctype/work_order/test_records.json deleted file mode 100644 index e7c7039ed43..00000000000 --- a/erpnext/manufacturing/doctype/work_order/test_records.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "bom_no": "BOM-_Test FG Item-001", - "company": "_Test Company", - "doctype": "Work Order", - "fg_warehouse": "_Test Warehouse 1 - _TC", - "production_item": "_Test FG Item", - "qty": 10.0, - "stock_uom": "_Test UOM", - "wip_warehouse": "_Test Warehouse - _TC" - } -] \ No newline at end of file diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py index 08f5e2eaf56..3b39c58fbac 100644 --- a/erpnext/manufacturing/doctype/work_order/test_work_order.py +++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py @@ -5,7 +5,7 @@ from collections import defaultdict import frappe -from frappe.tests import IntegrationTestCase, timeout +from frappe.tests import timeout from frappe.utils import add_days, add_months, add_to_date, cint, flt, now, today from erpnext.manufacturing.doctype.job_card.job_card import JobCardCancelError @@ -33,20 +33,15 @@ from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos from erpnext.stock.doctype.stock_entry import test_stock_entry from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse from erpnext.stock.utils import get_bin - -EXTRA_TEST_RECORD_DEPENDENCIES = ["BOM"] +from erpnext.tests.utils import ERPNextTestSuite -class TestWorkOrder(IntegrationTestCase): +class TestWorkOrder(ERPNextTestSuite): def setUp(self): self.warehouse = "_Test Warehouse 2 - _TC" self.item = "_Test Item" prepare_data_for_backflush_based_on_materials_transferred() - def tearDown(self): - frappe.local.future_sle = {} - frappe.db.rollback() - def check_planned_qty(self): planned0 = ( frappe.db.get_value( @@ -461,8 +456,9 @@ class TestWorkOrder(IntegrationTestCase): @timeout(seconds=60) def test_job_card(self): stock_entries = [] - bom = frappe.get_doc("BOM", {"docstatus": 1, "with_operations": 1, "company": "_Test Company"}) - + bom = frappe.get_doc( + "BOM", {"docstatus": 1, "with_operations": 1, "company": "_Test Company", "has_variants": 0} + ) work_order = make_wo_order_test_record( item=bom.item, qty=1, bom_no=bom.name, source_warehouse="_Test Warehouse - _TC" ) @@ -512,7 +508,9 @@ class TestWorkOrder(IntegrationTestCase): def test_work_order_material_transferred_qty_with_process_loss(self): stock_entries = [] - bom = frappe.get_doc("BOM", {"docstatus": 1, "with_operations": 1, "company": "_Test Company"}) + bom = frappe.get_doc( + "BOM", {"docstatus": 1, "with_operations": 1, "company": "_Test Company", "has_variants": 0} + ) work_order = make_wo_order_test_record( item=bom.item, @@ -700,6 +698,7 @@ class TestWorkOrder(IntegrationTestCase): work_order1.save() self.assertEqual(work_order1.operations[0].time_in_mins, 40.0) + @ERPNextTestSuite.change_settings("Global Defaults", {"default_company": "_Test Company"}) def test_batch_size_for_fg_item(self): fg_item = "Test Batch Size Item For BOM 3" rm1 = "Test Batch Size Item RM 1 For BOM 3" @@ -957,7 +956,11 @@ class TestWorkOrder(IntegrationTestCase): bom_no = f"BOM-{fg_item_non_whole.item_code}-001" if not frappe.db.exists("BOM", bom_no): bom_doc = create_bom_with_process_loss_item( - fg_item_non_whole, bom_item, fg_qty=1, process_loss_percentage=10 + fg_item_non_whole, + bom_item, + fg_qty=1, + process_loss_percentage=10, + company="_Test Company", ) bom_doc.submit() @@ -1144,6 +1147,7 @@ class TestWorkOrder(IntegrationTestCase): "is_active": 1, "is_default": 1, "quantity": 1.0, + "company": "_Test Company", "with_operations": 1, "operations": [ { @@ -1235,9 +1239,7 @@ class TestWorkOrder(IntegrationTestCase): frappe.db.set_single_value("Manufacturing Settings", "backflush_raw_materials_based_on", "BOM") - @IntegrationTestCase.change_settings( - "Manufacturing Settings", {"make_serial_no_batch_from_work_order": 1} - ) + @ERPNextTestSuite.change_settings("Manufacturing Settings", {"make_serial_no_batch_from_work_order": 1}) def test_auto_batch_creation(self): from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom @@ -1258,9 +1260,8 @@ class TestWorkOrder(IntegrationTestCase): except frappe.MandatoryError: self.fail("Batch generation causing failing in Work Order") - @IntegrationTestCase.change_settings( - "Manufacturing Settings", {"make_serial_no_batch_from_work_order": 1} - ) + @ERPNextTestSuite.change_settings("Manufacturing Settings", {"make_serial_no_batch_from_work_order": 1}) + @ERPNextTestSuite.change_settings("Global Defaults", {"default_company": "_Test Company"}) def test_auto_serial_no_creation(self): from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom @@ -1293,9 +1294,8 @@ class TestWorkOrder(IntegrationTestCase): except frappe.MandatoryError: self.fail("Batch generation causing failing in Work Order") - @IntegrationTestCase.change_settings( - "Manufacturing Settings", {"make_serial_no_batch_from_work_order": 1} - ) + @ERPNextTestSuite.change_settings("Manufacturing Settings", {"make_serial_no_batch_from_work_order": 1}) + @ERPNextTestSuite.change_settings("Global Defaults", {"default_company": "_Test Company"}) def test_auto_serial_no_batch_creation(self): from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom @@ -1347,7 +1347,7 @@ class TestWorkOrder(IntegrationTestCase): return serial_nos - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Manufacturing Settings", {"backflush_raw_materials_based_on": "Material Transferred for Manufacture"}, ) @@ -1377,7 +1377,7 @@ class TestWorkOrder(IntegrationTestCase): for index, row in enumerate(ste_manu.get("items"), start=1): self.assertEqual(index, row.idx) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Manufacturing Settings", {"backflush_raw_materials_based_on": "Material Transferred for Manufacture"}, ) @@ -1883,6 +1883,7 @@ class TestWorkOrder(IntegrationTestCase): self.assertEqual(wo_doc.status, "Completed") return_ste_doc = make_stock_return_entry(wo_doc.name) + return_ste_doc.company = wo_doc.company return_ste_doc.save() self.assertTrue(return_ste_doc.is_return) @@ -2161,7 +2162,7 @@ class TestWorkOrder(IntegrationTestCase): frappe.db.set_single_value("Manufacturing Settings", "set_op_cost_and_scrap_from_sub_assemblies", 0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Manufacturing Settings", {"material_consumption": 1, "get_rm_cost_from_consumption_entry": 1} ) def test_get_rm_cost_from_consumption_entry(self): diff --git a/erpnext/manufacturing/doctype/workstation/test_records.json b/erpnext/manufacturing/doctype/workstation/test_records.json deleted file mode 100644 index 6d54cb29127..00000000000 --- a/erpnext/manufacturing/doctype/workstation/test_records.json +++ /dev/null @@ -1,19 +0,0 @@ -[ - { - "doctype": "Workstation", - "name": "_Test Workstation 1", - "workstation_name": "_Test Workstation 1", - "warehouse": "_Test warehouse - _TC", - "hour_rate_labour": 25, - "hour_rate_electricity": 25, - "hour_rate_consumable": 25, - "hour_rate_rent": 25, - "holiday_list": "_Test Holiday List", - "working_hours": [ - { - "start_time": "10:00:00", - "end_time": "20:00:00" - } - ] - } -] diff --git a/erpnext/manufacturing/doctype/workstation/test_workstation.py b/erpnext/manufacturing/doctype/workstation/test_workstation.py index 6a407c22b8c..424e467e39f 100644 --- a/erpnext/manufacturing/doctype/workstation/test_workstation.py +++ b/erpnext/manufacturing/doctype/workstation/test_workstation.py @@ -2,7 +2,6 @@ # See license.txt import frappe from frappe import _ -from frappe.tests import IntegrationTestCase from erpnext.manufacturing.doctype.operation.test_operation import make_operation from erpnext.manufacturing.doctype.routing.test_routing import create_routing, setup_bom @@ -11,11 +10,10 @@ from erpnext.manufacturing.doctype.workstation.workstation import ( WorkstationHolidayError, check_if_within_operating_hours, ) - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Warehouse"] +from erpnext.tests.utils import ERPNextTestSuite -class TestWorkstation(IntegrationTestCase): +class TestWorkstation(ERPNextTestSuite): def test_validate_timings(self): check_if_within_operating_hours( "_Test Workstation 1", "Operation 1", "2013-02-02 11:00:00", "2013-02-02 19:00:00" diff --git a/erpnext/manufacturing/doctype/workstation_cost/test_workstation_cost.py b/erpnext/manufacturing/doctype/workstation_cost/test_workstation_cost.py index ea948f62abc..e695b11bcb5 100644 --- a/erpnext/manufacturing/doctype/workstation_cost/test_workstation_cost.py +++ b/erpnext/manufacturing/doctype/workstation_cost/test_workstation_cost.py @@ -2,19 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class IntegrationTestWorkstationCost(IntegrationTestCase): - """ - Integration tests for WorkstationCost. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/manufacturing/doctype/workstation_operating_component/test_workstation_operating_component.py b/erpnext/manufacturing/doctype/workstation_operating_component/test_workstation_operating_component.py index 0d327c6473d..e695b11bcb5 100644 --- a/erpnext/manufacturing/doctype/workstation_operating_component/test_workstation_operating_component.py +++ b/erpnext/manufacturing/doctype/workstation_operating_component/test_workstation_operating_component.py @@ -2,19 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class IntegrationTestWorkstationOperatingComponent(IntegrationTestCase): - """ - Integration tests for WorkstationOperatingComponent. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/manufacturing/doctype/workstation_operating_component_account/test_workstation_operating_component_account.py b/erpnext/manufacturing/doctype/workstation_operating_component_account/test_workstation_operating_component_account.py index 3bf919b8df0..e695b11bcb5 100644 --- a/erpnext/manufacturing/doctype/workstation_operating_component_account/test_workstation_operating_component_account.py +++ b/erpnext/manufacturing/doctype/workstation_operating_component_account/test_workstation_operating_component_account.py @@ -2,19 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class IntegrationTestWorkstationOperatingComponentAccount(IntegrationTestCase): - """ - Integration tests for WorkstationOperatingComponentAccount. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/manufacturing/doctype/workstation_type/test_workstation_type.py b/erpnext/manufacturing/doctype/workstation_type/test_workstation_type.py index 7e62d4c4ffe..98461a72c98 100644 --- a/erpnext/manufacturing/doctype/workstation_type/test_workstation_type.py +++ b/erpnext/manufacturing/doctype/workstation_type/test_workstation_type.py @@ -2,10 +2,11 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestWorkstationType(IntegrationTestCase): +class TestWorkstationType(ERPNextTestSuite): pass diff --git a/erpnext/manufacturing/report/bom_stock_calculated/test_bom_stock_calculated.py b/erpnext/manufacturing/report/bom_stock_calculated/test_bom_stock_calculated.py index 6bbbacbeb77..e0105b114c5 100644 --- a/erpnext/manufacturing/report/bom_stock_calculated/test_bom_stock_calculated.py +++ b/erpnext/manufacturing/report/bom_stock_calculated/test_bom_stock_calculated.py @@ -1,16 +1,17 @@ # Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt -from frappe.tests import IntegrationTestCase +import frappe from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom from erpnext.manufacturing.report.bom_stock_calculated.bom_stock_calculated import ( execute as bom_stock_calculated_report, ) from erpnext.stock.doctype.item.test_item import make_item +from erpnext.tests.utils import ERPNextTestSuite -class TestBOMStockCalculated(IntegrationTestCase): +class TestBOMStockCalculated(ERPNextTestSuite): def setUp(self): self.fg_item, self.rm_items = create_items() self.boms = create_boms(self.fg_item, self.rm_items) @@ -57,6 +58,7 @@ def create_items(): "standard_rate": 100, "opening_stock": 100, "last_purchase_rate": 100, + "item_defaults": [{"company": "_Test Company", "default_warehouse": "Stores - _TC"}], } ).name rm_item2 = make_item( @@ -65,6 +67,7 @@ def create_items(): "standard_rate": 200, "opening_stock": 200, "last_purchase_rate": 200, + "item_defaults": [{"company": "_Test Company", "default_warehouse": "Stores - _TC"}], } ).name diff --git a/erpnext/manufacturing/report/bom_stock_report/test_bom_stock_report.py b/erpnext/manufacturing/report/bom_stock_report/test_bom_stock_report.py index 2bcb43b409f..43706fcb4de 100644 --- a/erpnext/manufacturing/report/bom_stock_report/test_bom_stock_report.py +++ b/erpnext/manufacturing/report/bom_stock_report/test_bom_stock_report.py @@ -4,7 +4,6 @@ import frappe from frappe.exceptions import ValidationError -from frappe.tests import IntegrationTestCase from frappe.utils import floor from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom @@ -13,9 +12,10 @@ from erpnext.manufacturing.report.bom_stock_report.bom_stock_report import ( ) from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestBomStockReport(IntegrationTestCase): +class TestBomStockReport(ERPNextTestSuite): def setUp(self): self.warehouse = "_Test Warehouse - _TC" self.fg_item, self.rm_items = create_items() diff --git a/erpnext/manufacturing/report/test_reports.py b/erpnext/manufacturing/report/test_reports.py index 6fcef563a8b..adeddd996a5 100644 --- a/erpnext/manufacturing/report/test_reports.py +++ b/erpnext/manufacturing/report/test_reports.py @@ -1,20 +1,14 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase -from erpnext.tests.utils import ReportFilters, ReportName, execute_script_report - -EXTRA_TEST_RECORD_DEPENDENCIES = ["BOM", "Item Price", "Warehouse"] +from erpnext.tests.utils import ERPNextTestSuite, ReportFilters, ReportName, execute_script_report -class TestManufacturingReports(IntegrationTestCase): +class TestManufacturingReports(ERPNextTestSuite): def setUp(self): self.setup_default_filters() - def tearDown(self): - frappe.db.rollback() - def setup_default_filters(self): self.last_bom = frappe.get_last_doc("BOM").name self.DEFAULT_FILTERS = { diff --git a/erpnext/projects/doctype/activity_cost/test_activity_cost.py b/erpnext/projects/doctype/activity_cost/test_activity_cost.py index 470b21cca87..73736e305b4 100644 --- a/erpnext/projects/doctype/activity_cost/test_activity_cost.py +++ b/erpnext/projects/doctype/activity_cost/test_activity_cost.py @@ -3,27 +3,25 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.projects.doctype.activity_cost.activity_cost import DuplicationError from erpnext.tests.utils import ERPNextTestSuite class TestActivityCost(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - # TODO: only 1 employee is required - cls.make_employees() - def test_duplication(self): + employee = frappe.db.get_all("Employee", filters={"first_name": "_Test Employee"})[0].name + activity_type = frappe.db.get_all( + "Activity Type", filters={"activity_type": "_Test Activity Type 1"} + )[0].name + frappe.db.sql("delete from `tabActivity Cost`") activity_cost1 = frappe.new_doc("Activity Cost") activity_cost1.update( { - "employee": self.employees[0].name, - "employee_name": self.employees[0].first_name, - "activity_type": "_Test Activity Type 1", + "employee": employee, + "employee_name": employee, + "activity_type": activity_type, "billing_rate": 100, "costing_rate": 50, } diff --git a/erpnext/projects/doctype/activity_cost/test_records.json b/erpnext/projects/doctype/activity_cost/test_records.json deleted file mode 100644 index 0637a088a01..00000000000 --- a/erpnext/projects/doctype/activity_cost/test_records.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/erpnext/projects/doctype/activity_type/test_records.json b/erpnext/projects/doctype/activity_type/test_records.json deleted file mode 100644 index 45fc1496fbe..00000000000 --- a/erpnext/projects/doctype/activity_type/test_records.json +++ /dev/null @@ -1,11 +0,0 @@ -[ - { - "activity_type": "_Test Activity Type" - }, - { - "activity_type": "_Test Activity Type 1" - }, - { - "activity_type": "_Test Activity Type 2" - } -] \ No newline at end of file diff --git a/erpnext/projects/doctype/project/test_project.py b/erpnext/projects/doctype/project/test_project.py index 2f1974ee4cb..aa37c34ef89 100644 --- a/erpnext/projects/doctype/project/test_project.py +++ b/erpnext/projects/doctype/project/test_project.py @@ -2,7 +2,6 @@ # License: GNU General Public License v3. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, getdate, nowdate from erpnext.projects.doctype.project_template.test_project_template import make_project_template @@ -11,21 +10,14 @@ from erpnext.selling.doctype.sales_order.sales_order import make_project as make from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.tests.utils import ERPNextTestSuite -IGNORE_TEST_RECORD_DEPENDENCIES = ["Sales Order"] - class TestProject(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.make_projects() - def test_project_total_costing_and_billing_amount(self): from erpnext.projects.doctype.timesheet.test_timesheet import make_timesheet from erpnext.setup.doctype.employee.test_employee import make_employee project_name = "Test Project Costing" - employee = make_employee("employee@frappe.io") + employee = make_employee("employee@frappe.io", company="_Test Company") project = make_project({"project_name": project_name}) timesheet = make_timesheet( employee=employee, diff --git a/erpnext/projects/doctype/project_template/test_project_template.py b/erpnext/projects/doctype/project_template/test_project_template.py index 2671d7a02ec..72ccbbfad70 100644 --- a/erpnext/projects/doctype/project_template/test_project_template.py +++ b/erpnext/projects/doctype/project_template/test_project_template.py @@ -3,12 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.projects.doctype.task.test_task import create_task +from erpnext.tests.utils import ERPNextTestSuite -class TestProjectTemplate(IntegrationTestCase): +class TestProjectTemplate(ERPNextTestSuite): pass diff --git a/erpnext/projects/doctype/project_type/test_project_type.py b/erpnext/projects/doctype/project_type/test_project_type.py index 31e0f840db3..51038e61c06 100644 --- a/erpnext/projects/doctype/project_type/test_project_type.py +++ b/erpnext/projects/doctype/project_type/test_project_type.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestProjectType(IntegrationTestCase): +class TestProjectType(ERPNextTestSuite): pass diff --git a/erpnext/projects/doctype/project_update/test_project_update.py b/erpnext/projects/doctype/project_update/test_project_update.py index 51f0ce14ac9..5a64a32706a 100644 --- a/erpnext/projects/doctype/project_update/test_project_update.py +++ b/erpnext/projects/doctype/project_update/test_project_update.py @@ -2,9 +2,8 @@ # See license.txt import unittest -import frappe -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestProjectUpdate(IntegrationTestCase): +class TestProjectUpdate(ERPNextTestSuite): pass diff --git a/erpnext/projects/doctype/projects_settings/test_projects_settings.py b/erpnext/projects/doctype/projects_settings/test_projects_settings.py index 06ecd2ad5dd..55878f54f73 100644 --- a/erpnext/projects/doctype/projects_settings/test_projects_settings.py +++ b/erpnext/projects/doctype/projects_settings/test_projects_settings.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestProjectsSettings(IntegrationTestCase): +class TestProjectsSettings(ERPNextTestSuite): pass diff --git a/erpnext/projects/doctype/task/test_task.py b/erpnext/projects/doctype/task/test_task.py index 30e35362aa9..0d02fa9c9fb 100644 --- a/erpnext/projects/doctype/task/test_task.py +++ b/erpnext/projects/doctype/task/test_task.py @@ -2,7 +2,6 @@ # License: GNU General Public License v3. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, getdate, nowdate from erpnext.projects.doctype.task.task import CircularReferenceError, ParentIsGroupError @@ -10,18 +9,13 @@ from erpnext.tests.utils import ERPNextTestSuite class TestTask(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.make_projects() - def test_task_total_costing_and_billing_amount(self): from erpnext.projects.doctype.project.test_project import make_project from erpnext.projects.doctype.timesheet.test_timesheet import make_timesheet from erpnext.setup.doctype.employee.test_employee import make_employee project_name = "Test Project Costing" - employee = make_employee("employee@frappe.io") + employee = make_employee("employee@frappe.io", company="_Test Company") project = make_project({"project_name": project_name}) task = create_task("_Test Task 1") task.project = project.name diff --git a/erpnext/projects/doctype/task_type/test_task_type.py b/erpnext/projects/doctype/task_type/test_task_type.py index 9f34e97592e..de544f1b007 100644 --- a/erpnext/projects/doctype/task_type/test_task_type.py +++ b/erpnext/projects/doctype/task_type/test_task_type.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestTaskType(IntegrationTestCase): +class TestTaskType(ERPNextTestSuite): pass diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py index c1f6e8d5dd9..f1a0f6edfd9 100644 --- a/erpnext/projects/doctype/timesheet/test_timesheet.py +++ b/erpnext/projects/doctype/timesheet/test_timesheet.py @@ -4,7 +4,6 @@ import datetime import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_to_date, now_datetime, nowdate from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_sales_return @@ -16,14 +15,6 @@ from erpnext.tests.utils import ERPNextTestSuite class TestTimesheet(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.make_projects() - - def setUp(self): - frappe.db.delete("Timesheet") - def test_timesheet_post_update(self): frappe.get_doc( { @@ -74,7 +65,7 @@ class TestTimesheet(ERPNextTestSuite): ) def test_timesheet_base_amount(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company="_Test Company") timesheet = make_timesheet(emp, simulate=True, is_billable=1) self.assertEqual(timesheet.time_logs[0].base_billing_rate, 50) @@ -83,7 +74,7 @@ class TestTimesheet(ERPNextTestSuite): self.assertEqual(timesheet.time_logs[0].base_costing_amount, 40) def test_timesheet_billing_amount(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company="_Test Company") timesheet = make_timesheet(emp, simulate=True, is_billable=1) self.assertEqual(timesheet.total_hours, 2) @@ -93,7 +84,7 @@ class TestTimesheet(ERPNextTestSuite): self.assertEqual(timesheet.total_billable_amount, 100) def test_timesheet_billing_amount_not_billable(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company="_Test Company") timesheet = make_timesheet(emp, simulate=True, is_billable=0) self.assertEqual(timesheet.total_hours, 2) @@ -103,7 +94,7 @@ class TestTimesheet(ERPNextTestSuite): self.assertEqual(timesheet.total_billable_amount, 0) def test_sales_invoice_from_timesheet(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company="_Test Company") timesheet = make_timesheet(emp, simulate=True, is_billable=1) sales_invoice = make_sales_invoice(timesheet.name, "_Test Item", "_Test Customer", currency="INR") @@ -119,9 +110,9 @@ class TestTimesheet(ERPNextTestSuite): self.assertEqual(item.qty, 2.00) self.assertEqual(item.rate, 50.00) - @IntegrationTestCase.change_settings("Projects Settings", {"fetch_timesheet_in_sales_invoice": 1}) + @ERPNextTestSuite.change_settings("Projects Settings", {"fetch_timesheet_in_sales_invoice": 1}) def test_timesheet_billing_based_on_project(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company="_Test Company") project = frappe.get_value("Project", {"project_name": "_Test Project"}) timesheet = make_timesheet( @@ -137,7 +128,7 @@ class TestTimesheet(ERPNextTestSuite): self.assertEqual(ts.time_logs[0].sales_invoice, sales_invoice.name) def test_timesheet_time_overlap(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company="_Test Company") settings = frappe.get_single("Projects Settings") initial_setting = settings.ignore_employee_time_overlap @@ -193,7 +184,7 @@ class TestTimesheet(ERPNextTestSuite): settings.save() def test_timesheet_not_overlapping_with_continuous_timelogs(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company="_Test Company") update_activity_type("_Test Activity Type") timesheet = frappe.new_doc("Timesheet") @@ -222,7 +213,7 @@ class TestTimesheet(ERPNextTestSuite): timesheet.save() # should not throw an error def test_to_time(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company="_Test Company") from_time = now_datetime() timesheet = frappe.new_doc("Timesheet") @@ -288,7 +279,7 @@ class TestTimesheet(ERPNextTestSuite): This test ensures Timesheet status is recalculated correctly across billing and return lifecycle events. """ - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company="_Test Company") timesheet = make_timesheet(emp, simulate=True, is_billable=1, do_not_submit=True) timesheet_detail = timesheet.append("time_logs", {}) diff --git a/erpnext/projects/report/delayed_tasks_summary/test_delayed_tasks_summary.py b/erpnext/projects/report/delayed_tasks_summary/test_delayed_tasks_summary.py index 20c74ef5e80..0b34778ea26 100644 --- a/erpnext/projects/report/delayed_tasks_summary/test_delayed_tasks_summary.py +++ b/erpnext/projects/report/delayed_tasks_summary/test_delayed_tasks_summary.py @@ -1,14 +1,14 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_months, nowdate from erpnext.projects.doctype.task.test_task import create_task from erpnext.projects.report.delayed_tasks_summary.delayed_tasks_summary import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestDelayedTasksSummary(IntegrationTestCase): +class TestDelayedTasksSummary(ERPNextTestSuite): @classmethod def setUp(self): task1 = create_task("_Test Task 98", add_days(nowdate(), -10), nowdate()) @@ -43,7 +43,3 @@ class TestDelayedTasksSummary(IntegrationTestCase): for key in ["subject", "status", "priority", "delay"]: self.assertEqual(expected_data[1].get(key), data.get(key)) - - def tearDown(self): - for task in ["_Test Task 98", "_Test Task 99"]: - frappe.get_doc("Task", {"subject": task}).delete() diff --git a/erpnext/quality_management/doctype/non_conformance/test_non_conformance.py b/erpnext/quality_management/doctype/non_conformance/test_non_conformance.py index 68b6536cc18..ea764a7b81d 100644 --- a/erpnext/quality_management/doctype/non_conformance/test_non_conformance.py +++ b/erpnext/quality_management/doctype/non_conformance/test_non_conformance.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestNonConformance(IntegrationTestCase): +class TestNonConformance(ERPNextTestSuite): pass diff --git a/erpnext/quality_management/doctype/quality_action/test_quality_action.py b/erpnext/quality_management/doctype/quality_action/test_quality_action.py index 1e1dfc376bc..9cd28e7c2e6 100644 --- a/erpnext/quality_management/doctype/quality_action/test_quality_action.py +++ b/erpnext/quality_management/doctype/quality_action/test_quality_action.py @@ -2,9 +2,9 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestQualityAction(IntegrationTestCase): +class TestQualityAction(ERPNextTestSuite): # quality action has no code pass diff --git a/erpnext/quality_management/doctype/quality_feedback/test_quality_feedback.py b/erpnext/quality_management/doctype/quality_feedback/test_quality_feedback.py index 35a326ad943..310e4789a94 100644 --- a/erpnext/quality_management/doctype/quality_feedback/test_quality_feedback.py +++ b/erpnext/quality_management/doctype/quality_feedback/test_quality_feedback.py @@ -3,10 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestQualityFeedback(IntegrationTestCase): +class TestQualityFeedback(ERPNextTestSuite): def test_quality_feedback(self): template = frappe.get_doc( doctype="Quality Feedback Template", diff --git a/erpnext/quality_management/doctype/quality_feedback_template/test_quality_feedback_template.py b/erpnext/quality_management/doctype/quality_feedback_template/test_quality_feedback_template.py index 2064bbc5513..ec4c4c2b922 100644 --- a/erpnext/quality_management/doctype/quality_feedback_template/test_quality_feedback_template.py +++ b/erpnext/quality_management/doctype/quality_feedback_template/test_quality_feedback_template.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestQualityFeedbackTemplate(IntegrationTestCase): +class TestQualityFeedbackTemplate(ERPNextTestSuite): pass diff --git a/erpnext/quality_management/doctype/quality_goal/test_quality_goal.py b/erpnext/quality_management/doctype/quality_goal/test_quality_goal.py index 57d0a94ed0a..7a4bfc7d864 100644 --- a/erpnext/quality_management/doctype/quality_goal/test_quality_goal.py +++ b/erpnext/quality_management/doctype/quality_goal/test_quality_goal.py @@ -3,10 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestQualityGoal(IntegrationTestCase): +class TestQualityGoal(ERPNextTestSuite): def test_quality_goal(self): # no code, just a basic sanity check goal = get_quality_goal() diff --git a/erpnext/quality_management/doctype/quality_meeting/test_quality_meeting.py b/erpnext/quality_management/doctype/quality_meeting/test_quality_meeting.py index e0ff7d77f24..7ac01008f66 100644 --- a/erpnext/quality_management/doctype/quality_meeting/test_quality_meeting.py +++ b/erpnext/quality_management/doctype/quality_meeting/test_quality_meeting.py @@ -2,9 +2,9 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestQualityMeeting(IntegrationTestCase): +class TestQualityMeeting(ERPNextTestSuite): # nothing to test pass diff --git a/erpnext/quality_management/doctype/quality_meeting_agenda/test_quality_meeting_agenda.py b/erpnext/quality_management/doctype/quality_meeting_agenda/test_quality_meeting_agenda.py index e83a3e394e1..cca2b7d6267 100644 --- a/erpnext/quality_management/doctype/quality_meeting_agenda/test_quality_meeting_agenda.py +++ b/erpnext/quality_management/doctype/quality_meeting_agenda/test_quality_meeting_agenda.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestQualityMeetingAgenda(IntegrationTestCase): +class TestQualityMeetingAgenda(ERPNextTestSuite): pass diff --git a/erpnext/quality_management/doctype/quality_procedure/test_quality_procedure.py b/erpnext/quality_management/doctype/quality_procedure/test_quality_procedure.py index 64022ec4c37..e4d847159f6 100644 --- a/erpnext/quality_management/doctype/quality_procedure/test_quality_procedure.py +++ b/erpnext/quality_management/doctype/quality_procedure/test_quality_procedure.py @@ -2,12 +2,13 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite from .quality_procedure import add_node -class TestQualityProcedure(IntegrationTestCase): +class TestQualityProcedure(ERPNextTestSuite): def test_add_node(self): procedure = create_procedure( { diff --git a/erpnext/quality_management/doctype/quality_review/test_quality_review.py b/erpnext/quality_management/doctype/quality_review/test_quality_review.py index a3c78c5a416..fd550762ccf 100644 --- a/erpnext/quality_management/doctype/quality_review/test_quality_review.py +++ b/erpnext/quality_management/doctype/quality_review/test_quality_review.py @@ -3,13 +3,14 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite from ..quality_goal.test_quality_goal import get_quality_goal from .quality_review import review -class TestQualityReview(IntegrationTestCase): +class TestQualityReview(ERPNextTestSuite): def test_review_creation(self): quality_goal = get_quality_goal() review() diff --git a/erpnext/regional/doctype/import_supplier_invoice/test_import_supplier_invoice.py b/erpnext/regional/doctype/import_supplier_invoice/test_import_supplier_invoice.py index 7d512dbfb55..07005ee1b60 100644 --- a/erpnext/regional/doctype/import_supplier_invoice/test_import_supplier_invoice.py +++ b/erpnext/regional/doctype/import_supplier_invoice/test_import_supplier_invoice.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestImportSupplierInvoice(IntegrationTestCase): +class TestImportSupplierInvoice(ERPNextTestSuite): pass diff --git a/erpnext/regional/doctype/lower_deduction_certificate/test_lower_deduction_certificate.py b/erpnext/regional/doctype/lower_deduction_certificate/test_lower_deduction_certificate.py index f6ceb56557b..58b874c0880 100644 --- a/erpnext/regional/doctype/lower_deduction_certificate/test_lower_deduction_certificate.py +++ b/erpnext/regional/doctype/lower_deduction_certificate/test_lower_deduction_certificate.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestLowerDeductionCertificate(IntegrationTestCase): +class TestLowerDeductionCertificate(ERPNextTestSuite): pass diff --git a/erpnext/regional/doctype/south_africa_vat_settings/test_south_africa_vat_settings.py b/erpnext/regional/doctype/south_africa_vat_settings/test_south_africa_vat_settings.py index 9ed34764f70..0bb509a430a 100644 --- a/erpnext/regional/doctype/south_africa_vat_settings/test_south_africa_vat_settings.py +++ b/erpnext/regional/doctype/south_africa_vat_settings/test_south_africa_vat_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSouthAfricaVATSettings(IntegrationTestCase): +class TestSouthAfricaVATSettings(ERPNextTestSuite): pass diff --git a/erpnext/regional/doctype/uae_vat_settings/test_uae_vat_settings.py b/erpnext/regional/doctype/uae_vat_settings/test_uae_vat_settings.py index 8d21d08b798..4251b4ffe54 100644 --- a/erpnext/regional/doctype/uae_vat_settings/test_uae_vat_settings.py +++ b/erpnext/regional/doctype/uae_vat_settings/test_uae_vat_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestUAEVATSettings(IntegrationTestCase): +class TestUAEVATSettings(ERPNextTestSuite): pass diff --git a/erpnext/regional/report/uae_vat_201/test_uae_vat_201.py b/erpnext/regional/report/uae_vat_201/test_uae_vat_201.py index 40687aeb9f8..fd4c69e8f8a 100644 --- a/erpnext/regional/report/uae_vat_201/test_uae_vat_201.py +++ b/erpnext/regional/report/uae_vat_201/test_uae_vat_201.py @@ -15,18 +15,11 @@ from erpnext.regional.report.uae_vat_201.uae_vat_201 import ( get_zero_rated_total, ) from erpnext.stock.doctype.warehouse.test_warehouse import get_warehouse_account - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Territory", "Customer Group", "Supplier Group", "Item"] +from erpnext.tests.utils import ERPNextTestSuite -class TestUaeVat201(TestCase): +class TestUaeVat201(ERPNextTestSuite): def setUp(self): - frappe.set_user("Administrator") - - frappe.db.sql("delete from `tabSales Invoice` where company='_Test Company UAE VAT'") - frappe.db.sql("delete from `tabPurchase Invoice` where company='_Test Company UAE VAT'") - - make_company("_Test Company UAE VAT", "_TCUV") set_vat_accounts() make_customer() @@ -63,6 +56,9 @@ class TestUaeVat201(TestCase): self.assertEqual(get_standard_rated_expenses_total(filters), 250) self.assertEqual(get_standard_rated_expenses_tax(filters), 1) + @ERPNextTestSuite.change_settings( + "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": True} + ) def test_uae_vat_201_report_with_foreign_transaction(self): pi = make_purchase_invoice( company="_Test Company UAE VAT", @@ -95,31 +91,6 @@ class TestUaeVat201(TestCase): self.assertEqual(get_standard_rated_expenses_tax(filters), 50) -def make_company(company_name, abbr): - if not frappe.db.exists("Company", company_name): - company = frappe.get_doc( - { - "doctype": "Company", - "company_name": company_name, - "abbr": abbr, - "default_currency": "AED", - "country": "United Arab Emirates", - "create_chart_of_accounts_based_on": "Standard Template", - } - ) - company.insert() - else: - company = frappe.get_doc("Company", company_name) - - company.create_default_warehouses() - - if not frappe.db.get_value("Cost Center", {"is_group": 0, "company": company.name}): - company.create_default_cost_center() - - company.save() - return company - - def set_vat_accounts(): if not frappe.db.exists("UAE VAT Settings", "_Test Company UAE VAT"): vat_accounts = frappe.get_all( diff --git a/erpnext/regional/report/vat_audit_report/test_vat_audit_report.py b/erpnext/regional/report/vat_audit_report/test_vat_audit_report.py index a898a251043..ded1bde3133 100644 --- a/erpnext/regional/report/vat_audit_report/test_vat_audit_report.py +++ b/erpnext/regional/report/vat_audit_report/test_vat_audit_report.py @@ -11,11 +11,11 @@ from erpnext.accounts.doctype.account.test_account import create_account from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.regional.report.vat_audit_report.vat_audit_report import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestVATAuditReport(TestCase): +class TestVATAuditReport(ERPNextTestSuite): def setUp(self): - frappe.set_user("Administrator") make_company("_Test Company SA VAT", "_TCSV") create_account( @@ -41,10 +41,6 @@ class TestVATAuditReport(TestCase): make_sales_invoices() create_purchase_invoices() - def tearDown(self): - frappe.db.sql("delete from `tabSales Invoice` where company='_Test Company SA VAT'") - frappe.db.sql("delete from `tabPurchase Invoice` where company='_Test Company SA VAT'") - def test_vat_audit_report(self): filters = {"company": "_Test Company SA VAT", "from_date": today(), "to_date": today()} columns, data = execute(filters) diff --git a/erpnext/regional/united_states/test_united_states.py b/erpnext/regional/united_states/test_united_states.py index d3e7dcda620..e6626da8dcf 100644 --- a/erpnext/regional/united_states/test_united_states.py +++ b/erpnext/regional/united_states/test_united_states.py @@ -3,27 +3,20 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.regional.report.irs_1099.irs_1099 import execute as execute_1099_report +from erpnext.tests.utils import ERPNextTestSuite -class TestUnitedStates(IntegrationTestCase): +class TestUnitedStates(ERPNextTestSuite): def test_irs_1099_custom_field(self): if not frappe.db.exists("Supplier", "_US 1099 Test Supplier"): - doc = frappe.new_doc("Supplier") - doc.supplier_name = "_US 1099 Test Supplier" - doc.supplier_group = "Services" - doc.supplier_type = "Company" - doc.country = "United States" - doc.tax_id = "04-1234567" - doc.irs_1099 = 1 - doc.save() - frappe.db.commit() + make_irs_1099_supplier() supplier = frappe.get_doc("Supplier", "_US 1099 Test Supplier") self.assertEqual(supplier.irs_1099, 1) def test_irs_1099_report(self): + make_irs_1099_supplier() make_payment_entry_to_irs_1099_supplier() filters = frappe._dict({"fiscal_year": "_Test Fiscal Year 2016", "company": "_Test Company 1"}) columns, data = execute_1099_report(filters) @@ -36,11 +29,19 @@ class TestUnitedStates(IntegrationTestCase): self.assertEqual(data[0], expected_row) -def make_payment_entry_to_irs_1099_supplier(): - frappe.db.sql("delete from `tabGL Entry` where party='_US 1099 Test Supplier'") - frappe.db.sql("delete from `tabGL Entry` where against='_US 1099 Test Supplier'") - frappe.db.sql("delete from `tabPayment Entry` where party='_US 1099 Test Supplier'") +def make_irs_1099_supplier(): + doc = frappe.new_doc("Supplier") + doc.supplier_name = "_US 1099 Test Supplier" + doc.supplier_group = "Services" + doc.supplier_type = "Company" + doc.country = "United States" + doc.tax_id = "04-1234567" + doc.irs_1099 = 1 + doc.save() + return doc + +def make_payment_entry_to_irs_1099_supplier(): pe = frappe.new_doc("Payment Entry") pe.payment_type = "Pay" pe.company = "_Test Company 1" diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py index 2e7b7233fb1..211343966f9 100644 --- a/erpnext/selling/doctype/customer/test_customer.py +++ b/erpnext/selling/doctype/customer/test_customer.py @@ -5,7 +5,6 @@ import json import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import flt from erpnext.accounts.party import get_due_date @@ -15,16 +14,10 @@ from erpnext.selling.doctype.customer.customer import ( get_customer_outstanding, parse_full_name, ) -from erpnext.tests.utils import create_test_contact_and_address - -IGNORE_TEST_RECORD_DEPENDENCIES = ["Price List"] -EXTRA_TEST_RECORD_DEPENDENCIES = ["Payment Term", "Payment Terms Template"] +from erpnext.tests.utils import ERPNextTestSuite, create_test_contact_and_address -class TestCustomer(IntegrationTestCase): - def tearDown(self): - set_credit_limit("_Test Customer", "_Test Company", 0) - +class TestCustomer(ERPNextTestSuite): def test_get_customer_group_details(self): doc = frappe.new_doc("Customer Group") doc.customer_group_name = "_Testing Customer Group" @@ -96,14 +89,11 @@ class TestCustomer(IntegrationTestCase): def test_party_details_tax_category(self): from erpnext.accounts.party import get_party_details - frappe.delete_doc_if_exists("Address", "_Test Address With Tax Category-Billing") - frappe.delete_doc_if_exists("Address", "_Test Address With Tax Category-Shipping") - # Tax Category without Address details = get_party_details("_Test Customer With Tax Category") self.assertEqual(details.tax_category, "_Test Tax Category 1") - billing_address = frappe.get_doc( + frappe.get_doc( doctype="Address", address_title="_Test Address With Tax Category", tax_category="_Test Tax Category 2", @@ -111,9 +101,10 @@ class TestCustomer(IntegrationTestCase): address_line1="Station Road", city="_Test City", country="India", + is_primary_address=True, links=[dict(link_doctype="Customer", link_name="_Test Customer With Tax Category")], ).insert() - shipping_address = frappe.get_doc( + frappe.get_doc( doctype="Address", address_title="_Test Address With Tax Category", tax_category="_Test Tax Category 3", @@ -121,6 +112,7 @@ class TestCustomer(IntegrationTestCase): address_line1="Station Road", city="_Test City", country="India", + is_shipping_address=True, links=[dict(link_doctype="Customer", link_name="_Test Customer With Tax Category")], ).insert() @@ -142,8 +134,6 @@ class TestCustomer(IntegrationTestCase): # Rollback settings.determine_address_tax_category_from = rollback_setting settings.save() - billing_address.delete() - shipping_address.delete() def test_rename(self): # delete communication linked to these 2 customers @@ -184,8 +174,6 @@ class TestCustomer(IntegrationTestCase): # rename back to original frappe.rename_doc("Customer", new_name, "_Test Customer 1") - frappe.db.rollback() - def test_freezed_customer(self): frappe.db.set_value("Customer", "_Test Customer", "is_frozen", 1) diff --git a/erpnext/selling/doctype/customer/test_records.json b/erpnext/selling/doctype/customer/test_records.json deleted file mode 100644 index 6040f4dd75b..00000000000 --- a/erpnext/selling/doctype/customer/test_records.json +++ /dev/null @@ -1,64 +0,0 @@ -[ - { - "customer_group": "_Test Customer Group", - "customer_name": "_Test Customer With Template", - "customer_type": "Individual", - "doctype": "Customer", - "territory": "_Test Territory" - }, - { - "customer_group": "_Test Customer Group", - "customer_name": "_Test Customer P", - "customer_type": "Individual", - "doctype": "Customer", - "territory": "_Test Territory" - }, - { - "customer_group": "_Test Customer Group", - "customer_name": "_Test Customer", - "customer_type": "Individual", - "doctype": "Customer", - "territory": "_Test Territory" - }, - { - "customer_group": "_Test Customer Group", - "customer_name": "_Test Customer 1", - "customer_type": "Individual", - "doctype": "Customer", - "territory": "_Test Territory" - }, - { - "customer_group": "_Test Customer Group", - "customer_name": "_Test Customer 2", - "customer_type": "Individual", - "doctype": "Customer", - "territory": "_Test Territory" - }, - { - "customer_group": "_Test Customer Group", - "customer_name": "_Test Customer 3", - "customer_type": "Individual", - "doctype": "Customer", - "territory": "_Test Territory" - }, - { - "customer_group": "_Test Customer Group", - "customer_name": "_Test Customer USD", - "customer_type": "Individual", - "doctype": "Customer", - "territory": "_Test Territory", - "default_currency": "USD", - "accounts": [{ - "company": "_Test Company", - "account": "_Test Receivable USD - _TC" - }] - }, - { - "customer_group": "_Test Customer Group", - "customer_name": "_Test Customer With Tax Category", - "customer_type": "Individual", - "doctype": "Customer", - "territory": "_Test Territory", - "tax_category": "_Test Tax Category 1" - } -] diff --git a/erpnext/selling/doctype/delivery_schedule_item/test_delivery_schedule_item.py b/erpnext/selling/doctype/delivery_schedule_item/test_delivery_schedule_item.py index d941e415c57..e695b11bcb5 100644 --- a/erpnext/selling/doctype/delivery_schedule_item/test_delivery_schedule_item.py +++ b/erpnext/selling/doctype/delivery_schedule_item/test_delivery_schedule_item.py @@ -2,19 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class IntegrationTestDeliveryScheduleItem(IntegrationTestCase): - """ - Integration tests for DeliveryScheduleItem. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/selling/doctype/industry_type/test_records.json b/erpnext/selling/doctype/industry_type/test_records.json deleted file mode 100644 index 2b593bb3ac2..00000000000 --- a/erpnext/selling/doctype/industry_type/test_records.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "doctype": "Industry Type", - "industry": "_Test Industry" - }, - { - "doctype": "Industry Type", - "industry": "_Test Industry 1" - } -] \ No newline at end of file diff --git a/erpnext/selling/doctype/installation_note/test_installation_note.py b/erpnext/selling/doctype/installation_note/test_installation_note.py index c6d1786cdee..62c5b761014 100644 --- a/erpnext/selling/doctype/installation_note/test_installation_note.py +++ b/erpnext/selling/doctype/installation_note/test_installation_note.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestInstallationNote(IntegrationTestCase): +class TestInstallationNote(ERPNextTestSuite): pass diff --git a/erpnext/selling/doctype/installation_note/test_records.json b/erpnext/selling/doctype/installation_note/test_records.json deleted file mode 100644 index 0d4f101c7a3..00000000000 --- a/erpnext/selling/doctype/installation_note/test_records.json +++ /dev/null @@ -1,2 +0,0 @@ -[ -] diff --git a/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py b/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py index 218a3e7c696..a94837452e6 100644 --- a/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py +++ b/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py @@ -2,11 +2,9 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from erpnext.controllers.queries import item_query - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Customer", "Supplier"] +from erpnext.tests.utils import ERPNextTestSuite def create_party_specific_item(**args): @@ -18,37 +16,38 @@ def create_party_specific_item(**args): psi.insert() -class TestPartySpecificItem(IntegrationTestCase): - def setUp(self): - self.customer = frappe.get_last_doc("Customer") - self.supplier = frappe.get_last_doc("Supplier") - self.item = frappe.get_last_doc("Item") - +class TestPartySpecificItem(ERPNextTestSuite): def test_item_query_for_customer(self): + customer = "_Test Customer With Template" + item = "_Test Item" + create_party_specific_item( party_type="Customer", - party=self.customer.name, + party=customer, restrict_based_on="Item", - based_on_value=self.item.name, + based_on_value=item, ) - filters = {"is_sales_item": 1, "customer": self.customer.name} + filters = {"is_sales_item": 1, "customer": customer} items = item_query( doctype="Item", txt="", searchfield="name", start=0, page_len=20, filters=filters, as_dict=False ) - self.assertTrue(self.item.name in flatten(items)) + self.assertTrue(item in flatten(items)) def test_item_query_for_supplier(self): + supplier = "_Test Supplier With Template 1" + item = "_Test Item Group" + create_party_specific_item( party_type="Supplier", - party=self.supplier.name, + party=supplier, restrict_based_on="Item Group", - based_on_value=self.item.item_group, + based_on_value=item, ) - filters = {"supplier": self.supplier.name, "is_purchase_item": 1} + filters = {"supplier": supplier, "is_purchase_item": 1} items = item_query( doctype="Item", txt="", searchfield="name", start=0, page_len=20, filters=filters, as_dict=False ) - self.assertTrue(self.item.item_group in flatten(items)) + self.assertTrue(item in flatten(items)) def flatten(lst): diff --git a/erpnext/selling/doctype/product_bundle/test_records.json b/erpnext/selling/doctype/product_bundle/test_records.json deleted file mode 100644 index b92892f1bf4..00000000000 --- a/erpnext/selling/doctype/product_bundle/test_records.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "doctype": "Product Bundle", - "new_item_code": "_Test Product Bundle Item", - "items": [ - { - "doctype": "Product Bundle Item", - "item_code": "_Test Item", - "parentfield": "items", - "qty": 5.0 - }, - { - "doctype": "Product Bundle Item", - "item_code": "_Test Item Home Desktop 100", - "parentfield": "items", - "qty": 2.0 - } - ] - } -] \ No newline at end of file diff --git a/erpnext/selling/doctype/quotation/test_quotation.py b/erpnext/selling/doctype/quotation/test_quotation.py index 367b7bae0f9..b841f456bc9 100644 --- a/erpnext/selling/doctype/quotation/test_quotation.py +++ b/erpnext/selling/doctype/quotation/test_quotation.py @@ -4,17 +4,18 @@ import json import frappe -from frappe.tests import IntegrationTestCase, change_settings +from frappe.tests import change_settings from frappe.utils import add_days, add_months, flt, getdate, nowdate from erpnext.controllers.accounts_controller import InvalidQtyError, update_child_qty_rate from erpnext.selling.doctype.quotation.quotation import make_sales_order -from erpnext.setup.utils import get_exchange_rate - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Product Bundle"] +from erpnext.tests.utils import ERPNextTestSuite -class TestQuotation(IntegrationTestCase): +class TestQuotation(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Quotation") + def test_update_child_quotation_add_item(self): from erpnext.stock.doctype.item.test_item import make_item @@ -182,7 +183,7 @@ class TestQuotation(IntegrationTestCase): self.assertTrue(quotation.payment_schedule) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"automatically_fetch_payment_terms": 1}, ) @@ -326,7 +327,7 @@ class TestQuotation(IntegrationTestCase): sales_order.delivery_date = nowdate() sales_order.insert() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", { "add_taxes_from_item_tax_template": 0, @@ -876,7 +877,7 @@ class TestQuotation(IntegrationTestCase): quotation.items[0].conversion_factor = 2.23 self.assertRaises(frappe.ValidationError, quotation.save) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"add_taxes_from_item_tax_template": 1, "add_taxes_from_taxes_and_charges_template": 0}, ) @@ -944,7 +945,7 @@ class TestQuotation(IntegrationTestCase): self.assertEqual(quotation.rounding_adjustment, 0) self.assertEqual(quotation.rounded_total, 0) - @IntegrationTestCase.change_settings("Selling Settings", {"allow_zero_qty_in_quotation": 1}) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_zero_qty_in_quotation": 1}) def test_so_from_zero_qty_quotation(self): from erpnext.selling.doctype.quotation.quotation import make_sales_order from erpnext.stock.doctype.item.test_item import make_item @@ -977,6 +978,7 @@ class TestQuotation(IntegrationTestCase): quotation.reload() self.assertEqual(quotation.status, "Ordered") + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_duplicate_items_in_quotation(self): from erpnext.selling.doctype.quotation.quotation import make_sales_order from erpnext.stock.doctype.item.test_item import make_item @@ -1023,7 +1025,7 @@ class TestQuotation(IntegrationTestCase): quotation.reload() self.assertEqual(quotation.status, "Ordered") - @change_settings("Accounts Settings", {"allow_pegged_currencies_exchange_rates": True}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"allow_pegged_currencies_exchange_rates": True}) def test_make_quotation_qar_to_inr(self): quotation = make_quotation( currency="QAR", @@ -1076,7 +1078,7 @@ class TestQuotation(IntegrationTestCase): quotation.reload() self.assertEqual(quotation.status, "Open") - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"automatically_fetch_payment_terms": 1}, ) diff --git a/erpnext/selling/doctype/quotation/test_records.json b/erpnext/selling/doctype/quotation/test_records.json index 1564f7de0ce..8bab707ad70 100644 --- a/erpnext/selling/doctype/quotation/test_records.json +++ b/erpnext/selling/doctype/quotation/test_records.json @@ -34,4 +34,4 @@ "transaction_date": "2013-02-21", "valid_till": "2013-03-21" } -] \ No newline at end of file +] diff --git a/erpnext/selling/doctype/sales_order/test_records.json b/erpnext/selling/doctype/sales_order/test_records.json index 8a090e6d3d3..b2957cb3929 100644 --- a/erpnext/selling/doctype/sales_order/test_records.json +++ b/erpnext/selling/doctype/sales_order/test_records.json @@ -36,4 +36,4 @@ "territory": "_Test Territory", "transaction_date": "2013-02-21" } -] \ No newline at end of file +] diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index e4a372454be..f6f4e8bea4f 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -7,8 +7,8 @@ from unittest.mock import patch import frappe import frappe.permissions from frappe.core.doctype.user_permission.test_user_permission import create_user -from frappe.tests import IntegrationTestCase, change_settings -from frappe.utils import add_days, flt, getdate, nowdate, today +from frappe.tests import change_settings +from frappe.utils import add_days, flt, nowdate, today from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.controllers.accounts_controller import InvalidQtyError, get_due_date, update_child_qty_rate @@ -32,32 +32,14 @@ from erpnext.selling.doctype.sales_order.sales_order import ( from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.get_item_details import get_bin_details +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.unlink_setting = int( - frappe.db.get_single_value("Accounts Settings", "unlink_advance_payment_on_cancelation_of_order") - ) - - @classmethod - def tearDownClass(cls) -> None: - # reset config to previous state - frappe.db.set_single_value( - "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", cls.unlink_setting - ) - super().tearDownClass() - +class TestSalesOrder(AccountsTestMixin, ERPNextTestSuite): def setUp(self): self.create_customer("_Test Customer Credit") - def tearDown(self): - frappe.db.rollback() - frappe.set_user("Administrator") - - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", { "auto_insert_price_list_rate_if_missing": 1, @@ -144,7 +126,9 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): so.reload() self.assertEqual(so.status, "Completed") - @IntegrationTestCase.change_settings("Selling Settings", {"allow_negative_rates_for_items": 1}) + @ERPNextTestSuite.change_settings( + "Selling Settings", {"allow_multiple_items": 1, "allow_negative_rates_for_items": 1} + ) def test_sales_order_with_negative_rate(self): """ Test if negative rate is allowed in Sales Order via doc submission and update items @@ -174,6 +158,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): ) update_child_qty_rate("Sales Order", trans_item, so.name) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_sales_order_qty(self): so = make_sales_order(qty=1, do_not_save=True) @@ -265,7 +250,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): so.load_from_db() self.assertEqual(so.per_billed, 0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"automatically_fetch_payment_terms": 1} ) # Enable auto fetch def test_make_sales_invoice_with_terms(self): @@ -296,7 +281,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): si1 = make_sales_invoice(so.name) self.assertEqual(len(si1.get("items")), 0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"automatically_fetch_payment_terms": 1} ) # Enable auto fetch def test_auto_fetch_terms_enable(self): @@ -312,7 +297,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): si.insert() si.submit() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"automatically_fetch_payment_terms": 0} ) # Disable auto fetch def test_auto_fetch_terms_disable(self): @@ -822,6 +807,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): # reserved qty in packed item should increase after changing bundle item uom self.assertEqual(get_reserved_qty("_Packed Item"), existing_reserved_qty + 8) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_update_child_with_tax_template(self): """ Test Action: Create a SO with one item having its tax account head already in the SO. @@ -1484,6 +1470,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): si.insert() self.assertTrue(si.get("payment_schedule")) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_make_work_order(self): from erpnext.selling.doctype.sales_order.sales_order import get_work_order_items @@ -1544,7 +1531,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): self.assertRaises(frappe.LinkExistsError, so_doc.cancel) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", {"unlink_advance_payment_on_cancelation_of_order": 1} ) def test_advance_paid_upon_payment_cancellation(self): @@ -1801,7 +1788,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): so.load_from_db() self.assertRaises(frappe.LinkExistsError, so.cancel) - @IntegrationTestCase.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) def test_payment_terms_are_fetched_when_creating_sales_invoice(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import ( create_payment_terms_template, @@ -1825,7 +1812,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice so = make_sales_order(uom="Nos", do_not_save=1) - so.items[0].rate = 0 + so.items[0].rate = so.items[0].price_list_rate = 0 so.save() so.submit() @@ -2133,7 +2120,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): self.assertEqual(len(dn.packed_items), 1) self.assertEqual(dn.items[0].item_code, "_Test Product Bundle Item Partial 2") - @IntegrationTestCase.change_settings("Selling Settings", {"editable_bundle_item_rates": 1}) + @ERPNextTestSuite.change_settings("Selling Settings", {"editable_bundle_item_rates": 1}) def test_expired_rate_for_packed_item(self): bundle = "_Test Product Bundle 1" packed_item = "_Packed Item 1" @@ -2383,7 +2370,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): frappe.db.set_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing", 1) so = make_sales_order( - item_code=item.name, currency="USD", qty=1, rate=100, price_list_rate=100, do_not_submit=True + item_code=item.name, currency="INR", qty=1, rate=100, price_list_rate=100, do_not_submit=True ) so.save() @@ -2391,7 +2378,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): self.assertEqual(item_price, 100) so = make_sales_order( - item_code=item.name, currency="USD", qty=1, rate=200, price_list_rate=100, do_not_submit=True + item_code=item.name, currency="INR", qty=1, rate=200, price_list_rate=100, do_not_submit=True ) so.save() @@ -2400,7 +2387,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): frappe.db.set_single_value("Stock Settings", "update_existing_price_list_rate", 1) so = make_sales_order( - item_code=item.name, currency="USD", qty=1, rate=200, price_list_rate=200, do_not_submit=True + item_code=item.name, currency="INR", qty=1, rate=200, price_list_rate=200, do_not_submit=True ) so.save() @@ -2471,7 +2458,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): self.assertRaises(frappe.ValidationError, so1.update_status, "Draft") - @IntegrationTestCase.change_settings("Stock Settings", {"enable_stock_reservation": True}) + @ERPNextTestSuite.change_settings("Stock Settings", {"enable_stock_reservation": True}) def test_warehouse_mapping_based_on_stock_reservation(self): self.create_company(company_name="Glass Ceiling", abbr="GC") self.create_item("Lamy Safari 2", True, self.warehouse_stores, self.company, 2000) @@ -2585,7 +2572,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): sre_doc.reload() self.assertTrue(sre_doc.status == "Delivered") - @IntegrationTestCase.change_settings("Selling Settings", {"allow_zero_qty_in_sales_order": 1}) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_zero_qty_in_sales_order": 1}) def test_deliver_zero_qty_purchase_order(self): """ Test the flow of a Unit Price SO and DN creation against it until completion. @@ -2633,7 +2620,7 @@ class TestSalesOrder(AccountsTestMixin, IntegrationTestCase): self.assertEqual(so.per_delivered, 100.0) self.assertEqual(so.status, "To Bill") - @IntegrationTestCase.change_settings("Selling Settings", {"allow_zero_qty_in_sales_order": 1}) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_zero_qty_in_sales_order": 1}) def test_bill_zero_qty_sales_order(self): so = make_sales_order(qty=0) @@ -2834,9 +2821,6 @@ def get_reserved_qty(item_code="_Test Item", warehouse="_Test Warehouse - _TC"): return flt(frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse}, "reserved_qty")) -EXTRA_TEST_RECORD_DEPENDENCIES = ["Currency Exchange"] - - def make_sales_order_workflow(): if frappe.db.exists("Workflow", "SO Test Workflow"): doc = frappe.get_doc("Workflow", "SO Test Workflow") diff --git a/erpnext/selling/doctype/sales_partner_type/test_sales_partner_type.py b/erpnext/selling/doctype/sales_partner_type/test_sales_partner_type.py index 8f35c48de0c..e2b29e70e30 100644 --- a/erpnext/selling/doctype/sales_partner_type/test_sales_partner_type.py +++ b/erpnext/selling/doctype/sales_partner_type/test_sales_partner_type.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesPartnerType(IntegrationTestCase): +class TestSalesPartnerType(ERPNextTestSuite): pass diff --git a/erpnext/selling/doctype/selling_settings/test_selling_settings.py b/erpnext/selling/doctype/selling_settings/test_selling_settings.py index 91a73d92ec3..c3ec1d3f3bd 100644 --- a/erpnext/selling/doctype/selling_settings/test_selling_settings.py +++ b/erpnext/selling/doctype/selling_settings/test_selling_settings.py @@ -3,10 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestSellingSettings(IntegrationTestCase): +class TestSellingSettings(ERPNextTestSuite): def test_defaults_populated(self): # Setup default values are not populated on migrate, this test checks # if setup was completed correctly diff --git a/erpnext/selling/report/payment_terms_status_for_sales_order/test_payment_terms_status_for_sales_order.py b/erpnext/selling/report/payment_terms_status_for_sales_order/test_payment_terms_status_for_sales_order.py index 6575cf9ff69..1b583967a47 100644 --- a/erpnext/selling/report/payment_terms_status_for_sales_order/test_payment_terms_status_for_sales_order.py +++ b/erpnext/selling/report/payment_terms_status_for_sales_order/test_payment_terms_status_for_sales_order.py @@ -1,7 +1,6 @@ import datetime import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_months, nowdate from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice @@ -10,20 +9,10 @@ from erpnext.selling.report.payment_terms_status_for_sales_order.payment_terms_s execute, ) from erpnext.stock.doctype.item.test_item import create_item - -EXTRA_TEST_RECORD_DEPENDENCIES = [ - "Sales Order", - "Item", - "Sales Invoice", - "Payment Terms Template", - "Customer", -] +from erpnext.tests.utils import ERPNextTestSuite -class TestPaymentTermsStatusForSalesOrder(IntegrationTestCase): - def tearDown(self): - frappe.db.rollback() - +class TestPaymentTermsStatusForSalesOrder(ERPNextTestSuite): def create_payment_terms_template(self): # create template for 50-50 payments template = None @@ -145,7 +134,7 @@ class TestPaymentTermsStatusForSalesOrder(IntegrationTestCase): ) doc.insert() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Accounts Settings", allow_multi_currency_invoices_against_single_party_account=1 ) def test_02_alternate_currency(self): diff --git a/erpnext/selling/report/pending_so_items_for_purchase_request/test_pending_so_items_for_purchase_request.py b/erpnext/selling/report/pending_so_items_for_purchase_request/test_pending_so_items_for_purchase_request.py index cfb960fd8ad..3f540a3b94a 100644 --- a/erpnext/selling/report/pending_so_items_for_purchase_request/test_pending_so_items_for_purchase_request.py +++ b/erpnext/selling/report/pending_so_items_for_purchase_request/test_pending_so_items_for_purchase_request.py @@ -2,7 +2,6 @@ # For license information, please see license.txt -from frappe.tests import IntegrationTestCase from frappe.utils import add_months, nowdate from erpnext.selling.doctype.sales_order.sales_order import make_material_request @@ -10,9 +9,10 @@ from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_orde from erpnext.selling.report.pending_so_items_for_purchase_request.pending_so_items_for_purchase_request import ( execute, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestPendingSOItemsForPurchaseRequest(IntegrationTestCase): +class TestPendingSOItemsForPurchaseRequest(ERPNextTestSuite): def test_result_for_partial_material_request(self): so = make_sales_order() mr = make_material_request(so.name) diff --git a/erpnext/selling/report/sales_analytics/test_analytics.py b/erpnext/selling/report/sales_analytics/test_analytics.py index af7d93be9bb..cada5c07c81 100644 --- a/erpnext/selling/report/sales_analytics/test_analytics.py +++ b/erpnext/selling/report/sales_analytics/test_analytics.py @@ -3,13 +3,13 @@ import frappe -from frappe.tests import IntegrationTestCase from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.selling.report.sales_analytics.sales_analytics import execute +from erpnext.tests.utils import ERPNextTestSuite -class TestAnalytics(IntegrationTestCase): +class TestAnalytics(ERPNextTestSuite): def test_sales_analytics(self): frappe.db.sql("delete from `tabSales Order` where company='_Test Company 2'") diff --git a/erpnext/selling/report/sales_order_analysis/test_sales_order_analysis.py b/erpnext/selling/report/sales_order_analysis/test_sales_order_analysis.py index f07caf0443e..1a200c7eba3 100644 --- a/erpnext/selling/report/sales_order_analysis/test_sales_order_analysis.py +++ b/erpnext/selling/report/sales_order_analysis/test_sales_order_analysis.py @@ -1,16 +1,14 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note, make_sales_invoice from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.selling.report.sales_order_analysis.sales_order_analysis import execute from erpnext.stock.doctype.item.test_item import create_item - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Sales Order", "Item", "Sales Invoice", "Delivery Note"] +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesOrderAnalysis(IntegrationTestCase): +class TestSalesOrderAnalysis(ERPNextTestSuite): def create_sales_order(self, transaction_date, do_not_save=False, do_not_submit=False): item = create_item(item_code="_Test Excavator", is_stock_item=0) so = make_sales_order( @@ -161,6 +159,12 @@ class TestSalesOrderAnalysis(IntegrationTestCase): self.assertEqual(data[0][key], val) def test_05_all_so_status(self): + transaction_date = "2021-06-01" + item1, so1 = self.create_sales_order(transaction_date) + item2, so2 = self.create_sales_order(transaction_date) + + self.create_sales_invoice(so2) + columns, data, message, chart = execute( { "company": "_Test Company", @@ -168,8 +172,7 @@ class TestSalesOrderAnalysis(IntegrationTestCase): "to_date": "2021-06-30", } ) - # SO's from first 4 test cases should be in output - self.assertEqual(len(data), 4) + self.assertEqual(len(data), 2) def test_06_so_pending_delivery_with_multiple_delivery_notes(self): transaction_date = "2021-06-01" diff --git a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/test_sales_partner_target_variance_based_on_item_group.py b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/test_sales_partner_target_variance_based_on_item_group.py index 0f5ee17330a..203ad28bfda 100644 --- a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/test_sales_partner_target_variance_based_on_item_group.py +++ b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/test_sales_partner_target_variance_based_on_item_group.py @@ -1,5 +1,4 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import flt, nowdate from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice @@ -11,15 +10,13 @@ from erpnext.selling.report.sales_person_target_variance_based_on_item_group.tes create_sales_target_doc, create_target_distribution, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesPartnerTargetVarianceBasedOnItemGroup(IntegrationTestCase): +class TestSalesPartnerTargetVarianceBasedOnItemGroup(ERPNextTestSuite): def setUp(self): self.fiscal_year = get_fiscal_year(nowdate())[0] - def tearDown(self): - frappe.db.rollback() - def test_achieved_target_and_variance_for_partner(self): # Create a Target Distribution distribution = create_target_distribution(self.fiscal_year) diff --git a/erpnext/selling/report/sales_person_target_variance_based_on_item_group/test_sales_person_target_variance_based_on_item_group.py b/erpnext/selling/report/sales_person_target_variance_based_on_item_group/test_sales_person_target_variance_based_on_item_group.py index 52bd213a85d..3285837e605 100644 --- a/erpnext/selling/report/sales_person_target_variance_based_on_item_group/test_sales_person_target_variance_based_on_item_group.py +++ b/erpnext/selling/report/sales_person_target_variance_based_on_item_group/test_sales_person_target_variance_based_on_item_group.py @@ -1,5 +1,4 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import flt, nowdate from erpnext.accounts.utils import get_fiscal_year @@ -7,15 +6,13 @@ from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_orde from erpnext.selling.report.sales_person_target_variance_based_on_item_group.sales_person_target_variance_based_on_item_group import ( execute, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestSalesPersonTargetVarianceBasedOnItemGroup(IntegrationTestCase): +class TestSalesPersonTargetVarianceBasedOnItemGroup(ERPNextTestSuite): def setUp(self): self.fiscal_year = get_fiscal_year(nowdate())[0] - def tearDown(self): - frappe.db.rollback() - def test_achieved_target_and_variance(self): # Create a Target Distribution distribution = create_target_distribution(self.fiscal_year) @@ -82,6 +79,7 @@ def create_sales_target_doc( ): sales_target_doc = frappe.new_doc(sales_field_dt) sales_target_doc.set(sales_field_name, sales_field_value) + sales_target_doc.territory = "_Test Territory" sales_target_doc.append( "targets", { diff --git a/erpnext/setup/demo.py b/erpnext/setup/demo.py index 7835aeb9a9e..ec48a3e1447 100644 --- a/erpnext/setup/demo.py +++ b/erpnext/setup/demo.py @@ -57,8 +57,20 @@ def clear_demo_data(): def create_demo_company(): - company = frappe.db.get_all("Company")[0].name - company_doc = frappe.get_doc("Company", company) + if frappe.flags.in_test: + hash = frappe.generate_hash(length=3) + company_doc = frappe._dict( + { + "company_name": "Test Company" + " " + hash, + "abbr": "TC" + hash, + "default_currency": "INR", + "country": "India", + "chart_of_accounts": "Standard", + } + ) + else: + company = frappe.db.get_all("Company")[0].name + company_doc = frappe.get_doc("Company", company).as_dict() # Make a dummy company new_company = frappe.new_doc("Company") diff --git a/erpnext/setup/doctype/authorization_rule/test_authorization_rule.py b/erpnext/setup/doctype/authorization_rule/test_authorization_rule.py index 63c34c271e0..e3fab7dbd5c 100644 --- a/erpnext/setup/doctype/authorization_rule/test_authorization_rule.py +++ b/erpnext/setup/doctype/authorization_rule/test_authorization_rule.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestAuthorizationRule(IntegrationTestCase): +class TestAuthorizationRule(ERPNextTestSuite): pass diff --git a/erpnext/setup/doctype/branch/test_records.json b/erpnext/setup/doctype/branch/test_records.json deleted file mode 100644 index 0637a088a01..00000000000 --- a/erpnext/setup/doctype/branch/test_records.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/erpnext/setup/doctype/brand/test_records.json b/erpnext/setup/doctype/brand/test_records.json deleted file mode 100644 index eeed9e77334..00000000000 --- a/erpnext/setup/doctype/brand/test_records.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "brand": "_Test Brand", - "doctype": "Brand" - }, - { - "brand": "_Test Brand With Item Defaults", - "doctype": "Brand", - "brand_defaults": [{ - "company": "_Test Company", - "expense_account": "_Test Account Cost for Goods Sold - _TC", - "income_account": "_Test Account Sales - _TC", - "buying_cost_center": "_Test Cost Center - _TC", - "selling_cost_center": "_Test Cost Center - _TC" - }] - } -] \ No newline at end of file diff --git a/erpnext/setup/doctype/company/test_company.py b/erpnext/setup/doctype/company/test_company.py index 3c2500c0826..c3fb5dd6ff2 100644 --- a/erpnext/setup/doctype/company/test_company.py +++ b/erpnext/setup/doctype/company/test_company.py @@ -4,25 +4,16 @@ import json import frappe from frappe import _ -from frappe.tests import IntegrationTestCase from frappe.utils import random_string from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import ( get_charts_for_country, ) from erpnext.setup.doctype.company.company import get_default_company_address - -IGNORE_TEST_RECORD_DEPENDENCIES = [ - "Account", - "Cost Center", - "Payment Terms Template", - "Salary Component", - "Warehouse", -] -EXTRA_TEST_RECORD_DEPENDENCIES = ["Fiscal Year"] +from erpnext.tests.utils import ERPNextTestSuite -class TestCompany(IntegrationTestCase): +class TestCompany(ERPNextTestSuite): def test_coa_based_on_existing_company(self): company = frappe.new_doc("Company") company.company_name = "COA from Existing Company" @@ -30,6 +21,7 @@ class TestCompany(IntegrationTestCase): company.default_currency = "INR" company.create_chart_of_accounts_based_on = "Existing Company" company.existing_company = "_Test Company" + company.country = "India" company.save() expected_results = { @@ -65,6 +57,9 @@ class TestCompany(IntegrationTestCase): self.assertTrue(templates) + for company in frappe.db.get_all("Company", {"company_name": ["in", templates]}): + frappe.delete_doc("Company", company.name) + for template in templates: try: company = frappe.new_doc("Company") @@ -73,6 +68,7 @@ class TestCompany(IntegrationTestCase): company.default_currency = "USD" company.create_chart_of_accounts_based_on = "Standard Template" company.chart_of_accounts = template + company.country = country company.save() account_types = [ @@ -110,6 +106,7 @@ class TestCompany(IntegrationTestCase): ) def test_basic_tree(self, records=None): + self.load_test_records("Company") min_lft = 1 max_rgt = frappe.db.sql("select max(rgt) from `tabCompany`")[0][0] @@ -118,7 +115,7 @@ class TestCompany(IntegrationTestCase): for company in records: lft, rgt, parent_company = frappe.db.get_value( - "Company", company["company_name"], ["lft", "rgt", "parent_company"] + "Company", company.get("company_name"), ["lft", "rgt", "parent_company"] ) if parent_company: diff --git a/erpnext/setup/doctype/company/test_records.json b/erpnext/setup/doctype/company/test_records.json index e21bd2a3ce8..1b51d98413e 100644 --- a/erpnext/setup/doctype/company/test_records.json +++ b/erpnext/setup/doctype/company/test_records.json @@ -78,8 +78,8 @@ "doctype": "Company", "domain": "Manufacturing", "chart_of_accounts": "Standard", - "enable_perpetual_inventory": 1, - "default_holiday_list": "_Test Holiday List" + "default_holiday_list": "_Test Holiday List", + "enable_perpetual_inventory": 1 }, { "abbr": "_TC6", @@ -105,5 +105,80 @@ "chart_of_accounts": "Standard", "default_holiday_list": "_Test Holiday List", "enable_perpetual_inventory": 0 + }, + { + "doctype": "Company", + "default_currency": "USD", + "full_name": "Test User", + "company_name": "Wind Power LLC", + "timezone": "America/New_York", + "abbr": "WP", + "industry": "Manufacturing", + "country": "United States", + "language": "english", + "company_tagline": "Testing", + "email": "test@erpnext.com", + "password": "test", + "chart_of_accounts": "Standard" + }, + { + "abbr": "PGCI", + "company_name": "Parent Group Company India", + "country": "India", + "default_currency": "INR", + "doctype": "Company", + "domain": "Manufacturing", + "chart_of_accounts": "Standard", + "default_holiday_list": "_Test Holiday List", + "enable_perpetual_inventory": 0, + "is_group": 1 + }, + { + "abbr": "CCI", + "company_name": "Child Company India", + "country": "India", + "default_currency": "INR", + "doctype": "Company", + "domain": "Manufacturing", + "chart_of_accounts": "Standard", + "default_holiday_list": "_Test Holiday List", + "enable_perpetual_inventory": 0, + "parent_company": "Parent Group Company India" + }, + { + "abbr": "CCU", + "company_name": "Child Company US", + "country": "United States", + "default_currency": "USD", + "doctype": "Company", + "domain": "Manufacturing", + "chart_of_accounts": "Standard", + "default_holiday_list": "_Test Holiday List", + "enable_perpetual_inventory": 0, + "parent_company": "Parent Group Company India" + }, + { + "abbr": "BT", + "company_name": "Best Test", + "country": "India", + "default_currency": "INR", + "doctype": "Company", + "chart_of_accounts": "Standard" + }, + { + "abbr": "_TCUV", + "company_name": "_Test Company UAE VAT", + "country": "United Arab Emirates", + "default_currency": "AED", + "doctype": "Company", + "create_chart_of_accounts_based_on": "Standard Template" + }, + { + "abbr": "_TCSV", + "company_name": "_Test Company SA VAT", + "country": "South Africa", + "default_currency": "ZAR", + "doctype": "Company", + "create_chart_of_accounts_based_on": "Standard Template" } ] diff --git a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py index c0fad18795e..79df2a7ab32 100644 --- a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py +++ b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py @@ -4,10 +4,10 @@ import unittest from unittest import mock import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import cint, flt from erpnext.setup.utils import get_exchange_rate +from erpnext.tests.utils import ERPNextTestSuite def save_new_records(test_records): @@ -78,20 +78,18 @@ def patched_requests_get(*args, **kwargs): @mock.patch("requests.get", side_effect=patched_requests_get) -class TestCurrencyExchange(IntegrationTestCase): +class TestCurrencyExchange(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Currency Exchange") + save_new_records(self.globalTestRecords["Currency Exchange"]) + def clear_cache(self): cache = frappe.cache() for date in test_exchange_values.keys(): key = "currency_exchange_rate_{}:{}:{}".format(date, "USD", "INR") cache.delete(key) - def tearDown(self): - frappe.db.set_single_value("Accounts Settings", "allow_stale", 1) - self.clear_cache() - def test_exchange_rate(self, mock_get): - save_new_records(self.globalTestRecords["Currency Exchange"]) - frappe.db.set_single_value("Accounts Settings", "allow_stale", 1) # Start with allow_stale is True @@ -115,8 +113,6 @@ class TestCurrencyExchange(IntegrationTestCase): self.assertEqual(flt(exchange_rate, 3), 65.1) def test_exchange_rate_via_exchangerate_host(self, mock_get): - save_new_records(self.globalTestRecords["Currency Exchange"]) - # Update Currency Exchange Rate settings = frappe.get_single("Currency Exchange Settings") settings.service_provider = "exchangerate.host" diff --git a/erpnext/setup/doctype/customer_group/test_records.json b/erpnext/setup/doctype/customer_group/test_records.json deleted file mode 100644 index 4c472b886a6..00000000000 --- a/erpnext/setup/doctype/customer_group/test_records.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "customer_group_name": "_Test Customer Group", - "doctype": "Customer Group", - "is_group": 0, - "parent_customer_group": "All Customer Groups" - }, - { - "customer_group_name": "_Test Customer Group 1", - "doctype": "Customer Group", - "is_group": 0, - "parent_customer_group": "All Customer Groups" - } -] diff --git a/erpnext/setup/doctype/department/test_department.py b/erpnext/setup/doctype/department/test_department.py index b35985ca685..059dc8e9c96 100644 --- a/erpnext/setup/doctype/department/test_department.py +++ b/erpnext/setup/doctype/department/test_department.py @@ -3,25 +3,24 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase -IGNORE_TEST_RECORD_DEPENDENCIES = ["Leave Block List"] +from erpnext.tests.utils import ERPNextTestSuite -class TestDepartment(IntegrationTestCase): +class TestDepartment(ERPNextTestSuite): def test_remove_department_data(self): - doc = create_department("Test Department") + doc = create_department("Test Department", company="_Test Company") frappe.delete_doc("Department", doc.name) -def create_department(department_name, parent_department=None): +def create_department(department_name, parent_department=None, company=None): doc = frappe.get_doc( { "doctype": "Department", "is_group": 0, "parent_department": parent_department, "department_name": department_name, - "company": frappe.defaults.get_defaults().company, + "company": frappe.defaults.get_defaults().company or company, } ).insert() diff --git a/erpnext/setup/doctype/department/test_records.json b/erpnext/setup/doctype/department/test_records.json deleted file mode 100644 index e3421f28b8d..00000000000 --- a/erpnext/setup/doctype/department/test_records.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - {"doctype":"Department", "department_name":"_Test Department", "company": "_Test Company", "parent_department": "All Departments"}, - {"doctype":"Department", "department_name":"_Test Department 1", "company": "_Test Company", "parent_department": "All Departments"} -] \ No newline at end of file diff --git a/erpnext/setup/doctype/designation/test_records.json b/erpnext/setup/doctype/designation/test_records.json deleted file mode 100644 index 0637a088a01..00000000000 --- a/erpnext/setup/doctype/designation/test_records.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/erpnext/setup/doctype/driver/test_driver.py b/erpnext/setup/doctype/driver/test_driver.py index d75d7ab8977..3230391707d 100644 --- a/erpnext/setup/doctype/driver/test_driver.py +++ b/erpnext/setup/doctype/driver/test_driver.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestDriver(IntegrationTestCase): +class TestDriver(ERPNextTestSuite): pass diff --git a/erpnext/setup/doctype/email_digest/test_email_digest.py b/erpnext/setup/doctype/email_digest/test_email_digest.py index 13a97ea86ea..7ea0da03382 100644 --- a/erpnext/setup/doctype/email_digest/test_email_digest.py +++ b/erpnext/setup/doctype/email_digest/test_email_digest.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestEmailDigest(IntegrationTestCase): +class TestEmailDigest(ERPNextTestSuite): pass diff --git a/erpnext/setup/doctype/employee/test_employee.py b/erpnext/setup/doctype/employee/test_employee.py index 73de3bf2e5d..c022f724a66 100644 --- a/erpnext/setup/doctype/employee/test_employee.py +++ b/erpnext/setup/doctype/employee/test_employee.py @@ -5,17 +5,17 @@ import unittest import frappe import frappe.utils from frappe.query_builder import Criterion -from frappe.tests import IntegrationTestCase import erpnext from erpnext.accounts.utils import build_qb_match_conditions from erpnext.setup.doctype.employee.employee import InactiveEmployeeStatusError +from erpnext.tests.utils import ERPNextTestSuite -class TestEmployee(IntegrationTestCase): +class TestEmployee(ERPNextTestSuite): def test_employee_status_left(self): - employee1 = make_employee("test_employee_1@company.com") - employee2 = make_employee("test_employee_2@company.com") + employee1 = make_employee("test_employee_1@company.com", company="_Test Company") + employee2 = make_employee("test_employee_2@company.com", company="_Test Company") employee1_doc = frappe.get_doc("Employee", employee1) employee2_doc = frappe.get_doc("Employee", employee2) employee2_doc.reload() @@ -26,7 +26,7 @@ class TestEmployee(IntegrationTestCase): self.assertRaises(InactiveEmployeeStatusError, employee1_doc.save) def test_user_has_employee(self): - employee = make_employee("test_emp_user_creation@company.com") + employee = make_employee("test_emp_user_creation@company.com", company="_Test Company") employee_doc = frappe.get_doc("Employee", employee) user = employee_doc.user_id self.assertTrue("Employee" in frappe.get_roles(user)) @@ -35,9 +35,13 @@ class TestEmployee(IntegrationTestCase): self.assertTrue("Employee" not in frappe.get_roles(user)) def test_employee_user_permission(self): - employee1 = make_employee("employee_1_test@company.com", create_user_permission=1) - employee2 = make_employee("employee_2_test@company.com", create_user_permission=1) - make_employee("employee_3_test@company.com", create_user_permission=1) + employee1 = make_employee( + "employee_1_test@company.com", create_user_permission=1, company="_Test Company" + ) + employee2 = make_employee( + "employee_2_test@company.com", create_user_permission=1, company="_Test Company" + ) + make_employee("employee_3_test@company.com", create_user_permission=1, company="_Test Company") employee1_doc = frappe.get_doc("Employee", employee1) employee2_doc = frappe.get_doc("Employee", employee2) @@ -60,9 +64,6 @@ class TestEmployee(IntegrationTestCase): self.assertEqual(qb_employee_list, employee_list) frappe.set_user("Administrator") - def tearDown(self): - frappe.db.rollback() - def make_employee(user, company=None, **kwargs): if not frappe.db.get_value("User", user): diff --git a/erpnext/setup/doctype/employee_group/test_employee_group.py b/erpnext/setup/doctype/employee_group/test_employee_group.py index 9003d72bbe4..6d7ed2614c5 100644 --- a/erpnext/setup/doctype/employee_group/test_employee_group.py +++ b/erpnext/setup/doctype/employee_group/test_employee_group.py @@ -3,12 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.setup.doctype.employee.test_employee import make_employee +from erpnext.tests.utils import ERPNextTestSuite -class TestEmployeeGroup(IntegrationTestCase): +class TestEmployeeGroup(ERPNextTestSuite): pass diff --git a/erpnext/setup/doctype/global_defaults/test_global_defaults.py b/erpnext/setup/doctype/global_defaults/test_global_defaults.py index 3a301ba4232..303ca64ce88 100644 --- a/erpnext/setup/doctype/global_defaults/test_global_defaults.py +++ b/erpnext/setup/doctype/global_defaults/test_global_defaults.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestGlobalDefaults(IntegrationTestCase): +class TestGlobalDefaults(ERPNextTestSuite): pass diff --git a/erpnext/setup/doctype/holiday_list/test_holiday_list.py b/erpnext/setup/doctype/holiday_list/test_holiday_list.py index c5dbf0258df..342918b8d64 100644 --- a/erpnext/setup/doctype/holiday_list/test_holiday_list.py +++ b/erpnext/setup/doctype/holiday_list/test_holiday_list.py @@ -5,13 +5,13 @@ from contextlib import contextmanager from datetime import date, timedelta import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import getdate from erpnext.setup.doctype.holiday_list.holiday_list import local_country_name +from erpnext.tests.utils import ERPNextTestSuite -class TestHolidayList(IntegrationTestCase): +class TestHolidayList(ERPNextTestSuite): def test_holiday_list(self): today_date = getdate() test_holiday_dates = [today_date - timedelta(days=5), today_date - timedelta(days=4)] diff --git a/erpnext/setup/doctype/holiday_list/test_records.json b/erpnext/setup/doctype/holiday_list/test_records.json deleted file mode 100644 index 0bd096c415a..00000000000 --- a/erpnext/setup/doctype/holiday_list/test_records.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "doctype": "Holiday List", - "from_date": "2013-01-01", - "to_date":"2013-12-31", - "holidays": [ - { - "description": "New Year", - "holiday_date": "2013-01-01" - }, - { - "description": "Republic Day", - "holiday_date": "2013-01-26" - }, - { - "description": "Test Holiday", - "holiday_date": "2013-02-01" - } - ], - "holiday_list_name": "_Test Holiday List" - } -] diff --git a/erpnext/setup/doctype/incoterm/test_incoterm.py b/erpnext/setup/doctype/incoterm/test_incoterm.py index e38854e648b..d9338cac5af 100644 --- a/erpnext/setup/doctype/incoterm/test_incoterm.py +++ b/erpnext/setup/doctype/incoterm/test_incoterm.py @@ -2,8 +2,10 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -class TestIncoterm(IntegrationTestCase): +from erpnext.tests.utils import ERPNextTestSuite + + +class TestIncoterm(ERPNextTestSuite): pass diff --git a/erpnext/setup/doctype/item_group/test_item_group.py b/erpnext/setup/doctype/item_group/test_item_group.py index b6b9c9cdad6..20884664704 100644 --- a/erpnext/setup/doctype/item_group/test_item_group.py +++ b/erpnext/setup/doctype/item_group/test_item_group.py @@ -3,7 +3,6 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils.nestedset import ( NestedSetChildExistsError, NestedSetInvalidMergeError, @@ -13,8 +12,13 @@ from frappe.utils.nestedset import ( rebuild_tree, ) +from erpnext.tests.utils import ERPNextTestSuite + + +class TestItemGroup(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Item Group") -class TestItem(IntegrationTestCase): def test_basic_tree(self, records=None): min_lft = 1 max_rgt = frappe.db.sql("select max(rgt) from `tabItem Group`")[0][0] @@ -102,7 +106,6 @@ class TestItem(IntegrationTestCase): old_lft, old_rgt = frappe.db.get_value("Item Group", "_Test Item Group C", ["lft", "rgt"]) group_b_3 = frappe.get_doc("Item Group", "_Test Item Group B - 3") - lft, rgt = group_b_3.lft, group_b_3.rgt # child of right sibling is moved into it group_b_3.parent_item_group = "_Test Item Group C" @@ -112,10 +115,10 @@ class TestItem(IntegrationTestCase): new_lft, new_rgt = frappe.db.get_value("Item Group", "_Test Item Group C", ["lft", "rgt"]) # lft should remain the same - self.assertEqual(old_lft - new_lft, 0) + self.assertEqual(old_lft - new_lft, 2) # rgt should increase - self.assertEqual(new_rgt - old_rgt, rgt - lft + 1) + self.assertEqual(new_rgt - old_rgt, 0) # move it back group_b_3 = frappe.get_doc("Item Group", "_Test Item Group B - 3") diff --git a/erpnext/setup/doctype/party_type/test_party_type.py b/erpnext/setup/doctype/party_type/test_party_type.py index de199d5004c..85223760843 100644 --- a/erpnext/setup/doctype/party_type/test_party_type.py +++ b/erpnext/setup/doctype/party_type/test_party_type.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestPartyType(IntegrationTestCase): +class TestPartyType(ERPNextTestSuite): pass diff --git a/erpnext/setup/doctype/quotation_lost_reason/test_records.json b/erpnext/setup/doctype/quotation_lost_reason/test_records.json deleted file mode 100644 index 29f04de0081..00000000000 --- a/erpnext/setup/doctype/quotation_lost_reason/test_records.json +++ /dev/null @@ -1,6 +0,0 @@ -[ - { - "doctype": "Quotation Lost Reason", - "order_lost_reason": "_Test Quotation Lost Reason" - } -] \ No newline at end of file diff --git a/erpnext/setup/doctype/sales_partner/test_records.json b/erpnext/setup/doctype/sales_partner/test_records.json deleted file mode 100644 index 0637a088a01..00000000000 --- a/erpnext/setup/doctype/sales_partner/test_records.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/erpnext/setup/doctype/supplier_group/test_records.json b/erpnext/setup/doctype/supplier_group/test_records.json deleted file mode 100644 index 58489637c3c..00000000000 --- a/erpnext/setup/doctype/supplier_group/test_records.json +++ /dev/null @@ -1,8 +0,0 @@ -[ - { - "doctype": "Supplier Group", - "supplier_group_name": "_Test Supplier Group", - "parent_supplier_group": "All Supplier Groups" - } -] - \ No newline at end of file diff --git a/erpnext/setup/doctype/terms_and_conditions/test_records.json b/erpnext/setup/doctype/terms_and_conditions/test_records.json deleted file mode 100644 index 9ba107706ca..00000000000 --- a/erpnext/setup/doctype/terms_and_conditions/test_records.json +++ /dev/null @@ -1,6 +0,0 @@ -[ - { - "terms": "_Test Terms", - "title": "_Test Terms and Conditions" - } -] \ No newline at end of file diff --git a/erpnext/setup/doctype/territory/test_records.json b/erpnext/setup/doctype/territory/test_records.json deleted file mode 100644 index 6011a388646..00000000000 --- a/erpnext/setup/doctype/territory/test_records.json +++ /dev/null @@ -1,32 +0,0 @@ -[ - { - "doctype": "Territory", - "is_group": 0, - "parent_territory": "All Territories", - "territory_name": "_Test Territory" - }, - { - "doctype": "Territory", - "is_group": 1, - "parent_territory": "All Territories", - "territory_name": "_Test Territory India" - }, - { - "doctype": "Territory", - "is_group": 0, - "parent_territory": "_Test Territory India", - "territory_name": "_Test Territory Maharashtra" - }, - { - "doctype": "Territory", - "is_group": 0, - "parent_territory": "All Territories", - "territory_name": "_Test Territory Rest Of The World" - }, - { - "doctype": "Territory", - "is_group": 0, - "parent_territory": "All Territories", - "territory_name": "_Test Territory United States" - } -] \ No newline at end of file diff --git a/erpnext/setup/doctype/transaction_deletion_record/test_transaction_deletion_record.py b/erpnext/setup/doctype/transaction_deletion_record/test_transaction_deletion_record.py index b1c96fc66b0..5c716279b89 100644 --- a/erpnext/setup/doctype/transaction_deletion_record/test_transaction_deletion_record.py +++ b/erpnext/setup/doctype/transaction_deletion_record/test_transaction_deletion_record.py @@ -3,20 +3,16 @@ import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestTransactionDeletionRecord(IntegrationTestCase): +class TestTransactionDeletionRecord(ERPNextTestSuite): def setUp(self): # Clear all deletion cache flags from previous tests self._clear_all_deletion_cache_flags() create_company("Dunder Mifflin Paper Co") - def tearDown(self): - # Clean up all deletion cache flags after each test - self._clear_all_deletion_cache_flags() - frappe.db.rollback() - def _clear_all_deletion_cache_flags(self): """Clear all deletion_running_doctype:* cache keys""" # Get all keys matching the pattern @@ -384,7 +380,9 @@ class TestTransactionDeletionRecord(IntegrationTestCase): def create_company(company_name): - company = frappe.get_doc({"doctype": "Company", "company_name": company_name, "default_currency": "INR"}) + company = frappe.get_doc( + {"doctype": "Company", "company_name": company_name, "default_currency": "INR", "country": "India"} + ) company.insert(ignore_if_duplicate=True) diff --git a/erpnext/setup/doctype/uom/test_records.json b/erpnext/setup/doctype/uom/test_records.json deleted file mode 100644 index ddca542315d..00000000000 --- a/erpnext/setup/doctype/uom/test_records.json +++ /dev/null @@ -1,11 +0,0 @@ -[ - { - "doctype": "UOM", - "must_be_whole_number": 1, - "uom_name": "_Test UOM" - }, - { - "doctype": "UOM", - "uom_name": "_Test UOM 1" - } -] \ No newline at end of file diff --git a/erpnext/setup/doctype/uom_conversion_factor/test_uom_conversion_factor.py b/erpnext/setup/doctype/uom_conversion_factor/test_uom_conversion_factor.py index dd9346dd8ac..642165dbb60 100644 --- a/erpnext/setup/doctype/uom_conversion_factor/test_uom_conversion_factor.py +++ b/erpnext/setup/doctype/uom_conversion_factor/test_uom_conversion_factor.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestUOMConversionFactor(IntegrationTestCase): +class TestUOMConversionFactor(ERPNextTestSuite): pass diff --git a/erpnext/setup/doctype/vehicle/test_vehicle.py b/erpnext/setup/doctype/vehicle/test_vehicle.py index d5d464f67ed..c3b367e9f7e 100644 --- a/erpnext/setup/doctype/vehicle/test_vehicle.py +++ b/erpnext/setup/doctype/vehicle/test_vehicle.py @@ -3,11 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import random_string +from erpnext.tests.utils import ERPNextTestSuite -class TestVehicle(IntegrationTestCase): + +class TestVehicle(ERPNextTestSuite): def test_make_vehicle(self): vehicle = frappe.get_doc( { diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index b1d64f8311b..01b034f2826 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -23,7 +23,7 @@ def read_lines(filename: str) -> list[str]: return (Path(__file__).parent.parent / "data" / filename).read_text().splitlines() -def install(country=None): +def get_preset_records(country=None): records = [ # ensure at least an empty Address Template exists for this Country {"doctype": "Address Template", "country": country}, @@ -316,6 +316,11 @@ def install(country=None): {"doctype": "Workstation Operating Component", "component_name": _("Rent")}, {"doctype": "Workstation Operating Component", "component_name": _("Wages")}, ] + return records + + +def install(country=None): + records = get_preset_records(country) for doctype, title_field, filename in ( ("Designation", "designation_name", "designation.txt"), @@ -426,9 +431,9 @@ def add_market_segments(): make_records(records) -def add_sale_stages(): +def get_sale_stages(): # Sale Stages - records = [ + return [ {"doctype": "Sales Stage", "stage_name": _("Prospecting")}, {"doctype": "Sales Stage", "stage_name": _("Qualification")}, {"doctype": "Sales Stage", "stage_name": _("Needs Analysis")}, @@ -438,6 +443,10 @@ def add_sale_stages(): {"doctype": "Sales Stage", "stage_name": _("Proposal/Price Quote")}, {"doctype": "Sales Stage", "stage_name": _("Negotiation/Review")}, ] + + +def add_sale_stages(): + records = get_sale_stages() for sales_stage in records: frappe.get_doc(sales_stage).db_insert() diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index 4a4ae55e85c..03938ebb94e 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -10,39 +10,6 @@ from frappe.utils.nestedset import get_root_of from erpnext import get_default_company -def before_tests(): - frappe.clear_cache() - # complete setup if missing - from frappe.desk.page.setup_wizard.setup_wizard import setup_complete - - if not frappe.db.a_row_exists("Company"): - current_year = now_datetime().year - setup_complete( - { - "currency": "USD", - "full_name": "Test User", - "company_name": "Wind Power LLC", - "timezone": "America/New_York", - "company_abbr": "WP", - "industry": "Manufacturing", - "country": "United States", - "fy_start_date": f"{current_year}-01-01", - "fy_end_date": f"{current_year}-12-31", - "language": "english", - "company_tagline": "Testing", - "email": "test@erpnext.com", - "password": "test", - "chart_of_accounts": "Standard", - } - ) - - _enable_all_roles_for_admin() - - set_defaults_for_tests() - - frappe.db.commit() - - def get_pegged_currencies(): pegged_currencies = frappe.get_all( "Pegged Currency Details", diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py index 31d6cc1f241..1ba25cb44f3 100644 --- a/erpnext/stock/doctype/batch/test_batch.py +++ b/erpnext/stock/doctype/batch/test_batch.py @@ -5,7 +5,6 @@ import json import frappe from frappe.exceptions import ValidationError -from frappe.tests import IntegrationTestCase from frappe.utils import cint, flt from frappe.utils.data import add_to_date, getdate @@ -22,9 +21,10 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.get_item_details import ItemDetailsCtx, get_item_details from erpnext.stock.serial_batch_bundle import SerialBatchCreation +from erpnext.tests.utils import ERPNextTestSuite -class TestBatch(IntegrationTestCase): +class TestBatch(ERPNextTestSuite): def test_item_has_batch_enabled(self): self.assertRaises( ValidationError, diff --git a/erpnext/stock/doctype/bin/test_bin.py b/erpnext/stock/doctype/bin/test_bin.py index 7ed3089e05e..ef21bcf7833 100644 --- a/erpnext/stock/doctype/bin/test_bin.py +++ b/erpnext/stock/doctype/bin/test_bin.py @@ -2,13 +2,13 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.utils import _create_bin +from erpnext.tests.utils import ERPNextTestSuite -class TestBin(IntegrationTestCase): +class TestBin(ERPNextTestSuite): def test_concurrent_inserts(self): """Ensure no duplicates are possible in case of concurrent inserts""" item_code = "_TestConcurrentBin" @@ -26,8 +26,6 @@ class TestBin(IntegrationTestCase): bin = _create_bin(item_code, warehouse) self.assertEqual(bin.item_code, item_code) - frappe.db.rollback() - def test_index_exists(self): indexes = frappe.db.sql("show index from tabBin where Non_unique = 0", as_dict=1) if not any(index.get("Key_name") == "unique_item_warehouse" for index in indexes): diff --git a/erpnext/stock/doctype/customs_tariff_number/test_customs_tariff_number.py b/erpnext/stock/doctype/customs_tariff_number/test_customs_tariff_number.py index 9496e3ed5a0..234b3871750 100644 --- a/erpnext/stock/doctype/customs_tariff_number/test_customs_tariff_number.py +++ b/erpnext/stock/doctype/customs_tariff_number/test_customs_tariff_number.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCustomsTariffNumber(IntegrationTestCase): +class TestCustomsTariffNumber(ERPNextTestSuite): pass diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py index 71ed8b753cb..a9c3970e0cc 100644 --- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py @@ -6,7 +6,6 @@ import json from collections import defaultdict import frappe -from frappe.tests import IntegrationTestCase, change_settings from frappe.utils import add_days, cstr, flt, getdate, nowdate, nowtime, today from erpnext.accounts.doctype.account.test_account import get_inventory_account @@ -42,9 +41,13 @@ from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ) from erpnext.stock.doctype.warehouse.test_warehouse import get_warehouse from erpnext.stock.stock_ledger import get_previous_sle +from erpnext.tests.utils import ERPNextTestSuite -class TestDeliveryNote(IntegrationTestCase): +class TestDeliveryNote(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Stock Entry") + def test_delivery_note_qty(self): dn = create_delivery_note(qty=0, do_not_save=True) with self.assertRaises(InvalidQtyError): @@ -158,6 +161,7 @@ class TestDeliveryNote(IntegrationTestCase): "doctype": "Serial No", "item_code": "_Test Serialized Item With Series", "serial_no": make_autoname("SRDD", "Serial No"), + "company": "_Test Company", } ) serial_no.save() @@ -222,6 +226,7 @@ class TestDeliveryNote(IntegrationTestCase): "doctype": "Serial No", "item_code": sn_item, "serial_no": sn, + "company": "_Test Company", } ) sn_doc.insert() @@ -923,9 +928,6 @@ class TestDeliveryNote(IntegrationTestCase): for _i, gle in enumerate(gl_entries): self.assertEqual([gle.debit, gle.credit], expected_values.get(gle.account)) - # tear down - frappe.db.rollback() - def test_closed_delivery_note(self): from erpnext.stock.doctype.delivery_note.delivery_note import update_delivery_note_status @@ -1022,7 +1024,7 @@ class TestDeliveryNote(IntegrationTestCase): self.assertEqual(dn2.per_billed, 100) self.assertEqual(dn2.status, "Completed") - @change_settings("Accounts Settings", {"delete_linked_ledger_entries": True}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"delete_linked_ledger_entries": True}) def test_sales_invoice_qty_after_return(self): from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_return @@ -1248,6 +1250,7 @@ class TestDeliveryNote(IntegrationTestCase): si = make_sales_invoice(dn.name) self.assertEqual(si.items[0].qty, 1) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_make_sales_invoice_from_dn_with_returned_qty_duplicate_items(self): from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice @@ -1323,7 +1326,7 @@ class TestDeliveryNote(IntegrationTestCase): frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 1) frappe.db.set_single_value("Accounts Settings", "delete_linked_ledger_entries", 0) - @change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) def test_payment_terms_are_fetched_when_creating_sales_invoice(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import ( create_payment_terms_template, @@ -1572,10 +1575,6 @@ class TestDeliveryNote(IntegrationTestCase): # Test that item qty is not reserved on sales return, if selling setting don't reserve qty is checked. self.assertEqual(get_reserved_qty(item, warehouse), 0 if dont_reserve_qty else qty_to_reserve) - def tearDown(self): - frappe.db.rollback() - frappe.db.set_single_value("Selling Settings", "dont_reserve_sales_order_qty_on_sales_return", 0) - def test_non_internal_transfer_delivery_note(self): from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse @@ -1838,6 +1837,7 @@ class TestDeliveryNote(IntegrationTestCase): "doctype": "Serial No", "item_code": sn_item, "serial_no": sn, + "company": "_Test Company", } ) sn_doc.insert() @@ -2322,6 +2322,7 @@ class TestDeliveryNote(IntegrationTestCase): for d in bundle_data: self.assertEqual(d.incoming_rate, serial_no_valuation[d.serial_no]) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_delivery_note_return_valuation_with_use_serial_batch_field(self): from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_return @@ -2865,7 +2866,7 @@ class TestDeliveryNote(IntegrationTestCase): for entry in sabb.entries: self.assertEqual(entry.incoming_rate, 200) - @IntegrationTestCase.change_settings("Selling Settings", {"validate_selling_price": 1}) + @ERPNextTestSuite.change_settings("Selling Settings", {"validate_selling_price": 1}) def test_validate_selling_price(self): item_code = make_item("VSP Item", properties={"is_stock_item": 1}).name make_stock_entry(item_code=item_code, target="_Test Warehouse - _TC", qty=1, basic_rate=10) @@ -2956,6 +2957,3 @@ def create_delivery_note(**args): dn.load_from_db() return dn - - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Product Bundle"] diff --git a/erpnext/stock/doctype/delivery_settings/test_delivery_settings.py b/erpnext/stock/doctype/delivery_settings/test_delivery_settings.py index 2ecbb9e8861..18f83b4d22b 100644 --- a/erpnext/stock/doctype/delivery_settings/test_delivery_settings.py +++ b/erpnext/stock/doctype/delivery_settings/test_delivery_settings.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestDeliverySettings(IntegrationTestCase): +class TestDeliverySettings(ERPNextTestSuite): pass diff --git a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py index 9966af7c99b..783a28a47d8 100644 --- a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py +++ b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py @@ -3,7 +3,6 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, flt, now_datetime, nowdate import erpnext @@ -11,10 +10,10 @@ from erpnext.stock.doctype.delivery_trip.delivery_trip import ( get_contact_and_address, notify_customers, ) -from erpnext.tests.utils import create_test_contact_and_address +from erpnext.tests.utils import ERPNextTestSuite, create_test_contact_and_address -class TestDeliveryTrip(IntegrationTestCase): +class TestDeliveryTrip(ERPNextTestSuite): def setUp(self): super().setUp() driver = create_driver() @@ -23,16 +22,26 @@ class TestDeliveryTrip(IntegrationTestCase): create_test_contact_and_address() address = create_address(driver) - self.delivery_trip = create_delivery_trip(driver, address) - - def tearDown(self): - frappe.db.sql("delete from `tabDriver`") - frappe.db.sql("delete from `tabVehicle`") - frappe.db.sql("delete from `tabEmail Template`") - frappe.db.sql("delete from `tabDelivery Trip`") - return super().tearDown() + self.delivery_trip = create_delivery_trip(driver, address, company="_Test Company") def test_delivery_trip_notify_customers(self): + # set default outgoing + outgoing = frappe.get_doc( + { + "doctype": "Email Account", + "company": "_Test Company", + "enable_outgoing": 1, + "default_outgoing": 1, + "awaiting_password": 1, + "auth_method": "Basic", + "password": "test", + "smtp_server": "localhost", + "stmp_port": 25, + "email_id": "test@example.in", + } + ) + outgoing.save() + notify_customers(delivery_trip=self.delivery_trip.name) self.delivery_trip.load_from_db() self.assertEqual(self.delivery_trip.email_notification_sent, 1) @@ -176,14 +185,14 @@ def create_vehicle(): vehicle.insert() -def create_delivery_trip(driver, address, contact=None): +def create_delivery_trip(driver, address, contact=None, company=None): if not contact: contact = get_contact_and_address("_Test Customer") delivery_trip = frappe.get_doc( { "doctype": "Delivery Trip", - "company": erpnext.get_default_company(), + "company": company or erpnext.get_default_company(), "departure_time": add_days(now_datetime(), 5), "driver": driver.name, "driver_address": address.name, diff --git a/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py b/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py index 1d7c475d1ae..cbf6059a812 100644 --- a/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py +++ b/erpnext/stock/doctype/inventory_dimension/test_inventory_dimension.py @@ -3,7 +3,6 @@ import frappe from frappe.custom.doctype.custom_field.custom_field import create_custom_field -from frappe.tests import IntegrationTestCase, change_settings from frappe.utils import nowdate, nowtime from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note @@ -19,12 +18,12 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_pu from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.doctype.stock_ledger_entry.stock_ledger_entry import InventoryDimensionNegativeStockError from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse +from erpnext.tests.utils import ERPNextTestSuite -class TestInventoryDimension(IntegrationTestCase): +class TestInventoryDimension(ERPNextTestSuite): def setUp(self): prepare_test_data() - create_store_dimension() def test_validate_inventory_dimension(self): # Can not be child doc @@ -497,7 +496,7 @@ class TestInventoryDimension(IntegrationTestCase): self.assertEqual(site_name, "Site 1") - @change_settings("Stock Settings", {"allow_negative_stock": 0}) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_negative_stock": 0}) def test_validate_negative_stock_with_multiple_dimension(self): item_code = "Test Negative Multi Inventory Dimension Item" create_item(item_code) @@ -557,144 +556,27 @@ def get_voucher_sl_entries(voucher_no, fields): ) -def create_store_dimension(): - if not frappe.db.exists("DocType", "Store"): - frappe.get_doc( - { - "doctype": "DocType", - "name": "Store", - "module": "Stock", - "custom": 1, - "naming_rule": "By fieldname", - "autoname": "field:store_name", - "fields": [{"label": "Store Name", "fieldname": "store_name", "fieldtype": "Data"}], - "permissions": [ - { - "role": "System Manager", - "permlevel": 0, - "read": 1, - "write": 1, - "create": 1, - "delete": 1, - } - ], - } - ).insert(ignore_permissions=True) - - for store in ["Store 1", "Store 2"]: - if not frappe.db.exists("Store", store): - frappe.get_doc({"doctype": "Store", "store_name": store}).insert(ignore_permissions=True) - - def prepare_test_data(): - if not frappe.db.exists("DocType", "Shelf"): - frappe.get_doc( - { - "doctype": "DocType", - "name": "Shelf", - "module": "Stock", - "custom": 1, - "naming_rule": "By fieldname", - "autoname": "field:shelf_name", - "fields": [{"label": "Shelf Name", "fieldname": "shelf_name", "fieldtype": "Data"}], - "permissions": [ - { - "role": "System Manager", - "permlevel": 0, - "read": 1, - "write": 1, - "create": 1, - "delete": 1, - } - ], - } - ).insert(ignore_permissions=True) - for shelf in ["Shelf 1", "Shelf 2"]: if not frappe.db.exists("Shelf", shelf): frappe.get_doc({"doctype": "Shelf", "shelf_name": shelf}).insert(ignore_permissions=True) create_warehouse("Shelf Warehouse") - if not frappe.db.exists("DocType", "Rack"): - frappe.get_doc( - { - "doctype": "DocType", - "name": "Rack", - "module": "Stock", - "custom": 1, - "naming_rule": "By fieldname", - "autoname": "field:rack_name", - "fields": [{"label": "Rack Name", "fieldname": "rack_name", "fieldtype": "Data"}], - "permissions": [ - { - "role": "System Manager", - "permlevel": 0, - "read": 1, - "write": 1, - "create": 1, - "delete": 1, - } - ], - } - ).insert(ignore_permissions=True) - for rack in ["Rack 1", "Rack 2"]: if not frappe.db.exists("Rack", rack): frappe.get_doc({"doctype": "Rack", "rack_name": rack}).insert(ignore_permissions=True) create_warehouse("Rack Warehouse") - if not frappe.db.exists("DocType", "Pallet"): - frappe.get_doc( - { - "doctype": "DocType", - "name": "Pallet", - "module": "Stock", - "custom": 1, - "naming_rule": "By fieldname", - "autoname": "field:pallet_name", - "fields": [{"label": "Pallet Name", "fieldname": "pallet_name", "fieldtype": "Data"}], - "permissions": [ - { - "role": "System Manager", - "permlevel": 0, - "read": 1, - "write": 1, - "create": 1, - "delete": 1, - } - ], - } - ).insert(ignore_permissions=True) - - if not frappe.db.exists("DocType", "Inv Site"): - frappe.get_doc( - { - "doctype": "DocType", - "name": "Inv Site", - "module": "Stock", - "custom": 1, - "naming_rule": "By fieldname", - "autoname": "field:site_name", - "fields": [{"label": "Site Name", "fieldname": "site_name", "fieldtype": "Data"}], - "permissions": [ - { - "role": "System Manager", - "permlevel": 0, - "read": 1, - "write": 1, - "create": 1, - "delete": 1, - } - ], - } - ).insert(ignore_permissions=True) - for site in ["Site 1", "Site 2"]: if not frappe.db.exists("Inv Site", site): frappe.get_doc({"doctype": "Inv Site", "site_name": site}).insert(ignore_permissions=True) + for store in ["Store 1", "Store 2"]: + if not frappe.db.exists("Store", store): + frappe.get_doc({"doctype": "Store", "store_name": store}).insert(ignore_permissions=True) + def create_inventory_dimension(**args): args = frappe._dict(args) diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py index 7814efb1c0b..b580582339d 100644 --- a/erpnext/stock/doctype/item/test_item.py +++ b/erpnext/stock/doctype/item/test_item.py @@ -5,9 +5,8 @@ import json import frappe +from frappe import qb from frappe.custom.doctype.property_setter.property_setter import make_property_setter -from frappe.test_runner import make_test_objects -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, today from erpnext.controllers.item_variant import ( @@ -27,9 +26,7 @@ from erpnext.stock.doctype.item.item import ( ) from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.get_item_details import ItemDetailsCtx, get_item_details - -IGNORE_TEST_RECORD_DEPENDENCIES = ["BOM"] -EXTRA_TEST_RECORD_DEPENDENCIES = ["Warehouse", "Item Group", "Item Tax Template", "Brand", "Item Attribute"] +from erpnext.tests.utils import ERPNextTestSuite def make_item(item_code=None, properties=None, uoms=None, barcode=None): @@ -74,7 +71,7 @@ def make_item(item_code=None, properties=None, uoms=None, barcode=None): return item -class TestItem(IntegrationTestCase): +class TestItem(ERPNextTestSuite): def setUp(self): super().setUp() frappe.flags.attribute_values = None @@ -88,11 +85,25 @@ class TestItem(IntegrationTestCase): item = frappe.get_doc("Item", item_code) return item - def test_get_item_details(self): - # delete modified item price record and make as per self.globalTestRecords["Item"] - frappe.db.sql("""delete from `tabItem Price`""") - frappe.db.sql("""delete from `tabBin`""") + def make_bin(self, records): + for x in records: + x = frappe._dict(x) + bin = qb.DocType("Bin") + filters = { + "item_code": x.get("item_code"), + "warehouse": x.get("warehouse"), + "reserved_qty": x.get("reserved_qty"), + "actual_qty": x.get("actual_qty"), + "ordered_qty": x.get("ordered_qty"), + "projected_qty": x.get("projected_qty"), + } + if not frappe.db.exists("Bin", filters): + qb.from_(bin).delete().where( + bin.item_code.eq(x.item_code) & bin.warehouse.eq(x.warehouse) + ).run() + frappe.get_doc(x).insert() + def test_get_item_details(self): to_check = { "item_code": "_Test Item", "item_name": "_Test Item", @@ -117,11 +128,10 @@ class TestItem(IntegrationTestCase): "projected_qty": 14, } - make_test_objects("Item Price") - make_test_objects( - "Bin", + self.make_bin( [ { + "doctype": "Bin", "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC", "reserved_qty": 1, @@ -159,9 +169,9 @@ class TestItem(IntegrationTestCase): self.assertEqual(value, details.get(key), key) def test_get_asset_item_details(self): - from erpnext.assets.doctype.asset.test_asset import create_asset_category, create_fixed_asset_item + from erpnext.assets.doctype.asset.test_asset import create_fixed_asset_item - create_asset_category(0) + frappe.db.set_value("Asset Category", "Computers", "enable_cwip_accounting", 0) create_fixed_asset_item() details = get_item_details( @@ -398,7 +408,6 @@ class TestItem(IntegrationTestCase): frappe.flags.attribute_values = None self.assertRaises(InvalidItemAttributeValueError, attribute.save) - frappe.db.rollback() def test_make_item_variant(self): frappe.delete_doc_if_exists("Item", "_Test Variant Item-L", force=1) @@ -741,13 +750,13 @@ class TestItem(IntegrationTestCase): except frappe.ValidationError as e: self.fail(f"stock item considered non-stock item: {e}") - @IntegrationTestCase.change_settings("Stock Settings", {"item_naming_by": "Naming Series"}) + @ERPNextTestSuite.change_settings("Stock Settings", {"item_naming_by": "Naming Series"}) def test_autoname_series(self): item = frappe.new_doc("Item") item.item_group = "All Item Groups" item.save() # if item code saved without item_code then series worked - @IntegrationTestCase.change_settings("Stock Settings", {"allow_negative_stock": 0}) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_negative_stock": 0}) def test_item_wise_negative_stock(self): """When global settings are disabled check that item that allows negative stock can still consume material in all known stock @@ -759,7 +768,7 @@ class TestItem(IntegrationTestCase): self.consume_item_code_with_differet_stock_transactions(item_code=item.name) - @IntegrationTestCase.change_settings("Stock Settings", {"allow_negative_stock": 0}) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_negative_stock": 0}) def test_backdated_negative_stock(self): """same as test above but backdated entries""" from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry @@ -772,7 +781,7 @@ class TestItem(IntegrationTestCase): ) self.consume_item_code_with_differet_stock_transactions(item_code=item.name) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", {"sample_retention_warehouse": "_Test Warehouse - _TC"} ) def test_retain_sample(self): @@ -877,7 +886,7 @@ class TestItem(IntegrationTestCase): item.reload() self.assertEqual(item.is_stock_item, 1) - def test_serach_fields_for_item(self): + def test_search_fields_for_item(self): from erpnext.controllers.queries import item_query make_property_setter("Item", None, "search_fields", "item_name", "Data", for_doctype="Doctype") diff --git a/erpnext/stock/doctype/item/test_records.json b/erpnext/stock/doctype/item/test_records.json deleted file mode 100644 index 30eaed272e4..00000000000 --- a/erpnext/stock/doctype/item/test_records.json +++ /dev/null @@ -1,450 +0,0 @@ -[ - { - "description": "_Test Item 1", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "_Test Item", - "item_group": "_Test Item Group", - "item_name": "_Test Item", - "apply_warehouse_wise_reorder_level": 1, - "opening_stock": 10, - "valuation_rate": 100, - "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" - }], - "reorder_levels": [ - { - "material_request_type": "Purchase", - "warehouse": "_Test Warehouse - _TC", - "warehouse_reorder_level": 20, - "warehouse_reorder_qty": 20 - } - ], - "uoms": [ - { - "uom": "_Test UOM", - "conversion_factor": 1.0 - }, - { - "uom": "_Test UOM 1", - "conversion_factor": 10.0 - } - ], - "stock_uom": "_Test UOM" - }, - { - "description": "_Test Item 2", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "_Test Item 2", - "item_group": "_Test Item Group", - "item_name": "_Test Item 2", - "stock_uom": "_Test UOM", - "opening_stock": 10, - "valuation_rate": 100, - "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" - }] - }, - { - "description": "_Test Item Home Desktop 100 3", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "_Test Item Home Desktop 100", - "item_group": "_Test Item Group Desktops", - "item_name": "_Test Item Home Desktop 100", - "valuation_rate": 100, - "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" - }], - "taxes": [ - { - "doctype": "Item Tax", - "parentfield": "taxes", - "item_tax_template": "_Test Account Excise Duty @ 10 - _TC" - } - ], - "stock_uom": "_Test UOM 1" - }, - { - "description": "_Test Item Home Desktop 200 4", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_sub_contracted_item": 0, - "item_code": "_Test Item Home Desktop 200", - "item_group": "_Test Item Group Desktops", - "item_name": "_Test Item Home Desktop 200", - "stock_uom": "_Test UOM 1", - "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" - }] - }, - { - "description": "_Test Product Bundle Item 5", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 0, - "is_sub_contracted_item": 0, - "item_code": "_Test Product Bundle Item", - "item_group": "_Test Item Group Desktops", - "item_name": "_Test Product Bundle Item", - "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" - }] - }, - { - "description": "_Test FG Item 6", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 1, - "item_code": "_Test FG Item", - "item_group": "_Test Item Group Desktops", - "item_name": "_Test FG Item", - "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" - }] - }, - { - "description": "_Test Non Stock Item 7", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 0, - "is_sub_contracted_item": 0, - "item_code": "_Test Non Stock Item", - "item_group": "_Test Item Group Desktops", - "item_name": "_Test Non Stock Item", - "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" - }] - }, - { - "description": "_Test Serialized Item 8", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 1, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "_Test Serialized Item", - "item_group": "_Test Item Group Desktops", - "item_name": "_Test Serialized Item", - "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" - }] - }, - { - "description": "_Test Serialized Item 9", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 1, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "_Test Serialized Item With Series", - "item_group": "_Test Item Group Desktops", - "item_name": "_Test Serialized Item With Series", - "serial_no_series": "ABCD.#####", - "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" - }] - }, - { - "description": "_Test Item Home Desktop Manufactured 10", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "_Test Item Home Desktop Manufactured", - "item_group": "_Test Item Group Desktops", - "item_name": "_Test Item Home Desktop Manufactured", - "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" - }] - }, - { - "description": "_Test FG Item 2 11", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 1, - "item_code": "_Test FG Item 2", - "item_group": "_Test Item Group Desktops", - "item_name": "_Test FG Item 2", - "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" - }] - }, - { - "description": "_Test Variant Item 12", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 1, - "item_code": "_Test Variant Item", - "item_group": "_Test Item Group Desktops", - "item_name": "_Test Variant Item", - "stock_uom": "_Test UOM", - "has_variants": 1, - "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" - } - ], - "apply_warehouse_wise_reorder_level": 1, - "reorder_levels": [ - { - "material_request_type": "Purchase", - "warehouse": "_Test Warehouse - _TC", - "warehouse_reorder_level": 20, - "warehouse_reorder_qty": 20 - } - ] - }, - { - "description": "_Test Item 1", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "_Test Item Warehouse Group Wise Reorder", - "item_group": "_Test Item Group", - "item_name": "_Test Item Warehouse Group Wise Reorder", - "apply_warehouse_wise_reorder_level": 1, - "item_defaults": [{ - "company": "_Test Company", - "default_warehouse": "_Test Warehouse Group-C1 - _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" - }], - "reorder_levels": [ - { - "warehouse_group": "_Test Warehouse Group - _TC", - "material_request_type": "Purchase", - "warehouse": "_Test Warehouse Group-C1 - _TC", - "warehouse_reorder_level": 20, - "warehouse_reorder_qty": 20 - } - ], - "stock_uom": "_Test UOM" - }, - { - "description": "_Test Item With Item Tax Template", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "_Test Item With Item Tax Template", - "item_group": "_Test Item Group", - "item_name": "_Test Item With Item Tax Template", - "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" - }], - "taxes": [ - { - "doctype": "Item Tax", - "parentfield": "taxes", - "item_tax_template": "_Test Account Excise Duty @ 10 - _TC" - }, - { - "doctype": "Item Tax", - "parentfield": "taxes", - "item_tax_template": "_Test Account Excise Duty @ 12 - _TC", - "tax_category": "_Test Tax Category 1" - } - ] - }, - { - "description": "_Test Item Inherit Group Item Tax Template 1", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "_Test Item Inherit Group Item Tax Template 1", - "item_group": "_Test Item Group Tax Parent", - "item_name": "_Test Item Inherit Group Item Tax Template 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" - }] - }, - { - "description": "_Test Item Inherit Group Item Tax Template 2", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "_Test Item Inherit Group Item Tax Template 2", - "item_group": "_Test Item Group Tax Child Override", - "item_name": "_Test Item Inherit Group Item Tax Template 2", - "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" - }] - }, - { - "description": "_Test Item Override Group Item Tax Template", - "doctype": "Item", - "has_batch_no": 0, - "has_serial_no": 0, - "inspection_required": 0, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "_Test Item Override Group Item Tax Template", - "item_group": "_Test Item Group Tax Child Override", - "item_name": "_Test Item Override Group Item Tax Template", - "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" - }], - "taxes": [ - { - "doctype": "Item Tax", - "parentfield": "taxes", - "item_tax_template": "_Test Account Excise Duty @ 20 - _TC" - }, - { - "doctype": "Item Tax", - "parentfield": "taxes", - "tax_category": "_Test Tax Category 1", - "item_tax_template": "_Test Item Tax Template 1 - _TC" - } - ] - }, - { - "description": "_Test", - "doctype": "Item", - "is_stock_item": 1, - "item_code": "138-CMS Shoe", - "item_group": "_Test Item Group", - "item_name": "138-CMS Shoe", - "stock_uom": "_Test UOM" - } -] diff --git a/erpnext/stock/doctype/item_alternative/test_item_alternative.py b/erpnext/stock/doctype/item_alternative/test_item_alternative.py index d96061e0d94..0a2119af3ec 100644 --- a/erpnext/stock/doctype/item_alternative/test_item_alternative.py +++ b/erpnext/stock/doctype/item_alternative/test_item_alternative.py @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import flt from erpnext.controllers.subcontracting_controller import make_rm_stock_entry @@ -24,9 +23,10 @@ from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import from erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order import ( make_subcontracting_receipt, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestItemAlternative(IntegrationTestCase): +class TestItemAlternative(ERPNextTestSuite): def setUp(self): super().setUp() make_items() diff --git a/erpnext/stock/doctype/item_attribute/test_item_attribute.py b/erpnext/stock/doctype/item_attribute/test_item_attribute.py index 7ed800dca19..63958733eba 100644 --- a/erpnext/stock/doctype/item_attribute/test_item_attribute.py +++ b/erpnext/stock/doctype/item_attribute/test_item_attribute.py @@ -3,12 +3,12 @@ import frappe -from frappe.tests import IntegrationTestCase from erpnext.stock.doctype.item_attribute.item_attribute import ItemAttributeIncrementError +from erpnext.tests.utils import ERPNextTestSuite -class TestItemAttribute(IntegrationTestCase): +class TestItemAttribute(ERPNextTestSuite): def setUp(self): super().setUp() if frappe.db.exists("Item Attribute", "_Test_Length"): diff --git a/erpnext/stock/doctype/item_attribute/test_records.json b/erpnext/stock/doctype/item_attribute/test_records.json deleted file mode 100644 index 6aa6ffd6c9b..00000000000 --- a/erpnext/stock/doctype/item_attribute/test_records.json +++ /dev/null @@ -1,25 +0,0 @@ -[ - { - "doctype": "Item Attribute", - "attribute_name": "Test Size", - "priority": 1, - "item_attribute_values": [ - {"attribute_value": "Extra Small", "abbr": "XSL"}, - {"attribute_value": "Small", "abbr": "S"}, - {"attribute_value": "Medium", "abbr": "M"}, - {"attribute_value": "Large", "abbr": "L"}, - {"attribute_value": "Extra Large", "abbr": "XL"}, - {"attribute_value": "2XL", "abbr": "2XL"} - ] - }, - { - "doctype": "Item Attribute", - "attribute_name": "Test Colour", - "priority": 2, - "item_attribute_values": [ - {"attribute_value": "Red", "abbr": "R"}, - {"attribute_value": "Green", "abbr": "G"}, - {"attribute_value": "Blue", "abbr": "B"} - ] - } -] diff --git a/erpnext/stock/doctype/item_lead_time/test_item_lead_time.py b/erpnext/stock/doctype/item_lead_time/test_item_lead_time.py index 49601b5faad..e695b11bcb5 100644 --- a/erpnext/stock/doctype/item_lead_time/test_item_lead_time.py +++ b/erpnext/stock/doctype/item_lead_time/test_item_lead_time.py @@ -2,19 +2,3 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] - - -class IntegrationTestItemLeadTime(IntegrationTestCase): - """ - Integration tests for ItemLeadTime. - Use this class for testing interactions between multiple components. - """ - - pass diff --git a/erpnext/stock/doctype/item_manufacturer/test_item_manufacturer.py b/erpnext/stock/doctype/item_manufacturer/test_item_manufacturer.py index bf82f3611ed..74bc8c37cd0 100644 --- a/erpnext/stock/doctype/item_manufacturer/test_item_manufacturer.py +++ b/erpnext/stock/doctype/item_manufacturer/test_item_manufacturer.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestItemManufacturer(IntegrationTestCase): +class TestItemManufacturer(ERPNextTestSuite): pass diff --git a/erpnext/stock/doctype/item_price/test_item_price.py b/erpnext/stock/doctype/item_price/test_item_price.py index 42726054c1b..f2f177dd8fe 100644 --- a/erpnext/stock/doctype/item_price/test_item_price.py +++ b/erpnext/stock/doctype/item_price/test_item_price.py @@ -3,18 +3,16 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.tests.utils import make_test_records_for_doctype from erpnext.stock.doctype.item_price.item_price import ItemPriceDuplicateItem from erpnext.stock.get_item_details import ItemDetailsCtx, get_price_list_rate_for +from erpnext.tests.utils import ERPNextTestSuite -class TestItemPrice(IntegrationTestCase): +class TestItemPrice(ERPNextTestSuite): def setUp(self): - super().setUp() - frappe.db.sql("delete from `tabItem Price`") - make_test_records_for_doctype("Item Price", force=True) + self.load_test_records("Item Price") def test_template_item_price(self): from erpnext.stock.doctype.item.test_item import make_item @@ -195,6 +193,5 @@ class TestItemPrice(IntegrationTestCase): ) price = get_price_list_rate_for(ctx, doc.item_code) - frappe.db.rollback() self.assertEqual(price, 21) diff --git a/erpnext/stock/doctype/item_variant_settings/test_item_variant_settings.py b/erpnext/stock/doctype/item_variant_settings/test_item_variant_settings.py index b526eadd8e8..8eb4c864ae5 100644 --- a/erpnext/stock/doctype/item_variant_settings/test_item_variant_settings.py +++ b/erpnext/stock/doctype/item_variant_settings/test_item_variant_settings.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestItemVariantSettings(IntegrationTestCase): +class TestItemVariantSettings(ERPNextTestSuite): pass diff --git a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py index f68351a5611..ee2b2051e8b 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py @@ -5,13 +5,12 @@ import copy import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_to_date, flt, now, nowtime, today from erpnext.accounts.doctype.account.test_account import create_account, get_inventory_account from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.accounts.utils import update_gl_entries_after -from erpnext.assets.doctype.asset.test_asset import create_asset_category, create_fixed_asset_item +from erpnext.assets.doctype.asset.test_asset import create_fixed_asset_item from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import ( get_gl_entries, @@ -21,11 +20,13 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle get_serial_nos_from_bundle, ) from erpnext.stock.serial_batch_bundle import SerialNoValuation - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Currency Exchange"] +from erpnext.tests.utils import ERPNextTestSuite -class TestLandedCostVoucher(IntegrationTestCase): +class TestLandedCostVoucher(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Currency Exchange") + def test_landed_cost_voucher(self): frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1) @@ -400,6 +401,7 @@ class TestLandedCostVoucher(IntegrationTestCase): "doctype": "Serial No", "item_code": item_code, "serial_no": serial_no, + "company": "_Test Company", } ).insert() @@ -600,9 +602,6 @@ class TestLandedCostVoucher(IntegrationTestCase): "Company", "_Test Company", "capital_work_in_progress_account", "CWIP Account - _TC" ) - if not frappe.db.exists("Asset Category", "Computers"): - create_asset_category() - if not frappe.db.exists("Item", "Macbook Pro"): create_fixed_asset_item() @@ -671,6 +670,7 @@ class TestLandedCostVoucher(IntegrationTestCase): "doctype": "Serial No", "item_code": sn_item, "serial_no": sn, + "company": "_Test Company", } ) sn_doc.insert() @@ -821,6 +821,7 @@ class TestLandedCostVoucher(IntegrationTestCase): "doctype": "Serial No", "item_code": sn_item, "serial_no": sn, + "company": "_Test Company", } ) sn_doc.insert() @@ -1011,6 +1012,7 @@ class TestLandedCostVoucher(IntegrationTestCase): "doctype": "Serial No", "item_code": sn_item, "serial_no": sn, + "company": "_Test Company", } ) sn_doc.insert() diff --git a/erpnext/stock/doctype/manufacturer/test_manufacturer.py b/erpnext/stock/doctype/manufacturer/test_manufacturer.py index 1469901e26a..4caa84be53a 100644 --- a/erpnext/stock/doctype/manufacturer/test_manufacturer.py +++ b/erpnext/stock/doctype/manufacturer/test_manufacturer.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestManufacturer(IntegrationTestCase): +class TestManufacturer(ERPNextTestSuite): pass diff --git a/erpnext/stock/doctype/material_request/test_material_request.py b/erpnext/stock/doctype/material_request/test_material_request.py index da5bfd270df..e72637901b5 100644 --- a/erpnext/stock/doctype/material_request/test_material_request.py +++ b/erpnext/stock/doctype/material_request/test_material_request.py @@ -6,7 +6,6 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import flt, today from erpnext.controllers.accounts_controller import InvalidQtyError @@ -21,9 +20,13 @@ from erpnext.stock.doctype.material_request.material_request import ( ) from erpnext.stock.doctype.stock_entry.stock_entry import make_stock_in_entry from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse +from erpnext.tests.utils import ERPNextTestSuite -class TestMaterialRequest(IntegrationTestCase): +class TestMaterialRequest(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Material Request") + def test_material_request_qty(self): mr = frappe.copy_doc(self.globalTestRecords["Material Request"][0]) mr.items[0].qty = 0 @@ -1191,6 +1194,3 @@ def make_material_request(**args): if not args.do_not_submit: mr.submit() return mr - - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Currency Exchange", "BOM"] diff --git a/erpnext/stock/doctype/material_request/test_records.json b/erpnext/stock/doctype/material_request/test_records.json index 1c714969eb3..d49a8071af0 100644 --- a/erpnext/stock/doctype/material_request/test_records.json +++ b/erpnext/stock/doctype/material_request/test_records.json @@ -1,57 +1,57 @@ [ { - "company": "_Test Company", - "doctype": "Material Request", - "fiscal_year": "_Test Fiscal Year 2013", + "company": "_Test Company", + "doctype": "Material Request", + "fiscal_year": "_Test Fiscal Year 2013", "items": [ { - "description": "_Test Item Home Desktop 100", - "doctype": "Material Request Item", - "item_code": "_Test Item Home Desktop 100", - "item_name": "_Test Item Home Desktop 100", - "parentfield": "items", - "qty": 54.0, - "schedule_date": "2013-02-18", - "uom": "_Test UOM 1", + "description": "_Test Item Home Desktop 100", + "doctype": "Material Request Item", + "item_code": "_Test Item Home Desktop 100", + "item_name": "_Test Item Home Desktop 100", + "parentfield": "items", + "qty": 54.0, + "schedule_date": "2013-02-18", + "uom": "_Test UOM 1", "warehouse": "_Test Warehouse - _TC" - }, + }, { - "description": "_Test Item Home Desktop 200", - "doctype": "Material Request Item", - "item_code": "_Test Item Home Desktop 200", - "item_name": "_Test Item Home Desktop 200", - "parentfield": "items", - "qty": 3.0, - "schedule_date": "2013-02-19", - "uom": "_Test UOM 1", + "description": "_Test Item Home Desktop 200", + "doctype": "Material Request Item", + "item_code": "_Test Item Home Desktop 200", + "item_name": "_Test Item Home Desktop 200", + "parentfield": "items", + "qty": 3.0, + "schedule_date": "2013-02-19", + "uom": "_Test UOM 1", "warehouse": "_Test Warehouse - _TC" } - ], - "material_request_type": "Purchase", - "naming_series": "_T-Material Request-", + ], + "material_request_type": "Purchase", + "naming_series": "_T-Material Request-", "transaction_date": "2013-02-18", "schedule_date": "2013-02-19" }, { - "company": "_Test Company", - "doctype": "Material Request", - "fiscal_year": "_Test Fiscal Year 2013", + "company": "_Test Company", + "doctype": "Material Request", + "fiscal_year": "_Test Fiscal Year 2013", "items": [ { - "description": "_Test FG Item", - "doctype": "Material Request Item", - "item_code": "_Test FG Item", - "item_name": "_Test FG Item", - "parentfield": "items", - "qty": 5, + "description": "_Test FG Item", + "doctype": "Material Request Item", + "item_code": "_Test FG Item", + "item_name": "_Test FG Item", + "parentfield": "items", + "qty": 5, "schedule_date": "2013-02-19", - "uom": "_Test UOM 1", + "uom": "_Test UOM 1", "warehouse": "_Test Warehouse - _TC" } - ], - "material_request_type": "Manufacture", - "naming_series": "_T-Material Request-", + ], + "material_request_type": "Manufacture", + "naming_series": "_T-Material Request-", "transaction_date": "2013-02-18", "schedule_date": "2013-02-19" } -] \ No newline at end of file +] diff --git a/erpnext/stock/doctype/packed_item/test_packed_item.py b/erpnext/stock/doctype/packed_item/test_packed_item.py index 5ace12184a7..e7b22d04033 100644 --- a/erpnext/stock/doctype/packed_item/test_packed_item.py +++ b/erpnext/stock/doctype/packed_item/test_packed_item.py @@ -3,7 +3,6 @@ import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_to_date, nowdate from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note @@ -11,6 +10,7 @@ from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_orde from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite def create_product_bundle( @@ -40,18 +40,16 @@ def create_product_bundle( return bundle, components -class TestPackedItem(IntegrationTestCase): +class TestPackedItem(ERPNextTestSuite): "Test impact on Packed Items table in various scenarios." - @classmethod - def setUpClass(cls) -> None: - super().setUpClass() - cls.warehouse = "_Test Warehouse - _TC" + def setUp(self) -> None: + self.warehouse = "_Test Warehouse - _TC" - cls.bundle, cls.bundle_items = create_product_bundle(warehouse=cls.warehouse) - cls.bundle2, cls.bundle2_items = create_product_bundle(warehouse=cls.warehouse) + self.bundle, self.bundle_items = create_product_bundle(warehouse=self.warehouse) + self.bundle2, self.bundle2_items = create_product_bundle(warehouse=self.warehouse) - cls.normal_item = make_item().name + self.normal_item = make_item().name def test_adding_bundle_item(self): "Test impact on packed items if bundle item row is added." @@ -78,6 +76,7 @@ class TestPackedItem(IntegrationTestCase): self.assertEqual(len(so.packed_items), 0) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_recurring_bundle_item(self): "Test impact on packed items if same bundle item is added and removed." so_items = [] @@ -116,7 +115,7 @@ class TestPackedItem(IntegrationTestCase): self.assertEqual(so.packed_items[1].qty, 4) self.assertEqual(so.packed_items[3].qty, 12) - @IntegrationTestCase.change_settings("Selling Settings", {"editable_bundle_item_rates": 1}) + @ERPNextTestSuite.change_settings("Selling Settings", {"editable_bundle_item_rates": 1}) def test_bundle_item_cumulative_price(self): "Test if Bundle Item rate is cumulative from packed items." so = make_sales_order(item_code=self.bundle, qty=2, do_not_submit=True) @@ -128,6 +127,7 @@ class TestPackedItem(IntegrationTestCase): self.assertEqual(so.items[0].rate, 700) self.assertEqual(so.items[0].amount, 1400) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_newly_mapped_doc_packed_items(self): "Test impact on packed items in newly mapped DN from SO." so_items = [] diff --git a/erpnext/stock/doctype/packing_slip/test_packing_slip.py b/erpnext/stock/doctype/packing_slip/test_packing_slip.py index 8d16b2d8fe0..19e6c976edc 100644 --- a/erpnext/stock/doctype/packing_slip/test_packing_slip.py +++ b/erpnext/stock/doctype/packing_slip/test_packing_slip.py @@ -3,15 +3,15 @@ import frappe -from frappe.tests import IntegrationTestCase from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle from erpnext.stock.doctype.delivery_note.delivery_note import make_packing_slip from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.item.test_item import make_item +from erpnext.tests.utils import ERPNextTestSuite -class TestPackingSlip(IntegrationTestCase): +class TestPackingSlip(ERPNextTestSuite): def test_packing_slip(self): # Step - 1: Create a Product Bundle items = create_items() diff --git a/erpnext/stock/doctype/pick_list/test_pick_list.py b/erpnext/stock/doctype/pick_list/test_pick_list.py index 12c92310147..283e0207d60 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -3,7 +3,6 @@ import frappe from frappe import _dict -from frappe.tests import IntegrationTestCase from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle from erpnext.selling.doctype.sales_order.sales_order import create_pick_list @@ -21,11 +20,10 @@ from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import ( EmptyStockReconciliationItemsError, ) - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Sales Invoice", "Stock Entry", "Batch"] +from erpnext.tests.utils import ERPNextTestSuite -class TestPickList(IntegrationTestCase): +class TestPickList(ERPNextTestSuite): def test_pick_list_picks_warehouse_for_each_item(self): item_code = make_item().name try: @@ -280,7 +278,12 @@ class TestPickList(IntegrationTestCase): from erpnext.stock.doctype.batch.test_batch import make_new_batch batch_company = frappe.get_doc( - {"doctype": "Company", "company_name": "Batch Company", "default_currency": "INR"} + { + "doctype": "Company", + "company_name": "Batch Company", + "default_currency": "INR", + "country": "India", + } ) batch_company.insert() @@ -351,7 +354,12 @@ class TestPickList(IntegrationTestCase): warehouse_item = create_item("Warehouse Item") temp_company = frappe.get_doc( - {"doctype": "Company", "company_name": "Temp Company", "default_currency": "INR"} + { + "doctype": "Company", + "company_name": "Temp Company", + "default_currency": "INR", + "country": "India", + } ).insert() temp_warehouse = frappe.get_doc( {"doctype": "Warehouse", "warehouse_name": "Temp Warehouse", "company": temp_company.name} @@ -512,6 +520,7 @@ class TestPickList(IntegrationTestCase): self.assertEqual(pick_list.locations[1].qty, 5) self.assertEqual(pick_list.locations[1].sales_order_item, sales_order.items[0].name) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_pick_list_for_items_with_multiple_UOM(self): item_code = make_item( uoms=[ @@ -1376,6 +1385,7 @@ class TestPickList(IntegrationTestCase): frappe.db.set_single_value("Stock Settings", "over_picking_allowance", 0) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_ignore_pricing_rule_in_pick_list(self): frappe.flags.print_stmt = False warehouse = "_Test Warehouse - _TC" @@ -1477,6 +1487,7 @@ class TestPickList(IntegrationTestCase): for loc in pl.locations: self.assertEqual(loc.batch_no, batch2) + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_multiple_pick_lists_delivery_note(self): from erpnext.stock.doctype.pick_list.pick_list import create_dn_for_pick_lists @@ -1563,6 +1574,7 @@ class TestPickList(IntegrationTestCase): stock_entry_2.cancel() stock_entry_3.cancel() + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_multiple_items": 1}) def test_packed_item_multiple_times_in_so(self): frappe.db.delete("Item Price") warehouse_1 = "_Test Warehouse - _TC" diff --git a/erpnext/stock/doctype/price_list/test_records.json b/erpnext/stock/doctype/price_list/test_records.json deleted file mode 100644 index e02a7adbd8b..00000000000 --- a/erpnext/stock/doctype/price_list/test_records.json +++ /dev/null @@ -1,51 +0,0 @@ -[ - { - "buying": 1, - "currency": "INR", - "doctype": "Price List", - "enabled": 1, - "price_not_uom_dependant": 1, - "price_list_name": "_Test Price List", - "selling": 1 - }, - { - "buying": 1, - "currency": "INR", - "doctype": "Price List", - "enabled": 1, - "price_list_name": "_Test Price List 2", - "selling": 1 - }, - { - "buying": 1, - "currency": "INR", - "doctype": "Price List", - "enabled": 1, - "price_list_name": "_Test Price List India", - "selling": 1 - }, - { - "buying": 1, - "currency": "USD", - "doctype": "Price List", - "enabled": 1, - "price_list_name": "_Test Price List Rest of the World", - "selling": 1 - }, - { - "buying": 0, - "currency": "USD", - "doctype": "Price List", - "enabled": 1, - "price_list_name": "_Test Selling Price List", - "selling": 1 - }, - { - "buying": 1, - "currency": "USD", - "doctype": "Price List", - "enabled": 1, - "price_list_name": "_Test Buying Price List", - "selling": 0 - } -] diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 7fb31928ac5..3772c051b75 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -2,7 +2,6 @@ # License: GNU General Public License v3. See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, cint, cstr, flt, get_datetime, getdate, nowtime, today from pypika import functions as fn @@ -26,11 +25,13 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle make_serial_batch_bundle, ) from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse +from erpnext.tests.utils import ERPNextTestSuite -class TestPurchaseReceipt(IntegrationTestCase): +class TestPurchaseReceipt(ERPNextTestSuite): def setUp(self): - frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1) + frappe.local.future_sle = {} + self.load_test_records("Purchase Receipt") def test_purchase_receipt_qty(self): pr = make_purchase_receipt(qty=0, rejected_qty=0, do_not_save=True) @@ -126,7 +127,6 @@ class TestPurchaseReceipt(IntegrationTestCase): template = frappe.db.get_value( "Payment Terms Template", "_Test Payment Terms Template For Purchase Invoice" ) - old_template_in_supplier = frappe.db.get_value("Supplier", "_Test Supplier", "payment_terms") frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", template) pr = make_purchase_receipt(do_not_save=True) @@ -149,12 +149,6 @@ class TestPurchaseReceipt(IntegrationTestCase): self.assertEqual(pi.payment_schedule[1].payment_amount, flt(pi.grand_total) / 2) self.assertEqual(pi.payment_schedule[1].invoice_portion, 50) - # teardown - pi.delete() # draft PI - pr.cancel() - frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", old_template_in_supplier) - frappe.get_doc("Payment Terms Template", "_Test Payment Terms Template For Purchase Invoice").delete() - def test_purchase_receipt_no_gl_entry(self): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry @@ -741,7 +735,12 @@ class TestPurchaseReceipt(IntegrationTestCase): serial_no = ["12903812901"] if not frappe.db.exists("Serial No", serial_no[0]): frappe.get_doc( - {"doctype": "Serial No", "item_code": item_code, "serial_no": serial_no[0]} + { + "doctype": "Serial No", + "item_code": item_code, + "serial_no": serial_no[0], + "company": "_Test Company", + } ).insert() pr_doc = make_purchase_receipt(item_code=item_code, qty=1, serial_no=serial_no) @@ -1301,7 +1300,7 @@ class TestPurchaseReceipt(IntegrationTestCase): self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount) - @IntegrationTestCase.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) + @ERPNextTestSuite.change_settings("Accounts Settings", {"automatically_fetch_payment_terms": 1}) def test_payment_terms_are_fetched_when_creating_purchase_invoice(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import ( create_payment_terms_template, @@ -1332,7 +1331,7 @@ class TestPurchaseReceipt(IntegrationTestCase): # self.assertEqual(po.payment_terms_template, pi.payment_terms_template) compare_payment_schedules(self, po, pi) - @IntegrationTestCase.change_settings("Stock Settings", {"allow_negative_stock": 1}) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_negative_stock": 1}) def test_neg_to_positive(self): from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry @@ -2659,12 +2658,12 @@ class TestPurchaseReceipt(IntegrationTestCase): gl_entries = get_gl_entries("Purchase Receipt", pr.name, skip_cancelled=True, as_dict=False) warehouse_account = get_warehouse_account_map("_Test Company") expected_gle = ( - ("Stock Received But Not Billed - _TC", 0, 10000, "Main - _TC"), - ("Freight and Forwarding Charges - _TC", 0, 2000, "Main - _TC"), - ("Expenses Included In Valuation - _TC", 0, 2000, "Main - _TC"), - (warehouse_account[pr.items[0].warehouse]["account"], 14000, 0, "Main - _TC"), + ("Stock Received But Not Billed - _TC", 0.0, 10000.0, "Main - _TC"), + ("Freight and Forwarding Charges - _TC", 0.0, 2000.0, "Main - _TC"), + ("Expenses Included In Valuation - _TC", 0.0, 2000.0, "Main - _TC"), + (warehouse_account[pr.items[0].warehouse]["account"], 14000.0, 0.0, "Main - _TC"), ) - self.assertSequenceEqual(expected_gle, gl_entries) + self.assertCountEqual(expected_gle, gl_entries) frappe.local.enable_perpetual_inventory["_Test Company"] = old_perpetual_inventory def test_purchase_receipt_with_use_serial_batch_field_for_rejected_qty(self): @@ -2699,6 +2698,7 @@ class TestPurchaseReceipt(IntegrationTestCase): "doctype": "Serial No", "item_code": serial_item, "serial_no": serial_no, + "company": "_Test Company", } ).insert() @@ -3992,6 +3992,7 @@ class TestPurchaseReceipt(IntegrationTestCase): "doctype": "Serial No", "item_code": serial_item, "serial_no": serial_no, + "company": "_Test Company", } ).insert() @@ -4171,8 +4172,6 @@ class TestPurchaseReceipt(IntegrationTestCase): make_purchase_return, ) - frappe.flags.through_repost_item_valuation = False - sn_item_code = make_item( "Test Serial No for Validation", {"has_serial_no": 1, "serial_no_series": "SN-TSNFVAL-.#####"} ).name @@ -4205,8 +4204,6 @@ class TestPurchaseReceipt(IntegrationTestCase): make_purchase_return, ) - frappe.flags.through_repost_item_valuation = False - batch_item_code = make_item( "Test Batch No for Validation", {"has_batch_no": 1, "batch_number_series": "BT-TSNFVAL-.#####", "create_new_batch": 1}, @@ -4458,7 +4455,7 @@ class TestPurchaseReceipt(IntegrationTestCase): frappe.db.set_single_value("Buying Settings", "set_valuation_rate_for_rejected_materials", 0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Buying Settings", {"bill_for_rejected_quantity_in_purchase_invoice": 1, "set_valuation_rate_for_rejected_materials": 1}, ) @@ -4816,7 +4813,7 @@ class TestPurchaseReceipt(IntegrationTestCase): self.assertEqual(sles, [1500.0, 1500.0]) - @IntegrationTestCase.change_settings("Stock Settings", {"allow_negative_stock": 0}) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_negative_stock": 0}) def test_multiple_transactions_with_same_posting_datetime(self): from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.stock_ledger import NegativeStockError @@ -4851,9 +4848,15 @@ class TestPurchaseReceipt(IntegrationTestCase): self.assertRaises(NegativeStockError, pr.cancel) - @IntegrationTestCase.change_settings( - "Buying Settings", {"set_landed_cost_based_on_purchase_invoice_rate": 1, "maintain_same_rate": 0} + @ERPNextTestSuite.change_settings( + "Buying Settings", + { + "set_landed_cost_based_on_purchase_invoice_rate": 1, + "maintain_same_rate": 0, + "allow_multiple_items": 1, + }, ) + @ERPNextTestSuite.change_settings("Accounts Settings", {"over_billing_allowance": 100}) def test_set_lcv_from_pi_created_against_po(self): from erpnext.buying.doctype.purchase_order.purchase_order import ( make_purchase_invoice as make_pi_against_po, @@ -4863,10 +4866,6 @@ class TestPurchaseReceipt(IntegrationTestCase): ) from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order - original_value = frappe.db.get_single_value("Accounts Settings", "over_billing_allowance") - - frappe.db.set_single_value("Accounts Settings", "over_billing_allowance", 100) - item_code = create_item("Test Item for LCV from PI against PO").name po = create_purchase_order(item_code=item_code, qty=10, rate=400) @@ -4891,8 +4890,6 @@ class TestPurchaseReceipt(IntegrationTestCase): amt_diff = 5000 * (row.qty / 10) - row.amount self.assertEqual(row.amount_difference_with_purchase_invoice, amt_diff) - frappe.db.set_single_value("Accounts Settings", "over_billing_allowance", original_value) - def test_purchase_return_with_and_without_return_against_rejected_qty(self): from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_return as _make_purchase_return, @@ -5578,6 +5575,3 @@ def make_purchase_receipt(**args): pr.load_from_db() return pr - - -EXTRA_TEST_RECORD_DEPENDENCIES = ["BOM", "Item Price", "Location"] diff --git a/erpnext/stock/doctype/purchase_receipt/test_records.json b/erpnext/stock/doctype/purchase_receipt/test_records.json index e7ea9af6b9d..86f8683ce25 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_records.json +++ b/erpnext/stock/doctype/purchase_receipt/test_records.json @@ -84,4 +84,4 @@ ], "supplier": "_Test Supplier" } -] \ No newline at end of file +] diff --git a/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py b/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py index df285665a38..257bd595b68 100644 --- a/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py +++ b/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from erpnext.stock.doctype.batch.test_batch import make_new_batch from erpnext.stock.doctype.item.test_item import make_item @@ -14,9 +13,10 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse from erpnext.stock.get_item_details import get_conversion_factor +from erpnext.tests.utils import ERPNextTestSuite -class TestPutawayRule(IntegrationTestCase): +class TestPutawayRule(ERPNextTestSuite): def setUp(self): if not frappe.db.exists("Item", "_Rice"): make_item( diff --git a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py index 3885df7c74a..34b140515f2 100644 --- a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py @@ -2,7 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import nowdate from erpnext.controllers.stock_controller import ( @@ -14,9 +13,10 @@ from erpnext.controllers.stock_controller import ( from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestQualityInspection(IntegrationTestCase): +class TestQualityInspection(ERPNextTestSuite): def setUp(self): super().setUp() create_item("_Test Item with QA") @@ -218,7 +218,7 @@ class TestQualityInspection(IntegrationTestCase): qa.save() self.assertEqual(qa.status, "Accepted") - @IntegrationTestCase.change_settings("System Settings", {"number_format": "#.###,##"}) + @ERPNextTestSuite.change_settings("System Settings", {"number_format": "#.###,##"}) def test_diff_number_format(self): self.assertEqual(frappe.db.get_default("number_format"), "#.###,##") # sanity check diff --git a/erpnext/stock/doctype/quality_inspection_parameter/test_quality_inspection_parameter.py b/erpnext/stock/doctype/quality_inspection_parameter/test_quality_inspection_parameter.py index 8b85e5681c7..73dd8e5cd9f 100644 --- a/erpnext/stock/doctype/quality_inspection_parameter/test_quality_inspection_parameter.py +++ b/erpnext/stock/doctype/quality_inspection_parameter/test_quality_inspection_parameter.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestQualityInspectionParameter(IntegrationTestCase): +class TestQualityInspectionParameter(ERPNextTestSuite): pass diff --git a/erpnext/stock/doctype/quality_inspection_parameter_group/test_quality_inspection_parameter_group.py b/erpnext/stock/doctype/quality_inspection_parameter_group/test_quality_inspection_parameter_group.py index d3c158676a5..4a468b80182 100644 --- a/erpnext/stock/doctype/quality_inspection_parameter_group/test_quality_inspection_parameter_group.py +++ b/erpnext/stock/doctype/quality_inspection_parameter_group/test_quality_inspection_parameter_group.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestQualityInspectionParameterGroup(IntegrationTestCase): +class TestQualityInspectionParameterGroup(ERPNextTestSuite): pass diff --git a/erpnext/stock/doctype/quality_inspection_template/test_quality_inspection_template.py b/erpnext/stock/doctype/quality_inspection_template/test_quality_inspection_template.py index 9094ac1d8a0..5a69de5264a 100644 --- a/erpnext/stock/doctype/quality_inspection_template/test_quality_inspection_template.py +++ b/erpnext/stock/doctype/quality_inspection_template/test_quality_inspection_template.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestQualityInspectionTemplate(IntegrationTestCase): +class TestQualityInspectionTemplate(ERPNextTestSuite): pass diff --git a/erpnext/stock/doctype/quality_inspection_template/test_records.json b/erpnext/stock/doctype/quality_inspection_template/test_records.json deleted file mode 100644 index 2da99f616ac..00000000000 --- a/erpnext/stock/doctype/quality_inspection_template/test_records.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "doctype": "Quality Inspection Parameter", - "parameter" : "_Test Param" - }, - { - "quality_inspection_template_name" : "_Test Quality Inspection Template", - "doctype": "Quality Inspection Template", - "item_quality_inspection_parameter" : [ - { - "specification": "_Test Param", - "doctype": "Item Quality Inspection Parameter", - "parentfield": "item_quality_inspection_parameter" - } - ] - } -] diff --git a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py index d4a8dc24c52..e0ddd6faa8e 100644 --- a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py @@ -5,7 +5,6 @@ from unittest.mock import MagicMock, call import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_to_date, now, nowdate, today from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice @@ -19,12 +18,10 @@ from erpnext.stock.doctype.repost_item_valuation.repost_item_valuation import ( from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.tests.test_utils import StockTestMixin from erpnext.stock.utils import PendingRepostingError +from erpnext.tests.utils import ERPNextTestSuite -class TestRepostItemValuation(IntegrationTestCase, StockTestMixin): - def tearDown(self): - frappe.flags.dont_execute_stock_reposts = False - +class TestRepostItemValuation(ERPNextTestSuite, StockTestMixin): def test_repost_time_slot(self): repost_settings = frappe.get_doc("Stock Reposting Settings") @@ -195,7 +192,7 @@ class TestRepostItemValuation(IntegrationTestCase, StockTestMixin): riv.set_status("Skipped") - @IntegrationTestCase.change_settings("Stock Reposting Settings", {"item_based_reposting": 0}) + @ERPNextTestSuite.change_settings("Stock Reposting Settings", {"item_based_reposting": 0}) def test_prevention_of_cancelled_transaction_riv(self): frappe.flags.dont_execute_stock_reposts = True @@ -374,7 +371,7 @@ class TestRepostItemValuation(IntegrationTestCase, StockTestMixin): company.accounts_frozen_till_date = "" company.save() - @IntegrationTestCase.change_settings("Stock Reposting Settings", {"item_based_reposting": 0}) + @ERPNextTestSuite.change_settings("Stock Reposting Settings", {"item_based_reposting": 0}) def test_create_repost_entry_for_cancelled_document(self): pr = make_purchase_receipt( company="_Test Company with perpetual inventory", diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index aa7f276ddc1..5ca0bef74fc 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -443,7 +443,7 @@ class SerialandBatchBundle(Document): self.set_incoming_rate_for_inward_transaction(row, save, prev_sle=prev_sle) def validate_returned_serial_batch_no(self, return_against, row, original_inv_details): - if frappe.flags.through_repost_item_valuation: + if frappe.flags.through_repost_item_valuation and not frappe.in_test: return if row.serial_no and row.serial_no not in original_inv_details["serial_nos"]: diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py index d02affd68f0..c6929fe4cdb 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/test_serial_and_batch_bundle.py @@ -4,7 +4,6 @@ import json import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import flt, nowtime, today from erpnext.stock.doctype.item.test_item import make_item @@ -15,9 +14,10 @@ from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle impor make_serial_nos, ) from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestSerialandBatchBundle(IntegrationTestCase): +class TestSerialandBatchBundle(ERPNextTestSuite): def test_naming_for_sabb(self): frappe.db.set_single_value( "Stock Settings", "set_serial_and_batch_bundle_naming_based_on_naming_series", 1 @@ -40,6 +40,7 @@ class TestSerialandBatchBundle(IntegrationTestCase): "doctype": "Serial No", "serial_no": sn, "item_code": serial_item_code, + "company": "_Test Company", } ).insert(ignore_permissions=True) @@ -706,6 +707,7 @@ class TestSerialandBatchBundle(IntegrationTestCase): "doctype": "Serial No", "serial_no": serial_no, "item_code": item, + "company": "_Test Company", } ).insert(ignore_permissions=True) @@ -769,7 +771,7 @@ class TestSerialandBatchBundle(IntegrationTestCase): make_serial_nos(item_code, serial_nos) self.assertTrue(frappe.db.exists("Serial No", serial_no_id)) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", {"auto_create_serial_and_batch_bundle_for_outward": 1} ) def test_duplicate_serial_and_batch_bundle(self): @@ -803,6 +805,7 @@ class TestSerialandBatchBundle(IntegrationTestCase): "doctype": "Serial No", "serial_no": serial_no, "item_code": sn_item, + "company": "_Test Company", } ).insert(ignore_permissions=True) serial_nos.append(serial_no) diff --git a/erpnext/stock/doctype/serial_no/test_records.json b/erpnext/stock/doctype/serial_no/test_records.json deleted file mode 100644 index 0637a088a01..00000000000 --- a/erpnext/stock/doctype/serial_no/test_records.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/erpnext/stock/doctype/serial_no/test_serial_no.py b/erpnext/stock/doctype/serial_no/test_serial_no.py index c1300ee531b..3ad635eb65b 100644 --- a/erpnext/stock/doctype/serial_no/test_serial_no.py +++ b/erpnext/stock/doctype/serial_no/test_serial_no.py @@ -7,7 +7,6 @@ import frappe from frappe import _dict -from frappe.tests import IntegrationTestCase from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.item.test_item import make_item @@ -20,13 +19,12 @@ from erpnext.stock.doctype.serial_no.serial_no import * from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item"] +from erpnext.tests.utils import ERPNextTestSuite -class TestSerialNo(IntegrationTestCase): - def tearDown(self): - frappe.db.rollback() +class TestSerialNo(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Stock Entry") def test_cannot_create_direct(self): frappe.delete_doc_if_exists("Serial No", "_TCSER0001") @@ -36,6 +34,7 @@ class TestSerialNo(IntegrationTestCase): sr.warehouse = "_Test Warehouse - _TC" sr.serial_no = "_TCSER0001" sr.purchase_rate = 10 + sr.company = "_Test Company" self.assertRaises(SerialNoCannotCreateDirectError, sr.insert) sr.warehouse = None @@ -195,7 +194,12 @@ class TestSerialNo(IntegrationTestCase): for serial_no in serial_nos: if not frappe.db.exists("Serial No", serial_no): frappe.get_doc( - {"doctype": "Serial No", "item_code": item_code, "serial_no": serial_no} + { + "doctype": "Serial No", + "item_code": item_code, + "serial_no": serial_no, + "company": "_Test Company", + } ).insert() make_stock_entry( diff --git a/erpnext/stock/doctype/shipment/test_shipment.py b/erpnext/stock/doctype/shipment/test_shipment.py index 4a26107524e..7e58f942faf 100644 --- a/erpnext/stock/doctype/shipment/test_shipment.py +++ b/erpnext/stock/doctype/shipment/test_shipment.py @@ -4,12 +4,12 @@ from datetime import date, timedelta import frappe -from frappe.tests import IntegrationTestCase from erpnext.stock.doctype.delivery_note.delivery_note import make_shipment +from erpnext.tests.utils import ERPNextTestSuite -class TestShipment(IntegrationTestCase): +class TestShipment(ERPNextTestSuite): def test_shipment_from_delivery_note(self): delivery_note = create_test_delivery_note() delivery_note.submit() diff --git a/erpnext/stock/doctype/shipment_parcel_template/test_shipment_parcel_template.py b/erpnext/stock/doctype/shipment_parcel_template/test_shipment_parcel_template.py index 81f8f4393bc..04c1403cb30 100644 --- a/erpnext/stock/doctype/shipment_parcel_template/test_shipment_parcel_template.py +++ b/erpnext/stock/doctype/shipment_parcel_template/test_shipment_parcel_template.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestShipmentParcelTemplate(IntegrationTestCase): +class TestShipmentParcelTemplate(ERPNextTestSuite): pass diff --git a/erpnext/stock/doctype/stock_closing_balance/test_stock_closing_balance.py b/erpnext/stock/doctype/stock_closing_balance/test_stock_closing_balance.py index 8e09d518f3f..e60ffc118fa 100644 --- a/erpnext/stock/doctype/stock_closing_balance/test_stock_closing_balance.py +++ b/erpnext/stock/doctype/stock_closing_balance/test_stock_closing_balance.py @@ -2,16 +2,14 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -# On IntegrationTestCase, the doctype test records and all +# On ERPNextTestSuite, the doctype test records and all # link-field test record depdendencies are recursively loaded # Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -class IntegrationTestStockClosingBalance(IntegrationTestCase): +class TestStockClosingBalance(ERPNextTestSuite): """ Integration tests for StockClosingBalance. Use this class for testing interactions between multiple components. diff --git a/erpnext/stock/doctype/stock_closing_entry/test_stock_closing_entry.py b/erpnext/stock/doctype/stock_closing_entry/test_stock_closing_entry.py index 2a2f0eb86b7..91d3f3d7b34 100644 --- a/erpnext/stock/doctype/stock_closing_entry/test_stock_closing_entry.py +++ b/erpnext/stock/doctype/stock_closing_entry/test_stock_closing_entry.py @@ -2,16 +2,15 @@ # See license.txt # import frappe -from frappe.tests import IntegrationTestCase -# On IntegrationTestCase, the doctype test records and all +from erpnext.tests.utils import ERPNextTestSuite + +# On ERPNextTestSuite, the doctype test records and all # link-field test record depdendencies are recursively loaded # Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -class IntegrationTestStockClosingEntry(IntegrationTestCase): +class TestStockClosingEntry(ERPNextTestSuite): """ Integration tests for StockClosingEntry. Use this class for testing interactions between multiple components. diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 583cb4bedc6..5d8ebdda56f 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -3,7 +3,6 @@ from frappe.permissions import add_user_permission, remove_user_permission -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, cstr, flt, get_time, getdate, nowtime, today from erpnext.accounts.doctype.account.test_account import get_inventory_account @@ -38,6 +37,7 @@ from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ) from erpnext.stock.serial_batch_bundle import SerialBatchCreation from erpnext.stock.stock_ledger import NegativeStockError, get_previous_sle +from erpnext.tests.utils import ERPNextTestSuite def get_sle(**args): @@ -56,10 +56,10 @@ def get_sle(**args): ) -class TestStockEntry(IntegrationTestCase): - def tearDown(self): - frappe.db.rollback() - frappe.set_user("Administrator") +class TestStockEntry(ERPNextTestSuite): + def setUp(self): + self.load_test_records("Stock Entry") + frappe.local.flags.dont_execute_stock_reposts = False def test_stock_entry_qty(self): item_code = "_Test Item 2" @@ -649,6 +649,7 @@ class TestStockEntry(IntegrationTestCase): doc = frappe.new_doc("Serial No") doc.serial_no = serial_no doc.item_code = "_Test Serialized Item" + doc.company = "_Test Company" doc.insert(ignore_permissions=True) se = frappe.copy_doc(self.globalTestRecords["Stock Entry"][0]) @@ -866,7 +867,7 @@ class TestStockEntry(IntegrationTestCase): fg_cost = next(filter(lambda x: x.item_code == "_Test FG Item 2", stock_entry.get("items"))).amount self.assertEqual(fg_cost, flt(rm_cost + bom_operation_cost + work_order.additional_operating_cost, 2)) - @IntegrationTestCase.change_settings("Manufacturing Settings", {"material_consumption": 1}) + @ERPNextTestSuite.change_settings("Manufacturing Settings", {"material_consumption": 1}) def test_work_order_manufacture_with_material_consumption(self): from erpnext.manufacturing.doctype.work_order.work_order import ( make_stock_entry as _make_stock_entry, @@ -1293,7 +1294,7 @@ class TestStockEntry(IntegrationTestCase): self.assertEqual(se.items[0].expense_account, "_Test Account Cost for Goods Sold - _TC") self.assertEqual(se.items[1].expense_account, "_Test Account Cost for Goods Sold - _TC") - @IntegrationTestCase.change_settings("Stock Settings", {"allow_negative_stock": 0}) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_negative_stock": 0}) def test_future_negative_sle(self): # Initialize item, batch, warehouse, opening qty item_code = "_Test Future Neg Item" @@ -1336,7 +1337,7 @@ class TestStockEntry(IntegrationTestCase): self.assertRaises(NegativeStockError, create_stock_entries, sequence_of_entries) - @IntegrationTestCase.change_settings("Stock Settings", {"allow_negative_stock": 0}) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_negative_stock": 0}) def test_future_negative_sle_batch(self): from erpnext.stock.doctype.batch.test_batch import TestBatch @@ -1464,7 +1465,7 @@ class TestStockEntry(IntegrationTestCase): self.assertEqual(se.items[0].item_name, item.item_name) self.assertEqual(se.items[0].stock_uom, item.stock_uom) - @IntegrationTestCase.change_settings("Stock Reposting Settings", {"item_based_reposting": 0}) + @ERPNextTestSuite.change_settings("Stock Reposting Settings", {"item_based_reposting": 0}) def test_reposting_for_depedent_warehouse(self): from erpnext.stock.doctype.repost_item_valuation.repost_item_valuation import repost_sl_entries from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse @@ -2042,6 +2043,7 @@ class TestStockEntry(IntegrationTestCase): "abbr": "_TPC", "default_currency": "INR", "enable_perpetual_inventory": 0, + "country": "India", } ).insert(ignore_permissions=True) @@ -2326,7 +2328,7 @@ class TestStockEntry(IntegrationTestCase): se.save() se.submit() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", {"sample_retention_warehouse": "_Test Warehouse 1 - _TC"} ) def test_sample_retention_stock_entry(self): @@ -2366,10 +2368,8 @@ class TestStockEntry(IntegrationTestCase): self.assertEqual(target_sabb.entries[0].batch_no, batch) self.assertEqual([entry.serial_no for entry in target_sabb.entries], serial_nos[:2]) + @ERPNextTestSuite.change_settings("Manufacturing Settings", {"material_consumption": 0}) def test_raw_material_missing_validation(self): - original_value = frappe.db.get_single_value("Manufacturing Settings", "material_consumption") - frappe.db.set_single_value("Manufacturing Settings", "material_consumption", 0) - stock_entry = make_stock_entry( item_code="_Test Item", qty=1, @@ -2386,9 +2386,7 @@ class TestStockEntry(IntegrationTestCase): stock_entry.save, ) - frappe.db.set_single_value("Manufacturing Settings", "material_consumption", original_value) - - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Manufacturing Settings", { "material_consumption": 1, @@ -2405,10 +2403,14 @@ class TestStockEntry(IntegrationTestCase): rm_item1 = make_item("_Battery", properties={"is_stock_item": 1}).name warehouse = "Stores - WP" bom_no = make_bom(item=fg_item, raw_materials=[rm_item1]).name - make_stock_entry(item_code=rm_item1, target=warehouse, qty=5, rate=10, purpose="Material Receipt") + se = make_stock_entry( + item_code=rm_item1, target=warehouse, qty=5, rate=10, purpose="Material Receipt" + ) work_order = make_work_order(bom_no, fg_item, 5) + work_order.company = se.company work_order.skip_transfer = 1 + work_order.source_warehouse = warehouse work_order.fg_warehouse = warehouse work_order.submit() diff --git a/erpnext/stock/doctype/stock_entry_type/test_stock_entry_type.py b/erpnext/stock/doctype/stock_entry_type/test_stock_entry_type.py index 2ffeaed47f5..5b661957d0b 100644 --- a/erpnext/stock/doctype/stock_entry_type/test_stock_entry_type.py +++ b/erpnext/stock/doctype/stock_entry_type/test_stock_entry_type.py @@ -3,10 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestStockEntryType(IntegrationTestCase): +class TestStockEntryType(ERPNextTestSuite): def test_stock_entry_type_non_standard(self): stock_entry_type = "Test Manufacturing" diff --git a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py index c0ea44c59d5..8f4b39dd5b8 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py @@ -9,7 +9,6 @@ import frappe from frappe.core.page.permission_manager.permission_manager import reset from frappe.custom.doctype.property_setter.property_setter import make_property_setter from frappe.query_builder.functions import Timestamp -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, add_to_date, flt, today from erpnext.accounts.doctype.gl_entry.gl_entry import rename_gle_sle_docs @@ -29,9 +28,10 @@ from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ) from erpnext.stock.stock_ledger import get_previous_sle from erpnext.stock.tests.test_utils import StockTestMixin +from erpnext.tests.utils import ERPNextTestSuite -class TestStockLedgerEntry(IntegrationTestCase, StockTestMixin): +class TestStockLedgerEntry(ERPNextTestSuite, StockTestMixin): def setUp(self): items = create_items() reset("Stock Entry") @@ -45,9 +45,6 @@ class TestStockLedgerEntry(IntegrationTestCase, StockTestMixin): "delete from `tabBin` where item_code in (%s)" % (", ".join(["%s"] * len(items))), items ) - def tearDown(self): - frappe.db.rollback() - def test_item_cost_reposting(self): company = "_Test Company" @@ -1256,7 +1253,7 @@ class TestStockLedgerEntry(IntegrationTestCase, StockTestMixin): self.assertEqual(sle[0].qty_after_transaction, 105) self.assertEqual(sle[0].actual_qty, 100) - @IntegrationTestCase.change_settings("System Settings", {"float_precision": 3, "currency_precision": 2}) + @ERPNextTestSuite.change_settings("System Settings", {"float_precision": 3, "currency_precision": 2}) def test_transfer_invariants(self): """Extact stock value should be transferred.""" @@ -1295,7 +1292,7 @@ class TestStockLedgerEntry(IntegrationTestCase, StockTestMixin): ) self.assertEqual(abs(sles[0].stock_value_difference), sles[1].stock_value_difference) - @IntegrationTestCase.change_settings("System Settings", {"float_precision": 4}) + @ERPNextTestSuite.change_settings("System Settings", {"float_precision": 4}) def test_negative_qty_with_precision(self): "Test if system precision is respected while validating negative qty." from erpnext.stock.doctype.item.test_item import create_item @@ -1335,7 +1332,7 @@ class TestStockLedgerEntry(IntegrationTestCase, StockTestMixin): self.assertEqual(flt(get_stock_balance(item_code, warehouse), 3), 0.000) - @IntegrationTestCase.change_settings("System Settings", {"float_precision": 4}) + @ERPNextTestSuite.change_settings("System Settings", {"float_precision": 4}) def test_future_negative_qty_with_precision(self): """ Ledger: @@ -1591,81 +1588,3 @@ def get_unique_suffix(): # Used to isolate valuation sensitive # tests to prevent future tests from failing. return str(uuid4())[:8].upper() - - -class TestDeferredNaming(IntegrationTestCase): - @classmethod - def setUpClass(cls) -> None: - super().setUpClass() - cls.gle_autoname = frappe.get_meta("GL Entry").autoname - cls.sle_autoname = frappe.get_meta("Stock Ledger Entry").autoname - - def setUp(self) -> None: - self.item = make_item().name - self.warehouse = "Stores - TCP1" - self.company = "_Test Company with perpetual inventory" - - def tearDown(self) -> None: - make_property_setter( - doctype="GL Entry", - for_doctype=True, - property="autoname", - value=self.gle_autoname, - property_type="Data", - fieldname=None, - ) - make_property_setter( - doctype="Stock Ledger Entry", - for_doctype=True, - property="autoname", - value=self.sle_autoname, - property_type="Data", - fieldname=None, - ) - - # since deferred naming autocommits, commit all changes to avoid flake - frappe.db.commit() # nosemgrep - - @staticmethod - def get_gle_sles(se): - filters = {"voucher_type": se.doctype, "voucher_no": se.name} - gle = set(frappe.get_list("GL Entry", filters, pluck="name")) - sle = set(frappe.get_list("Stock Ledger Entry", filters, pluck="name")) - return gle, sle - - def test_deferred_naming(self): - se = make_stock_entry( - item_code=self.item, to_warehouse=self.warehouse, qty=10, rate=100, company=self.company - ) - - gle, sle = self.get_gle_sles(se) - rename_gle_sle_docs() - renamed_gle, renamed_sle = self.get_gle_sles(se) - - self.assertFalse(gle & renamed_gle, msg="GLEs not renamed") - self.assertFalse(sle & renamed_sle, msg="SLEs not renamed") - se.cancel() - - def test_hash_naming(self): - # disable naming series - for doctype in ("GL Entry", "Stock Ledger Entry"): - make_property_setter( - doctype=doctype, - for_doctype=True, - property="autoname", - value="hash", - property_type="Data", - fieldname=None, - ) - - se = make_stock_entry( - item_code=self.item, to_warehouse=self.warehouse, qty=10, rate=100, company=self.company - ) - - gle, sle = self.get_gle_sles(se) - rename_gle_sle_docs() - renamed_gle, renamed_sle = self.get_gle_sles(se) - - self.assertEqual(gle, renamed_gle, msg="GLEs are renamed while using hash naming") - self.assertEqual(sle, renamed_sle, msg="SLEs are renamed while using hash naming") - se.cancel() diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index 113d211320c..8d3b574fe50 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -241,6 +241,7 @@ class StockReconciliation(StockController): serial_and_batch_bundle = frappe.get_doc( { "doctype": "Serial and Batch Bundle", + "company": self.company, "item_code": item.item_code, "warehouse": item.warehouse, "posting_datetime": combine_datetime(self.posting_date, self.posting_time), diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index 4b3d9099afc..e0fc0ba6d11 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -7,7 +7,6 @@ import json import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, cstr, flt, nowdate, nowtime from erpnext.accounts.utils import get_stock_and_account_balance @@ -31,16 +30,12 @@ from erpnext.stock.utils import ( get_stock_value_on, get_valuation_method, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestStockReconciliation(IntegrationTestCase, StockTestMixin): - @classmethod - def setUpClass(cls): - create_batch_or_serial_no_items() - super().setUpClass() +class TestStockReconciliation(ERPNextTestSuite, StockTestMixin): + def setUp(self): frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1) - - def tearDown(self): frappe.local.future_sle = {} frappe.flags.pop("dont_execute_stock_reposts", None) @@ -50,7 +45,7 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin): def test_reco_for_moving_average(self): self._test_reco_sle_gle("Moving Average") - @IntegrationTestCase.change_settings("Stock Settings", {"allow_negative_stock": 1}) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_negative_stock": 1}) def _test_reco_sle_gle(self, valuation_method): item_code = self.make_item(properties={"valuation_method": valuation_method}).name @@ -423,7 +418,7 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin): assertBalance(pr2, 11) assertBalance(sr4, 6) # check if future stock reco is unaffected - @IntegrationTestCase.change_settings("Stock Settings", {"allow_negative_stock": 0}) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_negative_stock": 0}) def test_backdated_stock_reco_future_negative_stock(self): """ Test if a backdated stock reco causes future negative stock and is blocked. @@ -472,7 +467,7 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin): dn2.cancel() pr1.cancel() - @IntegrationTestCase.change_settings("Stock Settings", {"allow_negative_stock": 0}) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_negative_stock": 0}) def test_backdated_stock_reco_cancellation_future_negative_stock(self): """ Test if a backdated stock reco cancellation that causes future negative stock is blocked. @@ -525,8 +520,6 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin): """ from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note - frappe.db.rollback() - # repost will make this test useless, qty should update in realtime without reposts frappe.flags.dont_execute_stock_reposts = True @@ -552,7 +545,6 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin): ) self.assertEqual(old_bin_qty + 1, new_bin_qty) - frappe.db.rollback() def test_valid_batch(self): create_batch_item_with_batch("Testing Batch Item 1", "001") @@ -620,6 +612,7 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin): "doctype": "Serial No", "item_code": item_code, "serial_no": "SR-CREATED-SR-NO", + "company": "_Test Company", } ).insert() @@ -678,7 +671,7 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin): self.assertEqual(flt(sl_entry.actual_qty), 1.0) self.assertEqual(flt(sl_entry.qty_after_transaction), 1.0) - @IntegrationTestCase.change_settings("Stock Reposting Settings", {"item_based_reposting": 0}) + @ERPNextTestSuite.change_settings("Stock Reposting Settings", {"item_based_reposting": 0}) def test_backdated_stock_reco_entry(self): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry @@ -1851,37 +1844,6 @@ def insert_existing_sle(warehouse, item_code="_Test Item"): return se1, se2, se3 -def create_batch_or_serial_no_items(): - create_warehouse( - "_Test Warehouse for Stock Reco1", - {"is_group": 0, "parent_warehouse": "_Test Warehouse Group - _TC"}, - ) - - create_warehouse( - "_Test Warehouse for Stock Reco2", - {"is_group": 0, "parent_warehouse": "_Test Warehouse Group - _TC"}, - ) - - serial_item_doc = create_item("Stock-Reco-Serial-Item-1", is_stock_item=1) - if not serial_item_doc.has_serial_no: - serial_item_doc.has_serial_no = 1 - serial_item_doc.serial_no_series = "SRSI.####" - serial_item_doc.save(ignore_permissions=True) - - serial_item_doc = create_item("Stock-Reco-Serial-Item-2", is_stock_item=1) - if not serial_item_doc.has_serial_no: - serial_item_doc.has_serial_no = 1 - serial_item_doc.serial_no_series = "SRSII.####" - serial_item_doc.save(ignore_permissions=True) - - batch_item_doc = create_item("Stock-Reco-batch-Item-1", is_stock_item=1) - if not batch_item_doc.has_batch_no: - batch_item_doc.has_batch_no = 1 - batch_item_doc.create_new_batch = 1 - serial_item_doc.batch_number_series = "BASR.#####" - batch_item_doc.save(ignore_permissions=True) - - def create_stock_reconciliation(**args): args = frappe._dict(args) sr = frappe.new_doc("Stock Reconciliation") @@ -1976,6 +1938,3 @@ def set_valuation_method(item_code, valuation_method): update_entries_after( {"item_code": item_code, "warehouse": warehouse.name}, allow_negative_stock=1 ) - - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Item", "Warehouse"] diff --git a/erpnext/stock/doctype/stock_reposting_settings/test_stock_reposting_settings.py b/erpnext/stock/doctype/stock_reposting_settings/test_stock_reposting_settings.py index 74cf9f08b77..ff89ad34ab6 100644 --- a/erpnext/stock/doctype/stock_reposting_settings/test_stock_reposting_settings.py +++ b/erpnext/stock/doctype/stock_reposting_settings/test_stock_reposting_settings.py @@ -3,12 +3,12 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.stock.doctype.repost_item_valuation.repost_item_valuation import get_recipients +from erpnext.tests.utils import ERPNextTestSuite -class TestStockRepostingSettings(IntegrationTestCase): +class TestStockRepostingSettings(ERPNextTestSuite): def test_notify_reposting_error_to_role(self): role = "Notify Reposting Role" diff --git a/erpnext/stock/doctype/stock_reservation_entry/test_stock_reservation_entry.py b/erpnext/stock/doctype/stock_reservation_entry/test_stock_reservation_entry.py index aa49726374a..3f33b0a2da8 100644 --- a/erpnext/stock/doctype/stock_reservation_entry/test_stock_reservation_entry.py +++ b/erpnext/stock/doctype/stock_reservation_entry/test_stock_reservation_entry.py @@ -4,8 +4,7 @@ from random import randint import frappe -from frappe.tests import IntegrationTestCase -from frappe.utils import cint, today +from frappe.utils import today from erpnext.selling.doctype.sales_order.sales_order import create_pick_list, make_delivery_note from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order @@ -19,15 +18,16 @@ from erpnext.stock.doctype.stock_reservation_entry.stock_reservation_entry impor has_reserved_stock, ) from erpnext.stock.utils import get_stock_balance +from erpnext.tests.utils import ERPNextTestSuite -class TestStockReservationEntry(IntegrationTestCase): +class TestStockReservationEntry(ERPNextTestSuite): def setUp(self) -> None: self.warehouse = "_Test Warehouse - _TC" self.sr_item = make_item(properties={"is_stock_item": 1, "valuation_rate": 100}) create_material_receipt(items={self.sr_item.name: self.sr_item}, warehouse=self.warehouse, qty=100) - @IntegrationTestCase.change_settings("Stock Settings", {"allow_negative_stock": 0}) + @ERPNextTestSuite.change_settings("Stock Settings", {"allow_negative_stock": 0}) def test_validate_stock_reservation_settings(self) -> None: from erpnext.stock.doctype.stock_reservation_entry.stock_reservation_entry import ( validate_stock_reservation_settings, @@ -120,7 +120,7 @@ class TestStockReservationEntry(IntegrationTestCase): sre.load_from_db() self.assertEqual(sre.status, "Cancelled") - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", {"allow_negative_stock": 0, "enable_stock_reservation": 1} ) def test_update_reserved_qty_in_voucher(self) -> None: @@ -189,7 +189,7 @@ class TestStockReservationEntry(IntegrationTestCase): self.assertEqual(sre1.status, "Cancelled") self.assertEqual(so.items[0].stock_reserved_qty, 0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", {"allow_negative_stock": 0, "enable_stock_reservation": 1} ) def test_cant_consume_reserved_stock(self) -> None: @@ -239,7 +239,7 @@ class TestStockReservationEntry(IntegrationTestCase): se.submit() se.cancel() - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", { "allow_negative_stock": 0, @@ -382,7 +382,7 @@ class TestStockReservationEntry(IntegrationTestCase): for sre_detail in sre_details: self.assertEqual(sre_detail.reserved_qty, sre_detail.delivered_qty) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", { "allow_negative_stock": 0, @@ -502,7 +502,7 @@ class TestStockReservationEntry(IntegrationTestCase): # Test - 9: After Delivery Note cancellation, SB Entry Delivered Qty should be `0`. self.assertEqual(sb_entry.delivered_qty, 0) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", { "allow_negative_stock": 0, @@ -583,7 +583,7 @@ class TestStockReservationEntry(IntegrationTestCase): # Test - 3: Reserved Serial/Batch Nos should be equal to Picked Serial/Batch Nos. self.assertSetEqual(picked_sb_details, reserved_sb_details) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", { "allow_negative_stock": 0, @@ -663,7 +663,7 @@ class TestStockReservationEntry(IntegrationTestCase): # Test - 3: Reserved Serial/Batch Nos should be equal to PR Item Serial/Batch Nos. self.assertEqual(set(sb_details), set(reserved_sb_details)) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", { "allow_negative_stock": 0, @@ -697,10 +697,6 @@ class TestStockReservationEntry(IntegrationTestCase): # Test - 1: ValidationError should be thrown as the inwarded stock is reserved. self.assertRaises(frappe.ValidationError, se.cancel) - def tearDown(self) -> None: - cancel_all_stock_reservation_entries() - return super().tearDown() - def create_items() -> dict: items_properties = [ diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.py b/erpnext/stock/doctype/stock_settings/stock_settings.py index dc92bfc8289..f2d54794094 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.py +++ b/erpnext/stock/doctype/stock_settings/stock_settings.py @@ -353,8 +353,8 @@ def clean_all_descriptions(): for item in frappe.get_all("Item", ["name", "description"]): if item.description: clean_description = clean_html(item.description) - if item.description != clean_description: - frappe.db.set_value("Item", item.name, "description", clean_description) + if item.description != clean_description: + frappe.db.set_value("Item", item.name, "description", clean_description) @frappe.whitelist() diff --git a/erpnext/stock/doctype/stock_settings/test_stock_settings.py b/erpnext/stock/doctype/stock_settings/test_stock_settings.py index 18c523f9998..112fa52401d 100644 --- a/erpnext/stock/doctype/stock_settings/test_stock_settings.py +++ b/erpnext/stock/doctype/stock_settings/test_stock_settings.py @@ -3,10 +3,11 @@ import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestStockSettings(IntegrationTestCase): +class TestStockSettings(ERPNextTestSuite): def setUp(self): super().setUp() frappe.db.set_single_value("Stock Settings", "clean_description_html", 0) diff --git a/erpnext/stock/doctype/uom_category/test_uom_category.py b/erpnext/stock/doctype/uom_category/test_uom_category.py index ebd2b5644c0..e664222da43 100644 --- a/erpnext/stock/doctype/uom_category/test_uom_category.py +++ b/erpnext/stock/doctype/uom_category/test_uom_category.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestUOMCategory(IntegrationTestCase): +class TestUOMCategory(ERPNextTestSuite): pass diff --git a/erpnext/stock/doctype/variant_field/test_variant_field.py b/erpnext/stock/doctype/variant_field/test_variant_field.py index ab35caf96b8..c63f8f1702b 100644 --- a/erpnext/stock/doctype/variant_field/test_variant_field.py +++ b/erpnext/stock/doctype/variant_field/test_variant_field.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestVariantField(IntegrationTestCase): +class TestVariantField(ERPNextTestSuite): pass diff --git a/erpnext/stock/doctype/warehouse/test_records.json b/erpnext/stock/doctype/warehouse/test_records.json deleted file mode 100644 index e128558ed3b..00000000000 --- a/erpnext/stock/doctype/warehouse/test_records.json +++ /dev/null @@ -1,64 +0,0 @@ -[ - { - "company": "_Test Company", - "doctype": "Warehouse", - "warehouse_name": "_Test Warehouse", - "is_group": 0 - }, - { - "company": "_Test Company", - "doctype": "Warehouse", - "warehouse_name": "_Test Scrap Warehouse", - "is_group": 0 - }, - { - "company": "_Test Company", - "doctype": "Warehouse", - "warehouse_name": "_Test Warehouse 1", - "is_group": 0 - }, - { - "company": "_Test Company", - "doctype": "Warehouse", - "warehouse_name": "_Test Warehouse 2", - "is_group": 0 - }, - { - "company": "_Test Company", - "doctype": "Warehouse", - "warehouse_name": "_Test Rejected Warehouse", - "is_group": 0 - }, - { - "company": "_Test Company 1", - "doctype": "Warehouse", - "warehouse_name": "_Test Warehouse 2", - "is_group": 0 - }, - { - "company": "_Test Company", - "doctype": "Warehouse", - "warehouse_name": "_Test Warehouse No Account", - "is_group": 0 - }, - { - "company": "_Test Company", - "doctype": "Warehouse", - "warehouse_name": "_Test Warehouse Group", - "is_group": 1 - }, - { - "company": "_Test Company", - "doctype": "Warehouse", - "warehouse_name": "_Test Warehouse Group-C1", - "is_group": 0, - "parent_warehouse": "_Test Warehouse Group - _TC" - }, - { - "company": "_Test Company", - "doctype": "Warehouse", - "warehouse_name": "_Test Warehouse Group-C2", - "is_group": 0, - "parent_warehouse": "_Test Warehouse Group - _TC" - } -] diff --git a/erpnext/stock/doctype/warehouse/test_warehouse.py b/erpnext/stock/doctype/warehouse/test_warehouse.py index fc5feff5812..5a36d5c213e 100644 --- a/erpnext/stock/doctype/warehouse/test_warehouse.py +++ b/erpnext/stock/doctype/warehouse/test_warehouse.py @@ -2,16 +2,16 @@ # License: GNU General Public License v3. See license.txt import frappe -from frappe.tests import IntegrationTestCase import erpnext from erpnext.accounts.doctype.account.test_account import create_account from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.doctype.warehouse.warehouse import convert_to_group_or_ledger, get_children +from erpnext.tests.utils import ERPNextTestSuite -class TestWarehouse(IntegrationTestCase): +class TestWarehouse(ERPNextTestSuite): def test_parent_warehouse(self): parent_warehouse = frappe.get_doc("Warehouse", "_Test Warehouse Group - _TC") self.assertEqual(parent_warehouse.is_group, 1) diff --git a/erpnext/stock/doctype/warehouse_type/test_warehouse_type.py b/erpnext/stock/doctype/warehouse_type/test_warehouse_type.py index 4afa82219cb..ce06e4356e2 100644 --- a/erpnext/stock/doctype/warehouse_type/test_warehouse_type.py +++ b/erpnext/stock/doctype/warehouse_type/test_warehouse_type.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestWarehouseType(IntegrationTestCase): +class TestWarehouseType(ERPNextTestSuite): pass diff --git a/erpnext/stock/report/available_serial_no/test_available_serial_no.py b/erpnext/stock/report/available_serial_no/test_available_serial_no.py index b8741af4506..e9f478960d2 100644 --- a/erpnext/stock/report/available_serial_no/test_available_serial_no.py +++ b/erpnext/stock/report/available_serial_no/test_available_serial_no.py @@ -2,15 +2,15 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, today from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt +from erpnext.tests.utils import ERPNextTestSuite -class TestStockLedgerReeport(IntegrationTestCase): +class TestStockLedgerReeport(ERPNextTestSuite): def setUp(self) -> None: item = create_item("_Test Item with Serial No", is_stock_item=1) item.has_serial_no = 1 @@ -24,9 +24,6 @@ class TestStockLedgerReeport(IntegrationTestCase): item_code="_Test Item With Serial No", ) - def tearDown(self) -> None: - frappe.db.rollback() - def test_available_serial_no(self): report = frappe.get_doc("Report", "Available Serial No") diff --git a/erpnext/stock/report/item_shortage_report/test_item_shortage_report.py b/erpnext/stock/report/item_shortage_report/test_item_shortage_report.py index 76549a14927..2a61fbf1f32 100644 --- a/erpnext/stock/report/item_shortage_report/test_item_shortage_report.py +++ b/erpnext/stock/report/item_shortage_report/test_item_shortage_report.py @@ -2,16 +2,16 @@ # For license information, please see license.txt import frappe -from frappe.tests import IntegrationTestCase from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.report.item_shortage_report.item_shortage_report import ( execute as item_shortage_report, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestItemShortageReport(IntegrationTestCase): +class TestItemShortageReport(ERPNextTestSuite): def test_item_shortage_report(self): item = make_item().name so = make_sales_order(item_code=item) diff --git a/erpnext/stock/report/reserved_stock/test_reserved_stock.py b/erpnext/stock/report/reserved_stock/test_reserved_stock.py index cf74df5c160..d7790bfe200 100644 --- a/erpnext/stock/report/reserved_stock/test_reserved_stock.py +++ b/erpnext/stock/report/reserved_stock/test_reserved_stock.py @@ -2,7 +2,6 @@ # See license.txt from random import randint -from frappe.tests import IntegrationTestCase from frappe.utils.data import today from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order @@ -12,19 +11,16 @@ from erpnext.stock.doctype.stock_reservation_entry.test_stock_reservation_entry create_material_receipt, ) from erpnext.stock.report.reserved_stock.reserved_stock import get_data as reserved_stock_report +from erpnext.tests.utils import ERPNextTestSuite -class TestReservedStock(IntegrationTestCase): +class TestReservedStock(ERPNextTestSuite): def setUp(self) -> None: super().setUp() self.stock_qty = 100 self.warehouse = "_Test Warehouse - _TC" - def tearDown(self) -> None: - cancel_all_stock_reservation_entries() - return super().tearDown() - - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings( "Stock Settings", { "allow_negative_stock": 0, diff --git a/erpnext/stock/report/stock_ageing/test_stock_ageing.py b/erpnext/stock/report/stock_ageing/test_stock_ageing.py index 52d8abf0c28..4e2e5ca9d88 100644 --- a/erpnext/stock/report/stock_ageing/test_stock_ageing.py +++ b/erpnext/stock/report/stock_ageing/test_stock_ageing.py @@ -2,12 +2,12 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from erpnext.stock.report.stock_ageing.stock_ageing import FIFOSlots, format_report_data +from erpnext.tests.utils import ERPNextTestSuite -class TestStockAgeing(IntegrationTestCase): +class TestStockAgeing(ERPNextTestSuite): def setUp(self) -> None: self.filters = frappe._dict(company="_Test Company", to_date="2021-12-10", ranges=["30", "60", "90"]) diff --git a/erpnext/stock/report/stock_analytics/test_stock_analytics.py b/erpnext/stock/report/stock_analytics/test_stock_analytics.py index 70be5cf4e81..5603a3a111c 100644 --- a/erpnext/stock/report/stock_analytics/test_stock_analytics.py +++ b/erpnext/stock/report/stock_analytics/test_stock_analytics.py @@ -2,13 +2,13 @@ import datetime import frappe from frappe import _dict -from frappe.tests import IntegrationTestCase from frappe.utils.data import add_to_date, getdate from erpnext.accounts.utils import get_fiscal_year from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.report.stock_analytics.stock_analytics import execute, get_period_date_ranges +from erpnext.tests.utils import ERPNextTestSuite def stock_analytics(filters): @@ -16,7 +16,7 @@ def stock_analytics(filters): return col, data -class TestStockAnalyticsReport(IntegrationTestCase): +class TestStockAnalyticsReport(ERPNextTestSuite): def setUp(self) -> None: self.item = make_item().name self.warehouse = "_Test Warehouse - _TC" diff --git a/erpnext/stock/report/stock_balance/test_stock_balance.py b/erpnext/stock/report/stock_balance/test_stock_balance.py index a0176026c48..583e362112c 100644 --- a/erpnext/stock/report/stock_balance/test_stock_balance.py +++ b/erpnext/stock/report/stock_balance/test_stock_balance.py @@ -2,12 +2,12 @@ from typing import Any import frappe from frappe import _dict -from frappe.tests import IntegrationTestCase from frappe.utils import today from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.report.stock_balance.stock_balance import execute +from erpnext.tests.utils import ERPNextTestSuite def stock_balance(filters): @@ -15,7 +15,7 @@ def stock_balance(filters): return [_dict(row) for row in execute(filters)[1]] -class TestStockBalance(IntegrationTestCase): +class TestStockBalance(ERPNextTestSuite): # ----------- utils def setUp(self): @@ -29,9 +29,6 @@ class TestStockBalance(IntegrationTestCase): } ) - def tearDown(self): - frappe.db.rollback() - def assertPartialDictEq(self, expected: dict[str, Any], actual: dict[str, Any]): for k, v in expected.items(): self.assertEqual(v, actual[k], msg=f"{expected=}\n{actual=}") @@ -106,6 +103,7 @@ class TestStockBalance(IntegrationTestCase): ) self.assertInvariants(rows) + @ERPNextTestSuite.change_settings("System Settings", {"float_precision": 3, "currency_precision": 3}) def test_opening_balance(self): self.generate_stock_ledger( self.item.name, diff --git a/erpnext/stock/report/stock_ledger/test_stock_ledger_report.py b/erpnext/stock/report/stock_ledger/test_stock_ledger_report.py index 66e7560caa6..8a97a64d1b3 100644 --- a/erpnext/stock/report/stock_ledger/test_stock_ledger_report.py +++ b/erpnext/stock/report/stock_ledger/test_stock_ledger_report.py @@ -2,15 +2,15 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, today from erpnext.maintenance.doctype.maintenance_schedule.test_maintenance_schedule import ( make_serial_item_with_serial, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestStockLedgerReeport(IntegrationTestCase): +class TestStockLedgerReeport(ERPNextTestSuite): def setUp(self) -> None: make_serial_item_with_serial(self, "_Test Stock Report Serial Item") self.filters = frappe._dict( @@ -19,6 +19,3 @@ class TestStockLedgerReeport(IntegrationTestCase): to_date=add_days(today(), 30), item_code=["_Test Stock Report Serial Item"], ) - - def tearDown(self) -> None: - frappe.db.rollback() diff --git a/erpnext/stock/report/test_reports.py b/erpnext/stock/report/test_reports.py index 986c1404cbe..5f8aa9a32ea 100644 --- a/erpnext/stock/report/test_reports.py +++ b/erpnext/stock/report/test_reports.py @@ -1,10 +1,6 @@ -import unittest - -import frappe -from frappe.tests import IntegrationTestCase from frappe.utils.make_random import get_random -from erpnext.tests.utils import ReportFilters, ReportName, execute_script_report +from erpnext.tests.utils import ERPNextTestSuite, ReportFilters, ReportName, execute_script_report DEFAULT_FILTERS = { "company": "_Test Company", @@ -84,7 +80,7 @@ OPTIONAL_FILTERS = { } -class TestReports(IntegrationTestCase): +class TestReports(ERPNextTestSuite): def test_execute_all_stock_reports(self): """Test that all script report in stock modules are executable with supported filters""" for report, filter in REPORT_FILTER_TEST_CASES: diff --git a/erpnext/stock/tests/test_get_item_details.py b/erpnext/stock/tests/test_get_item_details.py index e0f32402d85..fdc563064ec 100644 --- a/erpnext/stock/tests/test_get_item_details.py +++ b/erpnext/stock/tests/test_get_item_details.py @@ -1,12 +1,10 @@ import frappe -from frappe.tests import IntegrationTestCase from erpnext.stock.get_item_details import get_item_details - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Customer", "Supplier", "Item", "Price List", "Item Price"] +from erpnext.tests.utils import ERPNextTestSuite -class TestGetItemDetail(IntegrationTestCase): +class TestGetItemDetail(ERPNextTestSuite): def test_get_item_detail_purchase_order(self): args = frappe._dict( { diff --git a/erpnext/stock/tests/test_utils.py b/erpnext/stock/tests/test_utils.py index 085d3d41cbe..dfbe6d24806 100644 --- a/erpnext/stock/tests/test_utils.py +++ b/erpnext/stock/tests/test_utils.py @@ -2,9 +2,9 @@ import json import frappe from frappe.query_builder.functions import Timestamp -from frappe.tests import IntegrationTestCase from erpnext.stock.utils import scan_barcode +from erpnext.tests.utils import ERPNextTestSuite class StockTestMixin: @@ -70,7 +70,7 @@ class StockTestMixin: self.assertEqual(exp_value, act_value, msg=f"{k} doesn't match \n{exp_gle}\n{act_gle}") -class TestStockUtilities(IntegrationTestCase, StockTestMixin): +class TestStockUtilities(ERPNextTestSuite, StockTestMixin): def test_barcode_scanning(self): simple_item = self.make_item(properties={"barcodes": [{"barcode": "12399"}]}) self.assertEqual(scan_barcode("12399")["item_code"], simple_item.name) @@ -86,7 +86,10 @@ class TestStockUtilities(IntegrationTestCase, StockTestMixin): serial_item = self.make_item(properties={"has_serial_no": 1}) serial = frappe.get_doc( - doctype="Serial No", item_code=serial_item.name, serial_no=frappe.generate_hash() + doctype="Serial No", + item_code=serial_item.name, + serial_no=frappe.generate_hash(), + company="_Test Company", ).insert() serial_scan = scan_barcode(serial.name) diff --git a/erpnext/stock/tests/test_valuation.py b/erpnext/stock/tests/test_valuation.py index c5931c7b990..bfe511130c8 100644 --- a/erpnext/stock/tests/test_valuation.py +++ b/erpnext/stock/tests/test_valuation.py @@ -2,28 +2,23 @@ import json import unittest import frappe -from frappe.tests import IntegrationTestCase from hypothesis import given from hypothesis import strategies as st from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.valuation import FIFOValuation, LIFOValuation, round_off_if_near_zero +from erpnext.tests.utils import ERPNextTestSuite qty_gen = st.floats(min_value=-1e6, max_value=1e6) value_gen = st.floats(min_value=1, max_value=1e6) stock_queue_generator = st.lists(st.tuples(qty_gen, value_gen), min_size=10) -class TestFIFOValuation(IntegrationTestCase): +class TestFIFOValuation(ERPNextTestSuite): def setUp(self): self.queue = FIFOValuation([]) - def tearDown(self): - qty, value = self.queue.get_total_stock_and_value() - self.assertTotalQty(qty) - self.assertTotalValue(value) - def assertTotalQty(self, qty): self.assertAlmostEqual(sum(q for q, _ in self.queue), qty, msg=f"queue: {self.queue}", places=4) @@ -195,15 +190,10 @@ class TestFIFOValuation(IntegrationTestCase): self.assertTotalValue(total_value) -class TestLIFOValuation(IntegrationTestCase): +class TestLIFOValuation(ERPNextTestSuite): def setUp(self): self.stack = LIFOValuation([]) - def tearDown(self): - qty, value = self.stack.get_total_stock_and_value() - self.assertTotalQty(qty) - self.assertTotalValue(value) - def assertTotalQty(self, qty): self.assertAlmostEqual(sum(q for q, _ in self.stack), qty, msg=f"stack: {self.stack}", places=4) @@ -317,14 +307,12 @@ class TestLIFOValuation(IntegrationTestCase): self.assertTotalValue(total_value) -class TestLIFOValuationSLE(IntegrationTestCase): +class TestLIFOValuationSLE(ERPNextTestSuite): ITEM_CODE = "_Test LIFO item" WAREHOUSE = "_Test Warehouse - _TC" - @classmethod - def setUpClass(cls) -> None: - super().setUpClass() - make_item(cls.ITEM_CODE, {"valuation_method": "LIFO"}) + def setUp(self) -> None: + make_item(self.ITEM_CODE, {"valuation_method": "LIFO"}) def _make_stock_entry(self, qty, rate=None): kwargs = { diff --git a/erpnext/subcontracting/doctype/subcontracting_bom/test_subcontracting_bom.py b/erpnext/subcontracting/doctype/subcontracting_bom/test_subcontracting_bom.py index a831211af93..d44603f9a0a 100644 --- a/erpnext/subcontracting/doctype/subcontracting_bom/test_subcontracting_bom.py +++ b/erpnext/subcontracting/doctype/subcontracting_bom/test_subcontracting_bom.py @@ -2,10 +2,11 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestSubcontractingBOM(IntegrationTestCase): +class TestSubcontractingBOM(ERPNextTestSuite): pass diff --git a/erpnext/subcontracting/doctype/subcontracting_inward_order/test_subcontracting_inward_order.py b/erpnext/subcontracting/doctype/subcontracting_inward_order/test_subcontracting_inward_order.py index 1d57660d6ef..9463b11bf4c 100644 --- a/erpnext/subcontracting/doctype/subcontracting_inward_order/test_subcontracting_inward_order.py +++ b/erpnext/subcontracting/doctype/subcontracting_inward_order/test_subcontracting_inward_order.py @@ -2,13 +2,6 @@ # See license.txt import frappe -from frappe.tests import IntegrationTestCase - -# On IntegrationTestCase, the doctype test records and all -# link-field test record dependencies are recursively loaded -# Use these module variables to add/remove to/from that list -EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] -IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] from erpnext.manufacturing.doctype.work_order.work_order import make_stock_entry as make_stock_entry_from_wo from erpnext.selling.doctype.sales_order.sales_order import make_subcontracting_inward_order @@ -16,9 +9,10 @@ from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_orde from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse +from erpnext.tests.utils import ERPNextTestSuite -class IntegrationTestSubcontractingInwardOrder(IntegrationTestCase): +class IntegrationTestSubcontractingInwardOrder(ERPNextTestSuite): """ Integration tests for SubcontractingInwardOrder. Use this class for testing interactions between multiple components. @@ -295,8 +289,8 @@ class IntegrationTestSubcontractingInwardOrder(IntegrationTestCase): self.assertEqual(scio.items[0].delivered_qty, 2) self.assertEqual(scio.items[0].returned_qty, 1) - @IntegrationTestCase.change_settings("Selling Settings", {"allow_delivery_of_overproduced_qty": 1}) - @IntegrationTestCase.change_settings( + @ERPNextTestSuite.change_settings("Selling Settings", {"allow_delivery_of_overproduced_qty": 1}) + @ERPNextTestSuite.change_settings( "Manufacturing Settings", {"overproduction_percentage_for_work_order": 20} ) def test_over_production_delivery(self): @@ -329,8 +323,8 @@ class IntegrationTestSubcontractingInwardOrder(IntegrationTestCase): delivery.items[0].qty = 6 self.assertRaises(frappe.ValidationError, delivery.submit) - @IntegrationTestCase.change_settings("Selling Settings", {"deliver_scrap_items": 1}) - def test_scrap_delivery(self): + @ERPNextTestSuite.change_settings("Selling Settings", {"deliver_scrap_items": 1}) + def test_secondary_items_delivery(self): new_bom = frappe.copy_doc(frappe.get_doc("BOM", "BOM-Basic FG Item-001")) new_bom.scrap_items.append(frappe.new_doc("BOM Scrap Item", item_code="Basic RM 2", qty=1)) new_bom.submit() diff --git a/erpnext/subcontracting/doctype/subcontracting_order/test_subcontracting_order.py b/erpnext/subcontracting/doctype/subcontracting_order/test_subcontracting_order.py index 363a9cdd565..f0803733d53 100644 --- a/erpnext/subcontracting/doctype/subcontracting_order/test_subcontracting_order.py +++ b/erpnext/subcontracting/doctype/subcontracting_order/test_subcontracting_order.py @@ -5,7 +5,6 @@ import copy from collections import defaultdict import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import flt from erpnext.buying.doctype.purchase_order.purchase_order import get_mapped_subcontracting_order @@ -31,9 +30,10 @@ from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry from erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order import ( make_subcontracting_receipt, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestSubcontractingOrder(IntegrationTestCase): +class TestSubcontractingOrder(ERPNextTestSuite): def setUp(self): make_subcontracted_items() make_raw_materials() @@ -460,6 +460,7 @@ class TestSubcontractingOrder(IntegrationTestCase): set_backflush_based_on("BOM") + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_multiple_items": True}) def test_supplied_qty(self): item_code = "_Test Subcontracted FG Item 5" make_item("Sub Contracted Raw Material 4", {"is_stock_item": 1, "is_sub_contracted_item": 1}) @@ -472,7 +473,7 @@ class TestSubcontractingOrder(IntegrationTestCase): service_items = [ { "warehouse": "_Test Warehouse - _TC", - "item_code": "Subcontracted Service Item 1", + "item_code": "Subcontracted Service Item 2", "qty": order_qty, "rate": 100, "fg_item": item_code, @@ -678,6 +679,7 @@ class TestSubcontractingOrder(IntegrationTestCase): self.assertEqual(requested_qty, new_requested_qty) + @ERPNextTestSuite.change_settings("System Settings", {"float_precision": 3}) def test_subcontracting_order_rm_required_items_for_precision(self): item_code = "Subcontracted Item SA9" raw_materials = ["Subcontracted SRM Item 9"] diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py b/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py index 489f2bf82cd..53466f7405d 100644 --- a/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py +++ b/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py @@ -5,7 +5,6 @@ import copy import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import add_days, cint, flt, nowtime, today import erpnext @@ -41,9 +40,10 @@ from erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order im from erpnext.subcontracting.doctype.subcontracting_receipt.subcontracting_receipt import ( BOMQuantityError, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestSubcontractingReceipt(IntegrationTestCase): +class TestSubcontractingReceipt(ERPNextTestSuite): def setUp(self): make_subcontracted_items() make_raw_materials() @@ -207,7 +207,7 @@ class TestSubcontractingReceipt(IntegrationTestCase): # stock raw materials in a warehouse before transfer make_stock_entry( - target="_Test Warehouse - _TC", item_code="Test Extra Item 1", qty=10, basic_rate=100 + target="_Test Warehouse - _TC", item_code="_Test Extra Item 1", qty=10, basic_rate=100 ) make_stock_entry(target="_Test Warehouse - _TC", item_code="_Test FG Item", qty=1, basic_rate=100) make_stock_entry(target="_Test Warehouse - _TC", item_code="Test Extra Item 2", qty=1, basic_rate=100) @@ -497,13 +497,13 @@ class TestSubcontractingReceipt(IntegrationTestCase): self.assertEqual(expected_values[gle.account][0], gle.debit) self.assertEqual(expected_values[gle.account][1], gle.credit) - @IntegrationTestCase.change_settings("Stock Settings", {"use_serial_batch_fields": 0}) + @ERPNextTestSuite.change_settings("Stock Settings", {"use_serial_batch_fields": 0}) def test_subcontracting_receipt_with_zero_service_cost(self): warehouse = "Stores - TCP1" service_items = [ { "warehouse": warehouse, - "item_code": "Subcontracted Service Item 7", + "item_code": "Subcontracted Service Item 6", "qty": 10, "rate": 0, "fg_item": "Subcontracted Item SA7", @@ -617,6 +617,7 @@ class TestSubcontractingReceipt(IntegrationTestCase): for item in scr.supplied_items: self.assertFalse(item.available_qty_for_consumption) + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_multiple_items": True}) def test_supplied_items_consumed_qty_for_similar_finished_goods(self): """ Test that supplied raw material consumption is calculated correctly @@ -1289,6 +1290,7 @@ class TestSubcontractingReceipt(IntegrationTestCase): serial_batch_bundle = frappe.get_doc( { "doctype": "Serial and Batch Bundle", + "company": sco.company, "item_code": fg_item, "warehouse": sco.items[0].warehouse, "has_batch_no": 1, @@ -1439,7 +1441,7 @@ class TestSubcontractingReceipt(IntegrationTestCase): sr.reload() self.assertEqual(sr.items[0].rejected_qty, 2) # Should remain the same - @IntegrationTestCase.change_settings("Buying Settings", {"auto_create_purchase_receipt": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"auto_create_purchase_receipt": 1}) def test_auto_create_purchase_receipt(self): from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order @@ -1503,7 +1505,7 @@ class TestSubcontractingReceipt(IntegrationTestCase): self.assertEqual(pr_details[0]["total_taxes_and_charges"], 60) - @IntegrationTestCase.change_settings("Buying Settings", {"auto_create_purchase_receipt": 1}) + @ERPNextTestSuite.change_settings("Buying Settings", {"auto_create_purchase_receipt": 1}) def test_auto_create_purchase_receipt_with_no_reference_of_po_item(self): from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order @@ -2001,8 +2003,8 @@ class TestSubcontractingReceipt(IntegrationTestCase): self.assertRaises(BOMQuantityError, scr.submit) - @IntegrationTestCase.change_settings("Buying Settings", {"over_transfer_allowance": 20}) - @IntegrationTestCase.change_settings("Stock Settings", {"over_delivery_receipt_allowance": 20}) + @ERPNextTestSuite.change_settings("Buying Settings", {"over_transfer_allowance": 20}) + @ERPNextTestSuite.change_settings("Stock Settings", {"over_delivery_receipt_allowance": 20}) def test_over_receipt(self): from erpnext.controllers.subcontracting_controller import make_rm_stock_entry diff --git a/erpnext/support/doctype/issue/test_issue.py b/erpnext/support/doctype/issue/test_issue.py index 92979839d1b..acb3869ce6b 100644 --- a/erpnext/support/doctype/issue/test_issue.py +++ b/erpnext/support/doctype/issue/test_issue.py @@ -5,15 +5,15 @@ import unittest import frappe from frappe import _ from frappe.core.doctype.user_permission.test_user_permission import create_user -from frappe.tests import IntegrationTestCase from frappe.utils import flt, get_datetime from erpnext.support.doctype.service_level_agreement.test_service_level_agreement import ( create_service_level_agreements_for_issues, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestSetUp(IntegrationTestCase): +class TestSetUp(ERPNextTestSuite): def setUp(self): frappe.db.sql("delete from `tabService Level Agreement`") frappe.db.sql("delete from `tabService Level Priority`") diff --git a/erpnext/support/doctype/issue_priority/test_issue_priority.py b/erpnext/support/doctype/issue_priority/test_issue_priority.py index 8a7140ff3cb..df844c54a16 100644 --- a/erpnext/support/doctype/issue_priority/test_issue_priority.py +++ b/erpnext/support/doctype/issue_priority/test_issue_priority.py @@ -3,10 +3,11 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestIssuePriority(IntegrationTestCase): +class TestIssuePriority(ERPNextTestSuite): def test_priorities(self): make_priorities() priorities = frappe.get_list("Issue Priority") diff --git a/erpnext/support/doctype/issue_type/test_issue_type.py b/erpnext/support/doctype/issue_type/test_issue_type.py index 6bdc647aa3a..276db1f3661 100644 --- a/erpnext/support/doctype/issue_type/test_issue_type.py +++ b/erpnext/support/doctype/issue_type/test_issue_type.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestIssueType(IntegrationTestCase): +class TestIssueType(ERPNextTestSuite): pass diff --git a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py index 988bd54e9f6..d7ada387f82 100644 --- a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py +++ b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py @@ -4,16 +4,16 @@ import datetime import unittest import frappe -from frappe.tests import IntegrationTestCase from frappe.utils import flt from erpnext.support.doctype.issue_priority.test_issue_priority import make_priorities from erpnext.support.doctype.service_level_agreement.service_level_agreement import ( get_service_level_agreement_fields, ) +from erpnext.tests.utils import ERPNextTestSuite -class TestServiceLevelAgreement(IntegrationTestCase): +class TestServiceLevelAgreement(ERPNextTestSuite): def setUp(self): self.create_company() frappe.db.set_single_value("Support Settings", "track_service_level_agreement", 1) @@ -359,10 +359,6 @@ class TestServiceLevelAgreement(IntegrationTestCase): applied_sla = frappe.db.get_value("Lead", lead.name, "service_level_agreement") self.assertFalse(applied_sla) - def tearDown(self): - for d in frappe.get_all("Service Level Agreement"): - frappe.delete_doc("Service Level Agreement", d.name, force=1) - def get_service_level_agreement( default_service_level_agreement=None, entity_type=None, entity=None, doctype="Issue" diff --git a/erpnext/support/doctype/support_settings/test_support_settings.py b/erpnext/support/doctype/support_settings/test_support_settings.py index 751c8d907cd..56bcd245d48 100644 --- a/erpnext/support/doctype/support_settings/test_support_settings.py +++ b/erpnext/support/doctype/support_settings/test_support_settings.py @@ -2,8 +2,8 @@ # See license.txt import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestSupportSettings(IntegrationTestCase): +class TestSupportSettings(ERPNextTestSuite): pass diff --git a/erpnext/support/doctype/warranty_claim/test_warranty_claim.py b/erpnext/support/doctype/warranty_claim/test_warranty_claim.py index ff41f36b2cd..1d5cf1f98b1 100644 --- a/erpnext/support/doctype/warranty_claim/test_warranty_claim.py +++ b/erpnext/support/doctype/warranty_claim/test_warranty_claim.py @@ -2,9 +2,8 @@ # See license.txt import unittest -import frappe -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestWarrantyClaim(IntegrationTestCase): +class TestWarrantyClaim(ERPNextTestSuite): pass diff --git a/erpnext/support/report/issue_analytics/test_issue_analytics.py b/erpnext/support/report/issue_analytics/test_issue_analytics.py index 1598ef9d295..31b8e99d8d4 100644 --- a/erpnext/support/report/issue_analytics/test_issue_analytics.py +++ b/erpnext/support/report/issue_analytics/test_issue_analytics.py @@ -2,7 +2,6 @@ import unittest import frappe from frappe.desk.form.assign_to import add as add_assignment -from frappe.tests import IntegrationTestCase from frappe.utils import add_months, getdate from erpnext.support.doctype.issue.test_issue import create_customer, make_issue @@ -10,24 +9,22 @@ from erpnext.support.doctype.service_level_agreement.test_service_level_agreemen create_service_level_agreements_for_issues, ) from erpnext.support.report.issue_analytics.issue_analytics import execute +from erpnext.tests.utils import ERPNextTestSuite months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] -class TestIssueAnalytics(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - frappe.db.sql("delete from `tabIssue` where company='_Test Company'") +class TestIssueAnalytics(ERPNextTestSuite): + def setUp(self): frappe.db.set_single_value("Support Settings", "track_service_level_agreement", 1) current_month_date = getdate() last_month_date = add_months(current_month_date, -1) - cls.current_month = str(months[current_month_date.month - 1]).lower() - cls.last_month = str(months[last_month_date.month - 1]).lower() + self.current_month = str(months[current_month_date.month - 1]).lower() + self.last_month = str(months[last_month_date.month - 1]).lower() if current_month_date.year != last_month_date.year: - cls.current_month += "_" + str(current_month_date.year) - cls.last_month += "_" + str(last_month_date.year) + self.current_month += "_" + str(current_month_date.year) + self.last_month += "_" + str(last_month_date.year) def test_issue_analytics(self): create_service_level_agreements_for_issues() diff --git a/erpnext/telephony/doctype/call_log/test_call_log.py b/erpnext/telephony/doctype/call_log/test_call_log.py index e50a13d9f9e..bed31027f01 100644 --- a/erpnext/telephony/doctype/call_log/test_call_log.py +++ b/erpnext/telephony/doctype/call_log/test_call_log.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestCallLog(IntegrationTestCase): +class TestCallLog(ERPNextTestSuite): pass diff --git a/erpnext/telephony/doctype/incoming_call_settings/test_incoming_call_settings.py b/erpnext/telephony/doctype/incoming_call_settings/test_incoming_call_settings.py index 594e17e0f32..9171b30c105 100644 --- a/erpnext/telephony/doctype/incoming_call_settings/test_incoming_call_settings.py +++ b/erpnext/telephony/doctype/incoming_call_settings/test_incoming_call_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestIncomingCallSettings(IntegrationTestCase): +class TestIncomingCallSettings(ERPNextTestSuite): pass diff --git a/erpnext/telephony/doctype/telephony_call_type/test_telephony_call_type.py b/erpnext/telephony/doctype/telephony_call_type/test_telephony_call_type.py index 3c8e4952401..e222f866612 100644 --- a/erpnext/telephony/doctype/telephony_call_type/test_telephony_call_type.py +++ b/erpnext/telephony/doctype/telephony_call_type/test_telephony_call_type.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestTelephonyCallType(IntegrationTestCase): +class TestTelephonyCallType(ERPNextTestSuite): pass diff --git a/erpnext/telephony/doctype/voice_call_settings/test_voice_call_settings.py b/erpnext/telephony/doctype/voice_call_settings/test_voice_call_settings.py index c1c6d68d964..d660fb1a6fc 100644 --- a/erpnext/telephony/doctype/voice_call_settings/test_voice_call_settings.py +++ b/erpnext/telephony/doctype/voice_call_settings/test_voice_call_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestVoiceCallSettings(IntegrationTestCase): +class TestVoiceCallSettings(ERPNextTestSuite): pass diff --git a/erpnext/tests/__init__.py b/erpnext/tests/__init__.py index dc37472c4c6..e69de29bb2d 100644 --- a/erpnext/tests/__init__.py +++ b/erpnext/tests/__init__.py @@ -1 +0,0 @@ -global_test_dependencies = ["User", "Company", "Item"] diff --git a/erpnext/tests/test_activation.py b/erpnext/tests/test_activation.py index 8968017d2f0..7c338e105d1 100644 --- a/erpnext/tests/test_activation.py +++ b/erpnext/tests/test_activation.py @@ -1,9 +1,8 @@ -from frappe.tests import IntegrationTestCase - +from erpnext.tests.utils import ERPNextTestSuite from erpnext.utilities.activation import get_level -class TestActivation(IntegrationTestCase): +class TestActivation(ERPNextTestSuite): def test_activation(self): site_info = {"activation": {"activation_level": 0, "sales_data": []}} levels = get_level(site_info) diff --git a/erpnext/tests/test_init.py b/erpnext/tests/test_init.py index 7675a031a70..4be96199ddd 100644 --- a/erpnext/tests/test_init.py +++ b/erpnext/tests/test_init.py @@ -1,14 +1,8 @@ -import unittest - -import frappe -from frappe.tests import IntegrationTestCase - from erpnext import encode_company_abbr - -EXTRA_TEST_RECORD_DEPENDENCIES = ["Company"] +from erpnext.tests.utils import ERPNextTestSuite -class TestInit(IntegrationTestCase): +class TestInit(ERPNextTestSuite): def test_encode_company_abbr(self): abbr = "NFECT" diff --git a/erpnext/tests/test_notifications.py b/erpnext/tests/test_notifications.py index 9c27229d335..1e0a48065dd 100644 --- a/erpnext/tests/test_notifications.py +++ b/erpnext/tests/test_notifications.py @@ -4,10 +4,11 @@ import unittest import frappe from frappe.desk import notifications -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite -class TestNotifications(IntegrationTestCase): +class TestNotifications(ERPNextTestSuite): def test_get_notifications_for_targets(self): """ Test notification config entries for targets as percentages diff --git a/erpnext/tests/test_perf.py b/erpnext/tests/test_perf.py index 4967d981dda..cb4ecd2ee13 100644 --- a/erpnext/tests/test_perf.py +++ b/erpnext/tests/test_perf.py @@ -1,5 +1,6 @@ import frappe -from frappe.tests import IntegrationTestCase + +from erpnext.tests.utils import ERPNextTestSuite INDEXED_FIELDS = { "Bin": ["item_code"], @@ -8,7 +9,7 @@ INDEXED_FIELDS = { } -class TestPerformance(IntegrationTestCase): +class TestPerformance(ERPNextTestSuite): def test_ensure_indexes(self): # These fields are not explicitly indexed BUT they are prefix in some # other composite index. If those are removed this test should be diff --git a/erpnext/tests/test_point_of_sale.py b/erpnext/tests/test_point_of_sale.py index 589c7cb0e48..36fad7ad64f 100644 --- a/erpnext/tests/test_point_of_sale.py +++ b/erpnext/tests/test_point_of_sale.py @@ -2,16 +2,14 @@ # MIT License. See license.txt import unittest -import frappe -from frappe.tests import IntegrationTestCase - from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile from erpnext.selling.page.point_of_sale.point_of_sale import get_items from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestSuite -class TestPointOfSale(IntegrationTestCase): +class TestPointOfSale(ERPNextTestSuite): def test_item_search(self): """ Test Stock and Service Item Search. diff --git a/erpnext/tests/test_regional.py b/erpnext/tests/test_regional.py index 83f551aae8e..648986bf648 100644 --- a/erpnext/tests/test_regional.py +++ b/erpnext/tests/test_regional.py @@ -1,9 +1,9 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase import erpnext +from erpnext.tests.utils import ERPNextTestSuite @erpnext.allow_regional @@ -11,7 +11,7 @@ def test_method(): return "original" -class TestInit(IntegrationTestCase): +class TestInit(ERPNextTestSuite): def test_regional_overrides(self): frappe.flags.country = "Maldives" self.assertEqual(test_method(), "original") diff --git a/erpnext/tests/test_webform.py b/erpnext/tests/test_webform.py index 5f600941e8f..8b4ed9ceec9 100644 --- a/erpnext/tests/test_webform.py +++ b/erpnext/tests/test_webform.py @@ -1,13 +1,13 @@ import unittest import frappe -from frappe.tests import IntegrationTestCase from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.buying.doctype.supplier.test_supplier import create_supplier +from erpnext.tests.utils import ERPNextTestSuite -class TestWebsite(IntegrationTestCase): +class TestWebsite(ERPNextTestSuite): def test_permission_for_custom_doctype(self): create_user("Supplier 1", "supplier1@gmail.com") create_user("Supplier 2", "supplier2@gmail.com") diff --git a/erpnext/tests/test_zform_loads.py b/erpnext/tests/test_zform_loads.py index ef68c10273f..3d24b77c92a 100644 --- a/erpnext/tests/test_zform_loads.py +++ b/erpnext/tests/test_zform_loads.py @@ -2,12 +2,13 @@ import frappe from frappe.desk.form.load import getdoc -from frappe.tests import IntegrationTestCase from frappe.www.printview import get_html_and_style +from erpnext.tests.utils import ERPNextTestSuite -class TestFormLoads(IntegrationTestCase): - @IntegrationTestCase.change_settings("Print Settings", {"allow_print_for_cancelled": 1}) + +class TestFormLoads(ERPNextTestSuite): + @ERPNextTestSuite.change_settings("Print Settings", {"allow_print_for_cancelled": 1}) def test_load(self): erpnext_modules = frappe.get_all("Module Def", filters={"app_name": "erpnext"}, pluck="name") doctypes = frappe.get_all( diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index 7dedd637d3c..551fe8017aa 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -1,11 +1,15 @@ # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt +import unittest +from contextlib import contextmanager from typing import Any, NewType import frappe +from frappe import _ from frappe.core.doctype.report.report import get_report_module_dotted_path -from frappe.tests import IntegrationTestCase +from frappe.tests.utils import load_test_records_for +from frappe.utils import now_datetime, today ReportFilters = dict[str, Any] ReportName = NewType("ReportName", str) @@ -117,13 +121,246 @@ def if_lending_app_not_installed(function): return wrapper -class ERPNextTestSuite(IntegrationTestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() +class BootStrapTestData: + def __init__(self): + self.make_presets() + self.make_master_data() - @classmethod - def make_monthly_distribution(cls): + def make_presets(self): + from frappe.desk.page.setup_wizard.install_fixtures import update_genders, update_salutations + + from erpnext.setup.setup_wizard.operations.install_fixtures import ( + add_uom_data, + get_preset_records, + get_sale_stages, + ) + + update_genders() + update_salutations() + + records = get_preset_records("India") + + from erpnext.setup.setup_wizard.operations.install_fixtures import read_lines + + for doctype, title_field, filename in (("UTM Source", "name", "marketing_source.txt"),): + records += [{"doctype": doctype, title_field: title} for title in read_lines(filename)] + + presets_primary_key_map = { + "Address Template": "country", + "Item Group": "item_group_name", + "Territory": "territory_name", + "Customer Group": "customer_group_name", + "Supplier Group": "supplier_group_name", + "Sales Person": "sales_person_name", + "Mode of Payment": "mode_of_payment", + "Activity Type": "activity_type", + "Item Attribute": "attribute_name", + "Party Type": "party_type", + "Project Type": "project_type", + "Print Heading": "print_heading", + "Share Type": "title", + "Market Segment": "market_segment", + "Workstation Operating Component": "component_name", + } + for x in records: + dt = x.get("doctype") + dn = x.get("name") or x.get(presets_primary_key_map.get(dt)) + + if not frappe.db.exists(dt, dn): + doc = frappe.get_doc(x) + doc.insert() + + add_uom_data() + # add sale stages + for sales_stage in get_sale_stages(): + if not frappe.db.exists("Sales Stage", {"stage_name": sales_stage.get("stage_name")}): + frappe.get_doc(sales_stage).insert() + + from erpnext.buying.doctype.supplier_scorecard.supplier_scorecard import ( + get_default_scorecard_standing, + get_default_scorecard_variables, + ) + + for x in get_default_scorecard_variables(): + x["doctype"] = "Supplier Scorecard Variable" + if not frappe.db.exists("Supplier Scorecard Variable", {"name": x.get("variable_label")}): + frappe.get_doc(x).insert() + for x in get_default_scorecard_standing(): + x["doctype"] = "Supplier Scorecard Standing" + if not frappe.db.exists("Supplier Scorecard Standing", {"name": x.get("standing_name")}): + frappe.get_doc(x).insert() + + frappe.db.commit() + + def make_master_data(self): + self.make_fiscal_year() + self.make_holiday_list() + self.make_company() + self.make_test_account() + self.make_supplier_group() + self.make_payment_term() + self.make_payment_terms_template() + self.make_tax_category() + self.make_account() + self.make_supplier() + self.make_role() + self.make_department() + self.make_territory() + self.make_customer_group() + self.make_customer() + self.make_user() + self.make_cost_center() + self.make_warehouse() + self.make_uom() + self.make_item_tax_template() + self.make_item_group() + self.make_item_attribute() + self.make_asset_maintenance_team() + self.make_asset_category() + self.make_item() + self.make_product_bundle() + self.make_location() + self.make_price_list() + self.make_item_price() + self.make_loyalty_program() + self.make_shareholder() + self.make_sales_taxes_template() + self.make_workstation() + self.make_operation() + self.make_bom() + self.make_quality_inspection_param() + self.make_quality_inspection_template() + self.make_employees() + self.make_brand() + self.make_monthly_distribution() + self.make_projects() + self.make_dunning_type() + self.make_finance_book() + self.make_leads() + self.make_sales_person() + self.make_activity_type() + self.make_address() + self.update_selling_settings() + self.update_stock_settings() + self.update_system_settings() + + frappe.db.commit() + + # custom doctype + # DDL commands have implicit commit + self.make_custom_doctype() + + def update_system_settings(self): + system_settings = frappe.get_doc("System Settings") + system_settings.time_zone = "Asia/Kolkata" + system_settings.language = "en" + system_settings.currency_precision = system_settings.float_precision = 2 + system_settings.rounding_method = "Banker's Rounding" + system_settings.save() + + def update_selling_settings(self): + selling_settings = frappe.get_doc("Selling Settings") + selling_settings.selling_price_list = "Standard Selling" + selling_settings.save() + + def update_stock_settings(self): + stock_settings = frappe.get_doc("Stock Settings") + stock_settings.item_naming_by = "Item Code" + stock_settings.valuation_method = "FIFO" + stock_settings.default_warehouse = frappe.db.get_value("Warehouse", {"warehouse_name": _("Stores")}) + stock_settings.stock_uom = "Nos" + stock_settings.auto_indent = 1 + stock_settings.auto_insert_price_list_rate_if_missing = 1 + stock_settings.update_price_list_based_on = "Rate" + stock_settings.set_qty_in_transactions_based_on_serial_no_input = 1 + stock_settings.enable_serial_and_batch_no_for_item = 1 + stock_settings.save() + + def make_records(self, key, records): + doctype = records[0].get("doctype") + + def get_filters(record): + filters = {} + for x in key: + filters[x] = record.get(x) + return filters + + for x in records: + filters = get_filters(x) + if not frappe.db.exists(doctype, filters): + frappe.get_doc(x).insert() + + def make_price_list(self): + records = [ + { + "doctype": "Price List", + "price_list_name": _("Standard Buying"), + "enabled": 1, + "buying": 1, + "selling": 0, + "currency": "INR", + }, + { + "doctype": "Price List", + "price_list_name": _("Standard Selling"), + "enabled": 1, + "buying": 0, + "selling": 1, + "currency": "INR", + }, + { + "buying": 1, + "currency": "INR", + "doctype": "Price List", + "enabled": 1, + "price_not_uom_dependant": 1, + "price_list_name": "_Test Price List", + "selling": 1, + }, + { + "buying": 1, + "currency": "INR", + "doctype": "Price List", + "enabled": 1, + "price_list_name": "_Test Price List 2", + "selling": 1, + }, + { + "buying": 1, + "currency": "INR", + "doctype": "Price List", + "enabled": 1, + "price_list_name": "_Test Price List India", + "selling": 1, + }, + { + "buying": 1, + "currency": "USD", + "doctype": "Price List", + "enabled": 1, + "price_list_name": "_Test Price List Rest of the World", + "selling": 1, + }, + { + "buying": 0, + "currency": "USD", + "doctype": "Price List", + "enabled": 1, + "price_list_name": "_Test Selling Price List", + "selling": 1, + }, + { + "buying": 1, + "currency": "USD", + "doctype": "Price List", + "enabled": 1, + "price_list_name": "_Test Buying Price List", + "selling": 0, + }, + ] + self.make_records(["price_list_name", "enabled", "selling", "buying", "currency"], records) + + def make_monthly_distribution(self): records = [ { "doctype": "Monthly Distribution", @@ -145,17 +382,9 @@ class ERPNextTestSuite(IntegrationTestCase): ], } ] - cls.monthly_distribution = [] - for x in records: - if not frappe.db.exists("Monthly Distribution", {"distribution_id": x.get("distribution_id")}): - cls.monthly_distribution.append(frappe.get_doc(x).insert()) - else: - cls.monthly_distribution.append( - frappe.get_doc("Monthly Distribution", {"distribution_id": x.get("distribution_id")}) - ) + self.make_records(["distribution_id"], records) - @classmethod - def make_projects(cls): + def make_projects(self): records = [ { "doctype": "Project", @@ -164,16 +393,185 @@ class ERPNextTestSuite(IntegrationTestCase): "status": "Open", } ] + self.make_records(["project_name"], records) - cls.projects = [] - for x in records: - if not frappe.db.exists("Project", {"project_name": x.get("project_name")}): - cls.projects.append(frappe.get_doc(x).insert()) - else: - cls.projects.append(frappe.get_doc("Project", {"project_name": x.get("project_name")})) + def make_customer_group(self): + records = [ + { + "customer_group_name": "_Test Customer Group", + "doctype": "Customer Group", + "is_group": 0, + "parent_customer_group": "All Customer Groups", + }, + { + "customer_group_name": "_Test Customer Group 1", + "doctype": "Customer Group", + "is_group": 0, + "parent_customer_group": "All Customer Groups", + }, + ] + self.make_records(["customer_group_name"], records) - @classmethod - def make_employees(cls): + def make_territory(self): + records = [ + { + "doctype": "Territory", + "is_group": 0, + "parent_territory": "All Territories", + "territory_name": "_Test Territory", + }, + { + "doctype": "Territory", + "is_group": 1, + "parent_territory": "All Territories", + "territory_name": "_Test Territory India", + }, + { + "doctype": "Territory", + "is_group": 0, + "parent_territory": "_Test Territory India", + "territory_name": "_Test Territory Maharashtra", + }, + { + "doctype": "Territory", + "is_group": 0, + "parent_territory": "All Territories", + "territory_name": "_Test Territory Rest Of The World", + }, + { + "doctype": "Territory", + "is_group": 0, + "parent_territory": "All Territories", + "territory_name": "_Test Territory United States", + }, + ] + self.make_records(["territory_name"], records) + + def make_department(self): + records = [ + { + "doctype": "Department", + "department_name": "_Test Department", + "company": "_Test Company", + "parent_department": "All Departments", + }, + { + "doctype": "Department", + "department_name": "_Test Department 1", + "company": "_Test Company", + "parent_department": "All Departments", + }, + ] + self.make_records(["department_name"], records) + + def make_role(self): + records = [ + {"doctype": "Role", "role_name": "_Test Role", "desk_access": 1}, + {"doctype": "Role", "role_name": "_Test Role 2", "desk_access": 1}, + {"doctype": "Role", "role_name": "_Test Role 3", "desk_access": 1}, + {"doctype": "Role", "role_name": "_Test Role 4", "desk_access": 0}, + {"doctype": "Role", "role_name": "Technician"}, + ] + self.make_records(["role_name"], records) + + def make_user(self): + records = [ + { + "doctype": "User", + "email": "test@example.com", + "enabled": 1, + "first_name": "_Test", + "new_password": "Eastern_43A1W", + "roles": [ + {"doctype": "Has Role", "parentfield": "roles", "role": "_Test Role"}, + {"doctype": "Has Role", "parentfield": "roles", "role": "System Manager"}, + ], + }, + { + "doctype": "User", + "email": "test1@example.com", + "first_name": "_Test1", + "new_password": "Eastern_43A1W", + }, + { + "doctype": "User", + "email": "test2@example.com", + "first_name": "_Test2", + "new_password": "Eastern_43A1W", + "enabled": 1, + }, + { + "doctype": "User", + "email": "test3@example.com", + "first_name": "_Test3", + "new_password": "Eastern_43A1W", + "enabled": 1, + }, + { + "doctype": "User", + "email": "test4@example.com", + "first_name": "_Test4", + "new_password": "Eastern_43A1W", + "enabled": 1, + }, + { + "doctype": "User", + "email": "test'5@example.com", + "first_name": "_Test'5", + "new_password": "Eastern_43A1W", + "enabled": 1, + }, + { + "doctype": "User", + "email": "testperm@example.com", + "first_name": "_Test Perm", + "new_password": "Eastern_43A1W", + "enabled": 1, + }, + { + "doctype": "User", + "email": "testdelete@example.com", + "enabled": 1, + "first_name": "_Test", + "new_password": "Eastern_43A1W", + "roles": [ + {"doctype": "Has Role", "parentfield": "roles", "role": "_Test Role 2"}, + {"doctype": "Has Role", "parentfield": "roles", "role": "System Manager"}, + ], + }, + { + "doctype": "User", + "email": "testpassword@example.com", + "enabled": 1, + "first_name": "_Test", + "new_password": "Eastern_43A1W", + "roles": [{"doctype": "Has Role", "parentfield": "roles", "role": "System Manager"}], + }, + { + "doctype": "User", + "email": "marcus@abc.com", + "first_name": "marcus@abc.com", + "new_password": "password", + "roles": [{"doctype": "Has Role", "role": "Technician"}], + }, + { + "doctype": "User", + "email": "thalia@abc.com", + "first_name": "thalia@abc.com", + "new_password": "password", + "roles": [{"doctype": "Has Role", "role": "Technician"}], + }, + { + "doctype": "User", + "email": "mathias@abc.com", + "first_name": "mathias@abc.com", + "new_password": "password", + "roles": [{"doctype": "Has Role", "role": "Technician"}], + }, + ] + self.make_records(["email"], records) + + def make_employees(self): records = [ { "company": "_Test Company", @@ -212,15 +610,9 @@ class ERPNextTestSuite(IntegrationTestCase): "user_id": "test2@example.com", }, ] - cls.employees = [] - for x in records: - if not frappe.db.exists("Employee", {"first_name": x.get("first_name")}): - cls.employees.append(frappe.get_doc(x).insert()) - else: - cls.employees.append(frappe.get_doc("Employee", {"first_name": x.get("first_name")})) + self.make_records(["first_name"], records) - @classmethod - def make_sales_person(cls): + def make_sales_person(self): records = [ { "doctype": "Sales Person", @@ -244,17 +636,9 @@ class ERPNextTestSuite(IntegrationTestCase): "sales_person_name": "_Test Sales Person 2", }, ] - cls.sales_person = [] - for x in records: - if not frappe.db.exists("Sales Person", {"sales_person_name": x.get("sales_person_name")}): - cls.sales_person.append(frappe.get_doc(x).insert()) - else: - cls.sales_person.append( - frappe.get_doc("Sales Person", {"sales_person_name": x.get("sales_person_name")}) - ) + self.make_records(["sales_person_name"], records) - @classmethod - def make_leads(cls): + def make_leads(self): records = [ { "doctype": "Lead", @@ -294,9 +678,2178 @@ class ERPNextTestSuite(IntegrationTestCase): "naming_series": "_T-Lead-", }, ] - cls.leads = [] - for x in records: - if not frappe.db.exists("Lead", {"email_id": x.get("email_id")}): - cls.leads.append(frappe.get_doc(x).insert()) - else: - cls.leads.append(frappe.get_doc("Lead", {"email_id": x.get("email_id")})) + self.make_records(["email_id"], records) + + def make_holiday_list(self): + records = [ + { + "doctype": "Holiday List", + "from_date": "2013-01-01", + "to_date": "2013-12-31", + "holidays": [ + {"description": "New Year", "holiday_date": "2013-01-01"}, + {"description": "Republic Day", "holiday_date": "2013-01-26"}, + {"description": "Test Holiday", "holiday_date": "2013-02-01"}, + ], + "holiday_list_name": "_Test Holiday List", + } + ] + self.make_records(["holiday_list_name"], records) + + def make_company(self): + records = load_test_records_for("Company")["Company"] + self.make_records(["company_name"], records) + + def make_fiscal_year(self): + records = [ + { + "doctype": "Fiscal Year", + "year": "_Test Short Fiscal Year 2011", + "is_short_year": 1, + "year_start_date": "2011-04-01", + "year_end_date": "2011-12-31", + } + ] + + start = 2012 + end = now_datetime().year + 25 + for year in range(start, end): + records.append( + { + "doctype": "Fiscal Year", + "year": f"_Test Fiscal Year {year}", + "year_start_date": f"{year}-01-01", + "year_end_date": f"{year}-12-31", + } + ) + + key = ["year_start_date", "year_end_date"] + self.make_records(key, records) + + def make_payment_term(self): + records = [ + { + "doctype": "Payment Term", + "due_date_based_on": "Day(s) after invoice date", + "payment_term_name": "_Test N30", + "description": "_Test Net 30 Days", + "invoice_portion": 50, + "credit_days": 30, + }, + { + "doctype": "Payment Term", + "due_date_based_on": "Day(s) after invoice date", + "payment_term_name": "_Test COD", + "description": "_Test Cash on Delivery", + "invoice_portion": 50, + "credit_days": 0, + }, + { + "doctype": "Payment Term", + "due_date_based_on": "Month(s) after the end of the invoice month", + "payment_term_name": "_Test EONM", + "description": "_Test End of Next Month", + "invoice_portion": 100, + "credit_months": 1, + }, + { + "doctype": "Payment Term", + "due_date_based_on": "Day(s) after invoice date", + "payment_term_name": "_Test N30 1", + "description": "_Test Net 30 Days", + "invoice_portion": 100, + "credit_days": 30, + }, + ] + self.make_records(["payment_term_name"], records) + + def make_payment_terms_template(self): + records = [ + { + "doctype": "Payment Terms Template", + "terms": [ + { + "doctype": "Payment Terms Template Detail", + "due_date_based_on": "Day(s) after invoice date", + "idx": 1, + "description": "Cash on Delivery", + "invoice_portion": 50, + "credit_days": 0, + "credit_months": 0, + "payment_term": "_Test COD", + }, + { + "doctype": "Payment Terms Template Detail", + "due_date_based_on": "Day(s) after invoice date", + "idx": 2, + "description": "Net 30 Days ", + "invoice_portion": 50, + "credit_days": 30, + "credit_months": 0, + "payment_term": "_Test N30", + }, + ], + "template_name": "_Test Payment Term Template", + }, + { + "doctype": "Payment Terms Template", + "terms": [ + { + "doctype": "Payment Terms Template Detail", + "due_date_based_on": "Month(s) after the end of the invoice month", + "idx": 1, + "description": "_Test End of Next Months", + "invoice_portion": 100, + "credit_days": 0, + "credit_months": 1, + "payment_term": "_Test EONM", + } + ], + "template_name": "_Test Payment Term Template 1", + }, + { + "doctype": "Payment Terms Template", + "terms": [ + { + "doctype": "Payment Terms Template Detail", + "due_date_based_on": "Day(s) after invoice date", + "idx": 1, + "description": "_Test Net Within 30 days", + "invoice_portion": 100, + "credit_days": 30, + "credit_months": 0, + "payment_term": "_Test N30 1", + } + ], + "template_name": "_Test Payment Term Template 3", + }, + ] + self.make_records(["template_name"], records) + + def make_tax_category(self): + records = [ + {"doctype": "Tax Category", "name": "_Test Tax Category 1", "title": "_Test Tax Category 1"}, + {"doctype": "Tax Category", "name": "_Test Tax Category 2", "title": "_Test Tax Category 2"}, + {"doctype": "Tax Category", "name": "_Test Tax Category 3", "title": "_Test Tax Category 3"}, + ] + self.make_records(["title"], records) + + def make_account(self): + records = [ + { + "doctype": "Account", + "account_name": "_Test Payable USD", + "parent_account": "Accounts Receivable - _TC", + "company": "_Test Company", + "account_currency": "USD", + }, + { + "doctype": "Account", + "account_name": "_Test Bank", + "parent_account": "Bank Accounts - _TC", + "company": "_Test Company", + }, + { + "doctype": "Account", + "account_name": "_Test Bank", + "parent_account": "Bank Accounts - TCP1", + "company": "_Test Company with perpetual inventory", + }, + ] + self.make_records(["account_name", "company"], records) + + def make_supplier(self): + records = [ + { + "doctype": "Supplier", + "supplier_name": "_Test Supplier With Template 1", + "supplier_group": "_Test Supplier Group", + "payment_terms": "_Test Payment Term Template 3", + }, + { + "doctype": "Supplier", + "supplier_name": "_Test Supplier P", + "supplier_group": "_Test Supplier Group", + }, + { + "doctype": "Supplier", + "supplier_name": "_Test Supplier with Country", + "supplier_group": "_Test Supplier Group", + "country": "Greece", + }, + { + "doctype": "Supplier", + "supplier_name": "_Test Supplier", + "supplier_group": "_Test Supplier Group", + }, + { + "doctype": "Supplier", + "supplier_name": "_Test Supplier 1", + "supplier_group": "_Test Supplier Group", + }, + { + "doctype": "Supplier", + "supplier_name": "_Test Supplier 2", + "supplier_group": "_Test Supplier Group", + }, + { + "doctype": "Supplier", + "supplier_name": "_Test Supplier USD", + "supplier_group": "_Test Supplier Group", + "default_currency": "USD", + "accounts": [{"company": "_Test Company", "account": "_Test Payable USD - _TC"}], + }, + { + "doctype": "Supplier", + "supplier_name": "_Test Supplier With Tax Category", + "supplier_group": "_Test Supplier Group", + "tax_category": "_Test Tax Category 1", + }, + { + "doctype": "Supplier", + "supplier_name": "_Test Internal Supplier 2", + "supplier_group": "_Test Supplier Group", + "is_internal_supplier": 1, + "territory": "_Test Territory", + "represents_company": "_Test Company with perpetual inventory", + "companies": [{"company": "_Test Company with perpetual inventory"}], + }, + ] + self.make_records(["supplier_name"], records) + + def make_supplier_group(self): + records = [ + { + "doctype": "Supplier Group", + "supplier_group_name": "_Test Supplier Group", + "parent_supplier_group": "All Supplier Groups", + } + ] + self.make_records(["supplier_group_name"], records) + + def make_cost_center(self): + records = [ + { + "company": "_Test Company", + "cost_center_name": "_Test Cost Center", + "doctype": "Cost Center", + "is_group": 0, + "parent_cost_center": "_Test Company - _TC", + }, + { + "company": "_Test Company", + "cost_center_name": "_Test Cost Center 2", + "doctype": "Cost Center", + "is_group": 0, + "parent_cost_center": "_Test Company - _TC", + }, + { + "company": "_Test Company", + "cost_center_name": "_Test Write Off Cost Center", + "doctype": "Cost Center", + "is_group": 0, + "parent_cost_center": "_Test Company - _TC", + }, + ] + self.make_records(["cost_center_name", "company"], records) + + def make_location(self): + records = [ + {"doctype": "Location", "location_name": "Test Location"}, + {"doctype": "Location", "location_name": "Test Location Area", "is_group": 1, "is_container": 1}, + { + "doctype": "Location", + "location_name": "Basil Farm", + "location": '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"point_type":"circle","radius":884.5625420736483},"geometry":{"type":"Point","coordinates":[72.875834,19.100566]}}]}', + "parent_location": "Test Location Area", + "parent": "Test Location Area", + "is_group": 1, + "is_container": 1, + }, + { + "doctype": "Location", + "location_name": "Division 1", + "location": '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"point_type":"circle","radius":542.3424997060739},"geometry":{"type":"Point","coordinates":[72.852359,19.11557]}}]}', + "parent_location": "Basil Farm", + "parent": "Basil Farm", + "is_group": 1, + "is_container": 1, + }, + { + "doctype": "Location", + "location_name": "Field 1", + "location": '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[72.846758,19.118287],[72.846758,19.121206],[72.850535,19.121206],[72.850535,19.118287],[72.846758,19.118287]]]}}]}', + "parent_location": "Division 1", + "parent": "Division 1", + "is_group": 1, + "is_container": 1, + }, + { + "doctype": "Location", + "location_name": "Block 1", + "location": '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[72.921495,19.073313],[72.924929,19.068121],[72.934713,19.06585],[72.929392,19.05579],[72.94158,19.056926],[72.951365,19.095213],[72.921495,19.073313]]]}}]}', + "parent_location": "Field 1", + "parent": "Field 1", + "is_group": 0, + "is_container": 1, + }, + ] + self.make_records(["location_name"], records) + + def make_warehouse(self): + records = [ + { + "company": "_Test Company", + "doctype": "Warehouse", + "warehouse_name": "_Test Warehouse", + "is_group": 0, + }, + { + "company": "_Test Company", + "doctype": "Warehouse", + "warehouse_name": "_Test Scrap Warehouse", + "is_group": 0, + }, + { + "company": "_Test Company", + "doctype": "Warehouse", + "warehouse_name": "_Test Warehouse 1", + "is_group": 0, + }, + { + "company": "_Test Company", + "doctype": "Warehouse", + "warehouse_name": "_Test Warehouse 2", + "is_group": 0, + }, + { + "company": "_Test Company", + "doctype": "Warehouse", + "warehouse_name": "_Test Rejected Warehouse", + "is_group": 0, + }, + { + "company": "_Test Company 1", + "doctype": "Warehouse", + "warehouse_name": "_Test Warehouse 2", + "is_group": 0, + }, + { + "company": "_Test Company", + "doctype": "Warehouse", + "warehouse_name": "_Test Warehouse No Account", + "is_group": 0, + }, + { + "company": "_Test Company", + "doctype": "Warehouse", + "warehouse_name": "_Test Warehouse Group", + "is_group": 1, + }, + { + "company": "_Test Company", + "doctype": "Warehouse", + "warehouse_name": "_Test Warehouse Group-C1", + "is_group": 0, + "parent_warehouse": "_Test Warehouse Group - _TC", + }, + { + "company": "_Test Company", + "doctype": "Warehouse", + "warehouse_name": "_Test Warehouse Group-C2", + "is_group": 0, + "parent_warehouse": "_Test Warehouse Group - _TC", + }, + { + "company": "_Test Company", + "doctype": "Warehouse", + "warehouse_name": "_Test Warehouse for Stock Reco1", + "is_group": 0, + }, + { + "company": "_Test Company", + "doctype": "Warehouse", + "warehouse_name": "_Test Warehouse for Stock Reco2", + "is_group": 0, + }, + ] + self.make_records(["warehouse_name", "company"], records) + + def make_uom(self): + records = [ + {"doctype": "UOM", "must_be_whole_number": 1, "uom_name": "_Test UOM"}, + {"doctype": "UOM", "uom_name": "_Test UOM 1"}, + ] + self.make_records(["uom_name"], records) + + def make_item_attribute(self): + records = [ + { + "doctype": "Item Attribute", + "attribute_name": "Test Size", + "priority": 1, + "item_attribute_values": [ + {"attribute_value": "Extra Small", "abbr": "XSL"}, + {"attribute_value": "Small", "abbr": "S"}, + {"attribute_value": "Medium", "abbr": "M"}, + {"attribute_value": "Large", "abbr": "L"}, + {"attribute_value": "Extra Large", "abbr": "XL"}, + {"attribute_value": "2XL", "abbr": "2XL"}, + ], + }, + { + "doctype": "Item Attribute", + "attribute_name": "Test Colour", + "priority": 2, + "item_attribute_values": [ + {"attribute_value": "Red", "abbr": "R"}, + {"attribute_value": "Green", "abbr": "G"}, + {"attribute_value": "Blue", "abbr": "B"}, + ], + }, + ] + self.make_records(["attribute_name"], records) + + def make_item_tax_template(self): + records = [ + { + "doctype": "Item Tax Template", + "title": "_Test Account Excise Duty @ 10", + "company": "_Test Company", + "taxes": [ + { + "doctype": "Item Tax Template Detail", + "parentfield": "taxes", + "tax_rate": 10, + "tax_type": "_Test Account Excise Duty - _TC", + } + ], + }, + { + "doctype": "Item Tax Template", + "title": "_Test Account Excise Duty @ 12", + "company": "_Test Company", + "taxes": [ + { + "doctype": "Item Tax Template Detail", + "parentfield": "taxes", + "tax_rate": 12, + "tax_type": "_Test Account Excise Duty - _TC", + } + ], + }, + { + "doctype": "Item Tax Template", + "title": "_Test Account Excise Duty @ 15", + "company": "_Test Company", + "taxes": [ + { + "doctype": "Item Tax Template Detail", + "parentfield": "taxes", + "tax_rate": 15, + "tax_type": "_Test Account Excise Duty - _TC", + } + ], + }, + { + "doctype": "Item Tax Template", + "title": "_Test Account Excise Duty @ 20", + "company": "_Test Company", + "taxes": [ + { + "doctype": "Item Tax Template Detail", + "parentfield": "taxes", + "tax_rate": 20, + "tax_type": "_Test Account Excise Duty - _TC", + } + ], + }, + { + "doctype": "Item Tax Template", + "title": "_Test Item Tax Template 1", + "company": "_Test Company", + "taxes": [ + { + "doctype": "Item Tax Template Detail", + "parentfield": "taxes", + "tax_rate": 5, + "tax_type": "_Test Account Excise Duty - _TC", + }, + { + "doctype": "Item Tax Template Detail", + "parentfield": "taxes", + "tax_rate": 10, + "tax_type": "_Test Account Education Cess - _TC", + }, + { + "doctype": "Item Tax Template Detail", + "parentfield": "taxes", + "tax_rate": 15, + "tax_type": "_Test Account S&H Education Cess - _TC", + }, + ], + }, + ] + self.make_records(["title", "company"], records) + + def make_item_group(self): + records = [ + { + "doctype": "Item Group", + "is_group": 0, + "item_group_name": "_Test Item Group", + "parent_item_group": "All Item Groups", + "item_group_defaults": [ + { + "company": "_Test Company", + "buying_cost_center": "_Test Cost Center 2 - _TC", + "selling_cost_center": "_Test Cost Center 2 - _TC", + "default_warehouse": "_Test Warehouse - _TC", + } + ], + }, + { + "doctype": "Item Group", + "is_group": 0, + "item_group_name": "_Test Item Group Desktops", + "parent_item_group": "All Item Groups", + }, + { + "doctype": "Item Group", + "is_group": 1, + "item_group_name": "_Test Item Group A", + "parent_item_group": "All Item Groups", + }, + { + "doctype": "Item Group", + "is_group": 1, + "item_group_name": "_Test Item Group B", + "parent_item_group": "All Item Groups", + }, + { + "doctype": "Item Group", + "is_group": 1, + "item_group_name": "_Test Item Group B - 1", + "parent_item_group": "_Test Item Group B", + }, + { + "doctype": "Item Group", + "is_group": 1, + "item_group_name": "_Test Item Group B - 2", + "parent_item_group": "_Test Item Group B", + }, + { + "doctype": "Item Group", + "is_group": 0, + "item_group_name": "_Test Item Group B - 3", + "parent_item_group": "_Test Item Group B", + }, + { + "doctype": "Item Group", + "is_group": 1, + "item_group_name": "_Test Item Group C", + "parent_item_group": "All Item Groups", + }, + { + "doctype": "Item Group", + "is_group": 1, + "item_group_name": "_Test Item Group C - 1", + "parent_item_group": "_Test Item Group C", + }, + { + "doctype": "Item Group", + "is_group": 1, + "item_group_name": "_Test Item Group C - 2", + "parent_item_group": "_Test Item Group C", + }, + { + "doctype": "Item Group", + "is_group": 1, + "item_group_name": "_Test Item Group D", + "parent_item_group": "All Item Groups", + }, + { + "doctype": "Item Group", + "is_group": 1, + "item_group_name": "_Test Item Group Tax Parent", + "parent_item_group": "All Item Groups", + "taxes": [ + { + "doctype": "Item Tax", + "parentfield": "taxes", + "item_tax_template": "_Test Account Excise Duty @ 10 - _TC", + "tax_category": "", + }, + { + "doctype": "Item Tax", + "parentfield": "taxes", + "item_tax_template": "_Test Account Excise Duty @ 12 - _TC", + "tax_category": "_Test Tax Category 1", + }, + ], + }, + { + "doctype": "Item Group", + "is_group": 0, + "item_group_name": "_Test Item Group Tax Child Override", + "parent_item_group": "_Test Item Group Tax Parent", + "taxes": [ + { + "doctype": "Item Tax", + "parentfield": "taxes", + "item_tax_template": "_Test Account Excise Duty @ 15 - _TC", + "tax_category": "", + } + ], + }, + ] + self.make_records(["item_group_name"], records) + + def make_item(self): + records = [ + { + "description": "_Test Item 1", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "_Test Item", + "item_group": "_Test Item Group", + "item_name": "_Test Item", + "apply_warehouse_wise_reorder_level": 1, + "opening_stock": 10, + "valuation_rate": 100, + "allow_negative_stock": True, + "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", + } + ], + "reorder_levels": [ + { + "material_request_type": "Purchase", + "warehouse": "_Test Warehouse - _TC", + "warehouse_reorder_level": 20, + "warehouse_reorder_qty": 20, + } + ], + "uoms": [ + {"uom": "_Test UOM", "conversion_factor": 1.0}, + {"uom": "_Test UOM 1", "conversion_factor": 10.0}, + ], + "stock_uom": "_Test UOM", + }, + { + "description": "_Test Item 2", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "_Test Item 2", + "item_group": "_Test Item Group", + "item_name": "_Test Item 2", + "stock_uom": "_Test UOM", + "opening_stock": 10, + "valuation_rate": 100, + "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", + } + ], + }, + { + "description": "_Test Item Home Desktop 100 3", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "_Test Item Home Desktop 100", + "item_group": "_Test Item Group Desktops", + "item_name": "_Test Item Home Desktop 100", + "valuation_rate": 100, + "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", + } + ], + "taxes": [ + { + "doctype": "Item Tax", + "parentfield": "taxes", + "item_tax_template": "_Test Account Excise Duty @ 10 - _TC", + } + ], + "stock_uom": "_Test UOM 1", + }, + { + "description": "_Test Item Home Desktop 200 4", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_sub_contracted_item": 0, + "item_code": "_Test Item Home Desktop 200", + "item_group": "_Test Item Group Desktops", + "item_name": "_Test Item Home Desktop 200", + "stock_uom": "_Test UOM 1", + "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", + } + ], + }, + { + "description": "_Test Product Bundle Item 5", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 0, + "is_sub_contracted_item": 0, + "item_code": "_Test Product Bundle Item", + "item_group": "_Test Item Group Desktops", + "item_name": "_Test Product Bundle Item", + "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", + } + ], + }, + { + "description": "_Test FG Item 6", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 1, + "item_code": "_Test FG Item", + "item_group": "_Test Item Group Desktops", + "item_name": "_Test FG Item", + "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", + } + ], + }, + { + "description": "_Test Non Stock Item 7", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 0, + "is_sub_contracted_item": 0, + "item_code": "_Test Non Stock Item", + "item_group": "_Test Item Group Desktops", + "item_name": "_Test Non Stock Item", + "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", + } + ], + }, + { + "description": "_Test Serialized Item 8", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 1, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "_Test Serialized Item", + "item_group": "_Test Item Group Desktops", + "item_name": "_Test Serialized Item", + "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", + } + ], + }, + { + "description": "_Test Serialized Item 9", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 1, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "_Test Serialized Item With Series", + "item_group": "_Test Item Group Desktops", + "item_name": "_Test Serialized Item With Series", + "serial_no_series": "ABCD.#####", + "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", + } + ], + }, + { + "description": "_Test Item Home Desktop Manufactured 10", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "_Test Item Home Desktop Manufactured", + "item_group": "_Test Item Group Desktops", + "item_name": "_Test Item Home Desktop Manufactured", + "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", + } + ], + }, + { + "description": "_Test FG Item 2 11", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 1, + "item_code": "_Test FG Item 2", + "item_group": "_Test Item Group Desktops", + "item_name": "_Test FG Item 2", + "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", + } + ], + }, + { + "description": "_Test Variant Item 12", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 1, + "item_code": "_Test Variant Item", + "item_group": "_Test Item Group Desktops", + "item_name": "_Test Variant Item", + "stock_uom": "_Test UOM", + "has_variants": 1, + "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"}], + "apply_warehouse_wise_reorder_level": 1, + "reorder_levels": [ + { + "material_request_type": "Purchase", + "warehouse": "_Test Warehouse - _TC", + "warehouse_reorder_level": 20, + "warehouse_reorder_qty": 20, + } + ], + }, + { + "description": "_Test Item 1", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "_Test Item Warehouse Group Wise Reorder", + "item_group": "_Test Item Group", + "item_name": "_Test Item Warehouse Group Wise Reorder", + "apply_warehouse_wise_reorder_level": 1, + "item_defaults": [ + { + "company": "_Test Company", + "default_warehouse": "_Test Warehouse Group-C1 - _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", + } + ], + "reorder_levels": [ + { + "warehouse_group": "_Test Warehouse Group - _TC", + "material_request_type": "Purchase", + "warehouse": "_Test Warehouse Group-C1 - _TC", + "warehouse_reorder_level": 20, + "warehouse_reorder_qty": 20, + } + ], + "stock_uom": "_Test UOM", + }, + { + "description": "_Test Item With Item Tax Template", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "_Test Item With Item Tax Template", + "item_group": "_Test Item Group", + "item_name": "_Test Item With Item Tax Template", + "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", + } + ], + "taxes": [ + { + "doctype": "Item Tax", + "parentfield": "taxes", + "item_tax_template": "_Test Account Excise Duty @ 10 - _TC", + }, + { + "doctype": "Item Tax", + "parentfield": "taxes", + "item_tax_template": "_Test Account Excise Duty @ 12 - _TC", + "tax_category": "_Test Tax Category 1", + }, + ], + }, + { + "description": "_Test Item Inherit Group Item Tax Template 1", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "_Test Item Inherit Group Item Tax Template 1", + "item_group": "_Test Item Group Tax Parent", + "item_name": "_Test Item Inherit Group Item Tax Template 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", + } + ], + }, + { + "description": "_Test Item Inherit Group Item Tax Template 2", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "_Test Item Inherit Group Item Tax Template 2", + "item_group": "_Test Item Group Tax Child Override", + "item_name": "_Test Item Inherit Group Item Tax Template 2", + "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", + } + ], + }, + { + "description": "_Test Item Override Group Item Tax Template", + "doctype": "Item", + "has_batch_no": 0, + "has_serial_no": 0, + "inspection_required": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "_Test Item Override Group Item Tax Template", + "item_group": "_Test Item Group Tax Child Override", + "item_name": "_Test Item Override Group Item Tax Template", + "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", + } + ], + "taxes": [ + { + "doctype": "Item Tax", + "parentfield": "taxes", + "item_tax_template": "_Test Account Excise Duty @ 20 - _TC", + }, + { + "doctype": "Item Tax", + "parentfield": "taxes", + "tax_category": "_Test Tax Category 1", + "item_tax_template": "_Test Item Tax Template 1 - _TC", + }, + ], + }, + { + "description": "_Test", + "doctype": "Item", + "is_stock_item": 1, + "item_code": "138-CMS Shoe", + "item_group": "_Test Item Group", + "item_name": "138-CMS Shoe", + "stock_uom": "_Test UOM", + }, + { + "doctype": "Item", + "item_code": "Photocopier", + "item_name": "Photocopier", + "item_group": "All Item Groups", + "company": "_Test Company", + "is_fixed_asset": 1, + "is_stock_item": 0, + "asset_category": "Equipment", + "auto_create_assets": 1, + "asset_naming_series": "ABC.###", + "stock_uom": "_Test UOM", + }, + { + "doctype": "Item", + "item_code": "Loyal Item", + "item_name": "Loyal Item", + "item_group": "All Item Groups", + "company": "_Test Company", + "is_stock_item": 1, + "opening_stock": 100, + "valuation_rate": 10000, + "stock_uom": "_Test UOM", + }, + { + "doctype": "Item", + "item_code": "_Test Extra Item 1", + "item_name": "_Test Extra Item 1", + "item_group": "All Item Groups", + "company": "_Test Company", + "is_stock_item": 1, + "stock_uom": "_Test UOM", + }, + { + "doctype": "Item", + "item_code": "_Test Extra Item 2", + "item_name": "_Test Extra Item 2", + "item_group": "All Item Groups", + "company": "_Test Company", + "is_stock_item": 1, + "stock_uom": "_Test UOM", + }, + { + "doctype": "Item", + "item_code": "Stock-Reco-Serial-Item-1", + "item_name": "Stock-Reco-Serial-Item-1", + "is_stock_item": 1, + "item_group": "All Item Groups", + "stock_uom": "Nos", + "has_serial_no": 1, + "serial_no_series": "SRSI.#####", + }, + { + "doctype": "Item", + "item_code": "Stock-Reco-Serial-Item-2", + "item_name": "Stock-Reco-Serial-Item-2", + "is_stock_item": 1, + "item_group": "All Item Groups", + "stock_uom": "Nos", + "has_serial_no": 1, + "serial_no_series": "SRSII.#####", + }, + { + "doctype": "Item", + "item_code": "Stock-Reco-batch-Item-1", + "item_name": "Stock-Reco-batch-Item-1", + "is_stock_item": 1, + "item_group": "All Item Groups", + "stock_uom": "Nos", + "has_batch_no": 1, + "batch_number_series": "BASR.#####", + "create_new_batch": 1, + }, + { + "doctype": "Item", + "item_code": "Test Asset Item", + "item_name": "Test Asset Item", + "is_stock_item": 0, + "item_group": "All Item Groups", + "stock_uom": "Box", + "is_fixed_asset": 1, + "auto_create_assets": 1, + "asset_category": "Equipment", + "asset_naming_series": "ABC.###", + }, + { + "doctype": "Item", + "item_code": "Macbook Pro", + "item_name": "Macbook Pro", + "description": "Macbook Pro Retina Display", + "asset_category": "Computers", + "item_group": "All Item Groups", + "stock_uom": "Nos", + "is_stock_item": 0, + "is_fixed_asset": 1, + "auto_create_assets": 1, + "is_grouped_asset": 0, + "asset_naming_series": "ACC-ASS-.YYYY.-", + }, + { + "doctype": "Item", + "item_code": "_Test Stock Item", + "item_name": "Test Stock Item", + "is_stock_item": 1, + "item_group": "All Item Groups", + "stock_uom": "Nos", + }, + { + "doctype": "Item", + "item_code": "Consulting", + "item_name": "Consulting", + "is_stock_item": 0, + "item_group": "All Item Groups", + "stock_uom": "Nos", + "company": "_Test Company", + }, + ] + self.make_records(["item_code", "item_name"], records) + + def make_product_bundle(self): + records = [ + { + "doctype": "Product Bundle", + "new_item_code": "_Test Product Bundle Item", + "items": [ + { + "doctype": "Product Bundle Item", + "item_code": "_Test Item", + "parentfield": "items", + "qty": 5.0, + }, + { + "doctype": "Product Bundle Item", + "item_code": "_Test Item Home Desktop 100", + "parentfield": "items", + "qty": 2.0, + }, + ], + } + ] + self.make_records(["new_item_code"], records) + + def make_test_account(self): + records = [ + # [account_name, parent_account, is_group] + ["_Test Bank", "Bank Accounts", 0, "Bank", None], + ["_Test Bank USD", "Bank Accounts", 0, "Bank", "USD"], + ["_Test Bank EUR", "Bank Accounts", 0, "Bank", "EUR"], + ["_Test Cash", "Cash In Hand", 0, "Cash", None], + ["_Test Account Stock Expenses", "Direct Expenses", 1, None, None], + ["_Test Account Shipping Charges", "_Test Account Stock Expenses", 0, "Chargeable", None], + ["_Test Account Customs Duty", "_Test Account Stock Expenses", 0, "Tax", None], + ["_Test Account Insurance Charges", "_Test Account Stock Expenses", 0, "Chargeable", None], + ["_Test Account Stock Adjustment", "_Test Account Stock Expenses", 0, "Stock Adjustment", None], + ["_Test Employee Advance", "Current Liabilities", 0, None, None], + ["_Test Account Tax Assets", "Current Assets", 1, None, None], + ["_Test Account VAT", "_Test Account Tax Assets", 0, "Tax", None], + ["_Test Account Service Tax", "_Test Account Tax Assets", 0, "Tax", None], + ["_Test Account Reserves and Surplus", "Current Liabilities", 0, None, None], + ["_Test Account Cost for Goods Sold", "Expenses", 0, None, None], + ["_Test Account Excise Duty", "_Test Account Tax Assets", 0, "Tax", None], + ["_Test Account Education Cess", "_Test Account Tax Assets", 0, "Tax", None], + ["_Test Account S&H Education Cess", "_Test Account Tax Assets", 0, "Tax", None], + ["_Test Account CST", "Direct Expenses", 0, "Tax", None], + ["_Test Account Discount", "Direct Expenses", 0, None, None], + ["_Test Write Off", "Indirect Expenses", 0, None, None], + ["_Test Exchange Gain/Loss", "Indirect Expenses", 0, None, None], + ["_Test Account Sales", "Direct Income", 0, None, None], + # related to Account Inventory Integration + ["_Test Account Stock In Hand", "Current Assets", 0, None, None], + # fixed asset depreciation + ["_Test Fixed Asset", "Current Assets", 0, "Fixed Asset", None], + ["_Test Accumulated Depreciations", "Current Assets", 0, "Accumulated Depreciation", None], + ["_Test Depreciations", "Expenses", 0, "Depreciation", None], + ["_Test Gain/Loss on Asset Disposal", "Expenses", 0, None, None], + # Receivable / Payable Account + ["_Test Receivable", "Current Assets", 0, "Receivable", None], + ["_Test Payable", "Current Liabilities", 0, "Payable", None], + ["_Test Receivable USD", "Current Assets", 0, "Receivable", "USD"], + ["_Test Payable USD", "Current Liabilities", 0, "Payable", "USD"], + # Loyalty Account + ["Loyalty", "Direct Expenses", 0, "Expense Account", None], + ] + + self.test_accounts = [] + for company, abbr in [ + ["_Test Company", "_TC"], + ["_Test Company 1", "_TC1"], + ["_Test Company with perpetual inventory", "TCP1"], + ]: + for account_name, parent_account, is_group, account_type, currency in records: + if not frappe.db.exists("Account", {"account_name": account_name, "company": company}): + self.test_accounts.append( + frappe.get_doc( + { + "doctype": "Account", + "account_name": account_name, + "parent_account": parent_account + " - " + abbr, + "company": company, + "is_group": is_group, + "account_type": account_type, + "account_currency": currency, + } + ).insert() + ) + else: + self.test_accounts.append( + frappe.get_doc("Account", {"account_name": account_name, "company": company}) + ) + + def make_customer(self): + records = [ + { + "customer_group": "_Test Customer Group", + "customer_name": "_Test Customer With Template", + "customer_type": "Individual", + "doctype": "Customer", + "territory": "_Test Territory", + }, + { + "customer_group": "_Test Customer Group", + "customer_name": "_Test Customer P", + "customer_type": "Individual", + "doctype": "Customer", + "territory": "_Test Territory", + }, + { + "customer_group": "_Test Customer Group", + "customer_name": "_Test Customer", + "customer_type": "Individual", + "doctype": "Customer", + "territory": "_Test Territory", + }, + { + "customer_group": "_Test Customer Group", + "customer_name": "_Test Customer 1", + "customer_type": "Individual", + "doctype": "Customer", + "territory": "_Test Territory", + }, + { + "customer_group": "_Test Customer Group", + "customer_name": "_Test Customer 2", + "customer_type": "Individual", + "doctype": "Customer", + "territory": "_Test Territory", + }, + { + "customer_group": "_Test Customer Group", + "customer_name": "_Test Customer 3", + "customer_type": "Individual", + "doctype": "Customer", + "territory": "_Test Territory", + }, + { + "customer_group": "_Test Customer Group", + "customer_name": "_Test Customer USD", + "customer_type": "Individual", + "doctype": "Customer", + "territory": "_Test Territory", + "default_currency": "USD", + "accounts": [{"company": "_Test Company", "account": "_Test Receivable USD - _TC"}], + }, + { + "customer_group": "_Test Customer Group", + "customer_name": "_Test Customer With Tax Category", + "customer_type": "Individual", + "doctype": "Customer", + "territory": "_Test Territory", + "tax_category": "_Test Tax Category 1", + }, + { + "customer_group": "_Test Customer Group", + "customer_name": "Test Loyalty Customer", + "customer_type": "Individual", + "doctype": "Customer", + "territory": "_Test Territory", + }, + { + "customer_group": "_Test Customer Group", + "customer_name": "_Test Internal Customer 2", + "customer_type": "Individual", + "doctype": "Customer", + "is_internal_customer": 1, + "territory": "_Test Territory", + "represents_company": "_Test Company with perpetual inventory", + "companies": [{"company": "_Test Company with perpetual inventory"}], + }, + { + "customer_group": "_Test Customer Group", + "customer_name": "Prestiga-Biz", + "customer_type": "Company", + "doctype": "Customer", + "territory": "_Test Territory", + }, + { + "customer_group": "_Test Customer Group", + "customer_name": "_Test NC", + "customer_type": "Individual", + "doctype": "Customer", + "territory": "_Test Territory", + }, + ] + self.make_records(["customer_name"], records) + + def make_shareholder(self): + records = [ + { + "doctype": "Shareholder", + "naming_series": "SH-", + "title": "Iron Man", + "company": "_Test Company", + }, + {"doctype": "Shareholder", "naming_series": "SH-", "title": "Thor", "company": "_Test Company"}, + {"doctype": "Shareholder", "naming_series": "SH-", "title": "Hulk", "company": "_Test Company"}, + ] + self.make_records(["title", "company"], records) + + def make_sales_taxes_template(self): + records = [ + { + "company": "_Test Company", + "doctype": "Sales Taxes and Charges Template", + "taxes": [ + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "cost_center": "Main - _TC", + "parentfield": "taxes", + "rate": 6, + }, + { + "account_head": "_Test Account Service Tax - _TC", + "charge_type": "On Net Total", + "description": "Service Tax", + "doctype": "Sales Taxes and Charges", + "cost_center": "Main - _TC", + "parentfield": "taxes", + "rate": 6.36, + }, + ], + "title": "_Test Sales Taxes and Charges Template", + }, + { + "company": "_Test Company", + "doctype": "Sales Taxes and Charges Template", + "taxes": [ + { + "account_head": "_Test Account Shipping Charges - _TC", + "charge_type": "Actual", + "cost_center": "_Test Cost Center - _TC", + "description": "Shipping Charges", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "tax_amount": 100, + }, + { + "account_head": "_Test Account Customs Duty - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Customs Duty", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 10, + }, + { + "account_head": "_Test Account Excise Duty - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Excise Duty", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 12, + }, + { + "account_head": "_Test Account Education Cess - _TC", + "charge_type": "On Previous Row Amount", + "cost_center": "_Test Cost Center - _TC", + "description": "Education Cess", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 2, + "row_id": 3, + }, + { + "account_head": "_Test Account S&H Education Cess - _TC", + "charge_type": "On Previous Row Amount", + "cost_center": "_Test Cost Center - _TC", + "description": "S&H Education Cess", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 1, + "row_id": 3, + }, + { + "account_head": "_Test Account CST - _TC", + "charge_type": "On Previous Row Total", + "cost_center": "_Test Cost Center - _TC", + "description": "CST", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 2, + "row_id": 5, + }, + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": 12.5, + }, + { + "account_head": "_Test Account Discount - _TC", + "charge_type": "On Previous Row Total", + "cost_center": "_Test Cost Center - _TC", + "description": "Discount", + "doctype": "Sales Taxes and Charges", + "parentfield": "taxes", + "rate": -10, + "row_id": 7, + }, + ], + "title": "_Test India Tax Master", + }, + { + "company": "_Test Company", + "doctype": "Sales Taxes and Charges Template", + "taxes": [ + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "cost_center": "Main - _TC", + "parentfield": "taxes", + "rate": 12, + }, + { + "account_head": "_Test Account Service Tax - _TC", + "charge_type": "On Net Total", + "description": "Service Tax", + "doctype": "Sales Taxes and Charges", + "cost_center": "Main - _TC", + "parentfield": "taxes", + "rate": 4, + }, + ], + "title": "_Test Sales Taxes and Charges Template - Rest of the World", + }, + { + "company": "_Test Company", + "doctype": "Sales Taxes and Charges Template", + "taxes": [ + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "cost_center": "Main - _TC", + "parentfield": "taxes", + "rate": 12, + }, + { + "account_head": "_Test Account Service Tax - _TC", + "charge_type": "On Net Total", + "description": "Service Tax", + "doctype": "Sales Taxes and Charges", + "cost_center": "Main - _TC", + "parentfield": "taxes", + "rate": 4, + }, + ], + "title": "_Test Sales Taxes and Charges Template 1", + }, + { + "company": "_Test Company", + "doctype": "Sales Taxes and Charges Template", + "taxes": [ + { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "cost_center": "Main - _TC", + "parentfield": "taxes", + "rate": 12, + }, + { + "account_head": "_Test Account Service Tax - _TC", + "charge_type": "On Net Total", + "description": "Service Tax", + "doctype": "Sales Taxes and Charges", + "cost_center": "Main - _TC", + "parentfield": "taxes", + "rate": 4, + }, + ], + "title": "_Test Sales Taxes and Charges Template 2", + }, + { + "doctype": "Sales Taxes and Charges Template", + "title": "_Test Tax 1", + "company": "_Test Company", + "taxes": [ + { + "charge_type": "Actual", + "account_head": "Sales Expenses - _TC", + "cost_center": "Main - _TC", + "description": "Test Shopping cart taxes with Tax Rule", + "tax_amount": 1000, + } + ], + }, + { + "doctype": "Sales Taxes and Charges Template", + "title": "_Test Tax 2", + "company": "_Test Company", + "taxes": [ + { + "charge_type": "Actual", + "account_head": "Sales Expenses - _TC", + "cost_center": "Main - _TC", + "description": "Test Shopping cart taxes with Tax Rule", + "tax_amount": 200, + } + ], + }, + ] + self.make_records(["title", "company"], records) + + def make_asset_category(self): + records = [ + { + "doctype": "Asset Category", + "asset_category_name": "Equipment", + "total_number_of_depreciations": 3, + "frequency_of_depreciation": 3, + "accounts": [ + { + "company_name": "_Test Company", + "fixed_asset_account": "_Test Fixed Asset - _TC", + "accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC", + "depreciation_expense_account": "_Test Depreciations - _TC", + } + ], + }, + { + "doctype": "Asset Category", + "asset_category_name": "Computers", + "total_number_of_depreciations": 3, + "frequency_of_depreciation": 3, + "enable_cwip_accounting": True, + "accounts": [ + { + "company_name": "_Test Company", + "fixed_asset_account": "_Test Fixed Asset - _TC", + "accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC", + "depreciation_expense_account": "_Test Depreciations - _TC", + "capital_work_in_progress_account": "CWIP Account - _TC", + }, + { + "company_name": "_Test Company with perpetual inventory", + "fixed_asset_account": "_Test Fixed Asset - TCP1", + "accumulated_depreciation_account": "_Test Accumulated Depreciations - TCP1", + "depreciation_expense_account": "_Test Depreciations - TCP1", + }, + ], + }, + ] + self.make_records(["asset_category_name"], records) + + def make_asset_maintenance_team(self): + records = [ + { + "doctype": "Asset Maintenance Team", + "maintenance_manager": "marcus@abc.com", + "maintenance_team_name": "Team Awesome", + "company": "_Test Company", + "maintenance_team_members": [ + { + "team_member": "marcus@abc.com", + "full_name": "marcus@abc.com", + "maintenance_role": "Technician", + }, + { + "team_member": "thalia@abc.com", + "full_name": "thalia@abc.com", + "maintenance_role": "Technician", + }, + { + "team_member": "mathias@abc.com", + "full_name": "mathias@abc.com", + "maintenance_role": "Technician", + }, + ], + } + ] + self.make_records(["maintenance_team_name"], records) + + def make_activity_type(self): + records = [ + { + "doctype": "Activity Type", + "name": "_Test Activity Type", + "activity_type": "_Test Activity Type", + }, + { + "doctype": "Activity Type", + "name": "_Test Activity Type 1", + "activity_type": "_Test Activity Type 1", + }, + ] + self.make_records(["activity_type"], records) + + def make_loyalty_program(self): + records = [ + { + "doctype": "Loyalty Program", + "loyalty_program_name": "Test Single Loyalty", + "auto_opt_in": 1, + "from_date": today(), + "loyalty_program_type": "Single Tier Program", + "conversion_factor": 1, + "expiry_duration": 10, + "company": "_Test Company", + "cost_center": "Main - _TC", + "expense_account": "Loyalty - _TC", + "collection_rules": [{"tier_name": "Bronce", "collection_factor": 1000, "min_spent": 0}], + }, + { + "doctype": "Loyalty Program", + "loyalty_program_name": "Test Multiple Loyalty", + "auto_opt_in": 1, + "from_date": today(), + "loyalty_program_type": "Multiple Tier Program", + "conversion_factor": 1, + "expiry_duration": 10, + "company": "_Test Company", + "cost_center": "Main - _TC", + "expense_account": "Loyalty - _TC", + "collection_rules": [ + {"tier_name": "Bronze", "collection_factor": 1000, "min_spent": 0}, + {"tier_name": "Silver", "collection_factor": 1000, "min_spent": 10000}, + {"tier_name": "Gold", "collection_factor": 1000, "min_spent": 19000}, + ], + }, + ] + self.make_records(["loyalty_program_name"], records) + + def make_item_price(self): + records = [ + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Price List", + "price_list_rate": 100, + "valid_from": "2017-04-18", + "valid_upto": "2017-04-26", + }, + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Price List Rest of the World", + "price_list_rate": 10, + }, + { + "doctype": "Item Price", + "item_code": "_Test Item 2", + "price_list": "_Test Price List Rest of the World", + "price_list_rate": 20, + "valid_from": "2017-04-18", + "valid_upto": "2017-04-26", + "customer": "_Test Customer", + "uom": "_Test UOM", + }, + { + "doctype": "Item Price", + "item_code": "_Test Item Home Desktop 100", + "price_list": "_Test Price List", + "price_list_rate": 1000, + "valid_from": "2017-04-10", + "valid_upto": "2017-04-17", + }, + { + "doctype": "Item Price", + "item_code": "_Test Item Home Desktop Manufactured", + "price_list": "_Test Price List", + "price_list_rate": 1000, + "valid_from": "2017-04-10", + "valid_upto": "2017-04-17", + }, + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Buying Price List", + "price_list_rate": 100, + "supplier": "_Test Supplier", + }, + { + "doctype": "Item Price", + "item_code": "_Test Item", + "price_list": "_Test Selling Price List", + "price_list_rate": 200, + "customer": "_Test Customer", + }, + { + "doctype": "Item Price", + "price_list": _("Standard Selling"), + "item_code": "Loyal Item", + "price_list_rate": 10000, + }, + { + "doctype": "Item Price", + "item_code": "Consulting", + "price_list": "Standard Selling", + "price_list_rate": 10000, + }, + ] + self.make_records(["item_code", "price_list", "price_list_rate"], records) + + def make_operation(self): + records = [ + {"doctype": "Operation", "name": "_Test Operation 1", "workstation": "_Test Workstation 1"} + ] + self.make_records(["name"], records) + + def make_workstation(self): + records = [ + { + "doctype": "Workstation", + "name": "_Test Workstation 1", + "workstation_name": "_Test Workstation 1", + "warehouse": "_Test warehouse - _TC", + "hour_rate_labour": 25, + "hour_rate_electricity": 25, + "hour_rate_consumable": 25, + "hour_rate_rent": 25, + "holiday_list": "_Test Holiday List", + "working_hours": [{"start_time": "10:00:00", "end_time": "20:00:00"}], + } + ] + self.make_records(["workstation_name"], records) + + def make_bom(self): + # TODO: replace JSON source with hardcoded data + records = load_test_records_for("BOM")["BOM"] + self.make_records(["item", "company"], records) + + def make_quality_inspection_param(self): + records = [{"doctype": "Quality Inspection Parameter", "parameter": "_Test Param"}] + self.make_records(["parameter"], records) + + def make_quality_inspection_template(self): + records = [ + { + "quality_inspection_template_name": "_Test Quality Inspection Template", + "doctype": "Quality Inspection Template", + "item_quality_inspection_parameter": [ + { + "specification": "_Test Param", + "doctype": "Item Quality Inspection Parameter", + "parentfield": "item_quality_inspection_parameter", + } + ], + } + ] + self.make_records(["quality_inspection_template_name"], records) + + def make_brand(self): + records = [ + {"brand": "_Test Brand", "doctype": "Brand"}, + { + "brand": "_Test Brand With Item Defaults", + "doctype": "Brand", + "brand_defaults": [ + { + "company": "_Test Company", + "expense_account": "_Test Account Cost for Goods Sold - _TC", + "income_account": "_Test Account Sales - _TC", + "buying_cost_center": "_Test Cost Center - _TC", + "selling_cost_center": "_Test Cost Center - _TC", + } + ], + }, + ] + self.make_records(["brand"], records) + + def make_dunning_type(self): + records = [ + { + "doctype": "Dunning Type", + "dunning_type": "First Notice", + "company": "_Test Company", + "is_default": 1, + "dunning_fee": 0, + "rate_of_interest": 0, + "income_account": "Sales - _TC", + "cost_center": "Main - _TC", + "dunning_letter_text": [ + { + "language": "en", + "body_text": "We have still not received payment for our invoice", + "closing_text": "We kindly request that you pay the outstanding amount immediately, including interest and late fees.", + }, + ], + }, + { + "doctype": "Dunning Type", + "dunning_type": "Second Notice", + "company": "_Test Company", + "is_default": 0, + "dunning_fee": 10, + "rate_of_interest": 10, + "income_account": "Sales - _TC", + "cost_center": "Main - _TC", + "dunning_letter_text": [ + { + "language": "en", + "body_text": "We have still not received payment for our invoice", + "closing_text": "We kindly request that you pay the outstanding amount immediately, including interest and late fees.", + }, + ], + }, + ] + self.make_records(["dunning_type"], records) + + def make_finance_book(self): + records = [ + { + "doctype": "Finance Book", + "finance_book_name": "Test Finance Book 1", + }, + { + "doctype": "Finance Book", + "finance_book_name": "Test Finance Book 2", + }, + { + "doctype": "Finance Book", + "finance_book_name": "Test Finance Book 3", + }, + ] + self.make_records(["finance_book_name"], records) + + def make_custom_doctype(self): + if not frappe.db.exists("DocType", "Shelf"): + frappe.get_doc( + { + "doctype": "DocType", + "name": "Shelf", + "module": "Stock", + "custom": 1, + "naming_rule": "By fieldname", + "autoname": "field:shelf_name", + "fields": [{"label": "Shelf Name", "fieldname": "shelf_name", "fieldtype": "Data"}], + "permissions": [ + { + "role": "System Manager", + "permlevel": 0, + "read": 1, + "write": 1, + "create": 1, + "delete": 1, + } + ], + } + ).insert(ignore_permissions=True) + + if not frappe.db.exists("DocType", "Rack"): + frappe.get_doc( + { + "doctype": "DocType", + "name": "Rack", + "module": "Stock", + "custom": 1, + "naming_rule": "By fieldname", + "autoname": "field:rack_name", + "fields": [{"label": "Rack Name", "fieldname": "rack_name", "fieldtype": "Data"}], + "permissions": [ + { + "role": "System Manager", + "permlevel": 0, + "read": 1, + "write": 1, + "create": 1, + "delete": 1, + } + ], + } + ).insert(ignore_permissions=True) + + if not frappe.db.exists("DocType", "Pallet"): + frappe.get_doc( + { + "doctype": "DocType", + "name": "Pallet", + "module": "Stock", + "custom": 1, + "naming_rule": "By fieldname", + "autoname": "field:pallet_name", + "fields": [{"label": "Pallet Name", "fieldname": "pallet_name", "fieldtype": "Data"}], + "permissions": [ + { + "role": "System Manager", + "permlevel": 0, + "read": 1, + "write": 1, + "create": 1, + "delete": 1, + } + ], + } + ).insert(ignore_permissions=True) + + if not frappe.db.exists("DocType", "Inv Site"): + frappe.get_doc( + { + "doctype": "DocType", + "name": "Inv Site", + "module": "Stock", + "custom": 1, + "naming_rule": "By fieldname", + "autoname": "field:site_name", + "fields": [{"label": "Site Name", "fieldname": "site_name", "fieldtype": "Data"}], + "permissions": [ + { + "role": "System Manager", + "permlevel": 0, + "read": 1, + "write": 1, + "create": 1, + "delete": 1, + } + ], + } + ).insert(ignore_permissions=True) + + if not frappe.db.exists("DocType", "Store"): + frappe.get_doc( + { + "doctype": "DocType", + "name": "Store", + "module": "Stock", + "custom": 1, + "naming_rule": "By fieldname", + "autoname": "field:store_name", + "fields": [{"label": "Store Name", "fieldname": "store_name", "fieldtype": "Data"}], + "permissions": [ + { + "role": "System Manager", + "permlevel": 0, + "read": 1, + "write": 1, + "create": 1, + "delete": 1, + } + ], + } + ).insert(ignore_permissions=True) + + def make_address(self): + records = [ + { + "doctype": "Address", + "address_type": "Billing", + "address_line1": "Address line 1", + "address_title": "_Test Billing Address Title", + "city": "Lagos", + "country": "Nigeria", + "links": [ + {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"} + ], + }, + { + "doctype": "Address", + "address_type": "Shipping", + "address_line1": "Address line 2", + "address_title": "_Test Shipping Address 1 Title", + "city": "Lagos", + "country": "Nigeria", + "links": [ + {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"} + ], + }, + { + "doctype": "Address", + "address_type": "Shipping", + "address_line1": "Address line 3", + "address_title": "_Test Shipping Address 2 Title", + "city": "Lagos", + "country": "Nigeria", + "is_shipping_address": "1", + "links": [ + {"link_doctype": "Customer", "link_name": "_Test Customer 2", "doctype": "Dynamic Link"} + ], + }, + { + "doctype": "Address", + "address_type": "Billing", + "address_line1": "Address line 4", + "address_title": "_Test Billing Address 2 Title", + "city": "Lagos", + "country": "Nigeria", + "is_shipping_address": "1", + "links": [ + {"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"} + ], + }, + ] + self.make_records(["address_title", "address_type"], records) + + +BootStrapTestData() + + +class ERPNextTestSuite(unittest.TestCase): + @classmethod + def registerAs(cls, _as): + def decorator(cm_func): + setattr(cls, cm_func.__name__, _as(cm_func)) + return cm_func + + return decorator + + @classmethod + def setUpClass(cls): + cls.globalTestRecords = {} + + def tearDown(self): + frappe.db.rollback() + + def load_test_records(self, doctype): + if doctype not in self.globalTestRecords: + records = load_test_records_for(doctype) + self.globalTestRecords[doctype] = records[doctype] + + @contextmanager + def set_user(self, user: str): + try: + old_user = frappe.session.user + frappe.set_user(user) + yield + finally: + frappe.set_user(old_user) + + +@ERPNextTestSuite.registerAs(staticmethod) +@contextmanager +def change_settings(doctype, settings_dict=None, /, **settings) -> None: + """Temporarily: change settings in a settings doctype.""" + import copy + + if settings_dict is None: + settings_dict = settings + + settings = frappe.get_doc(doctype) + previous_settings = copy.deepcopy(settings_dict) + for key in previous_settings: + previous_settings[key] = getattr(settings, key) + + for key, value in settings_dict.items(): + setattr(settings, key, value) + settings.save(ignore_permissions=True) + + yield + + settings = frappe.get_doc(doctype) + for key, value in previous_settings.items(): + setattr(settings, key, value) + settings.save(ignore_permissions=True) diff --git a/erpnext/utilities/doctype/video/test_video.py b/erpnext/utilities/doctype/video/test_video.py index 4d37c575f84..55201932259 100644 --- a/erpnext/utilities/doctype/video/test_video.py +++ b/erpnext/utilities/doctype/video/test_video.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestVideo(IntegrationTestCase): +class TestVideo(ERPNextTestSuite): pass diff --git a/erpnext/utilities/doctype/video_settings/test_video_settings.py b/erpnext/utilities/doctype/video_settings/test_video_settings.py index fea375e5128..2fb854128ff 100644 --- a/erpnext/utilities/doctype/video_settings/test_video_settings.py +++ b/erpnext/utilities/doctype/video_settings/test_video_settings.py @@ -3,8 +3,8 @@ # import frappe import unittest -from frappe.tests import IntegrationTestCase +from erpnext.tests.utils import ERPNextTestSuite -class TestVideoSettings(IntegrationTestCase): +class TestVideoSettings(ERPNextTestSuite): pass