mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 08:54:45 +00:00
refactor(test): create ERPNext specific test suite
and move data initialization there
This commit is contained in:
@@ -3,72 +3,22 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.tests import IntegrationTestCase
|
|
||||||
from frappe.utils import now_datetime, nowdate
|
from frappe.utils import now_datetime, nowdate
|
||||||
|
|
||||||
from erpnext.accounts.doctype.budget.budget import BudgetError, get_actual_expense
|
from erpnext.accounts.doctype.budget.budget import BudgetError, get_actual_expense
|
||||||
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
||||||
from erpnext.accounts.utils import get_fiscal_year
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
|
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
|
||||||
|
from erpnext.tests.utils import ERPNextTestSuite
|
||||||
|
|
||||||
|
|
||||||
class TestBudget(IntegrationTestCase):
|
class TestBudget(ERPNextTestSuite):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
cls.make_monthly_distribution()
|
cls.make_monthly_distribution()
|
||||||
cls.make_projects()
|
cls.make_projects()
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def make_monthly_distribution(cls):
|
|
||||||
records = [
|
|
||||||
{
|
|
||||||
"doctype": "Monthly Distribution",
|
|
||||||
"distribution_id": "_Test Distribution",
|
|
||||||
"fiscal_year": "_Test Fiscal Year 2013",
|
|
||||||
"percentages": [
|
|
||||||
{"month": "January", "percentage_allocation": "8"},
|
|
||||||
{"month": "February", "percentage_allocation": "8"},
|
|
||||||
{"month": "March", "percentage_allocation": "8"},
|
|
||||||
{"month": "April", "percentage_allocation": "8"},
|
|
||||||
{"month": "May", "percentage_allocation": "8"},
|
|
||||||
{"month": "June", "percentage_allocation": "8"},
|
|
||||||
{"month": "July", "percentage_allocation": "8"},
|
|
||||||
{"month": "August", "percentage_allocation": "8"},
|
|
||||||
{"month": "September", "percentage_allocation": "8"},
|
|
||||||
{"month": "October", "percentage_allocation": "8"},
|
|
||||||
{"month": "November", "percentage_allocation": "10"},
|
|
||||||
{"month": "December", "percentage_allocation": "10"},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
]
|
|
||||||
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")})
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def make_projects(cls):
|
|
||||||
records = [
|
|
||||||
{
|
|
||||||
"doctype": "Project",
|
|
||||||
"company": "_Test Company",
|
|
||||||
"project_name": "_Test Project",
|
|
||||||
"status": "Open",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
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 test_monthly_budget_crossed_ignore(self):
|
def test_monthly_budget_crossed_ignore(self):
|
||||||
set_total_expense_zero(nowdate(), "cost_center")
|
set_total_expense_zero(nowdate(), "cost_center")
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from typing import Any, NewType
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.core.doctype.report.report import get_report_module_dotted_path
|
from frappe.core.doctype.report.report import get_report_module_dotted_path
|
||||||
|
from frappe.tests import IntegrationTestCase
|
||||||
|
|
||||||
ReportFilters = dict[str, Any]
|
ReportFilters = dict[str, Any]
|
||||||
ReportName = NewType("ReportName", str)
|
ReportName = NewType("ReportName", str)
|
||||||
@@ -114,3 +115,59 @@ def if_lending_app_not_installed(function):
|
|||||||
return
|
return
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
class ERPNextTestSuite(IntegrationTestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def make_monthly_distribution(cls):
|
||||||
|
records = [
|
||||||
|
{
|
||||||
|
"doctype": "Monthly Distribution",
|
||||||
|
"distribution_id": "_Test Distribution",
|
||||||
|
"fiscal_year": "_Test Fiscal Year 2013",
|
||||||
|
"percentages": [
|
||||||
|
{"month": "January", "percentage_allocation": "8"},
|
||||||
|
{"month": "February", "percentage_allocation": "8"},
|
||||||
|
{"month": "March", "percentage_allocation": "8"},
|
||||||
|
{"month": "April", "percentage_allocation": "8"},
|
||||||
|
{"month": "May", "percentage_allocation": "8"},
|
||||||
|
{"month": "June", "percentage_allocation": "8"},
|
||||||
|
{"month": "July", "percentage_allocation": "8"},
|
||||||
|
{"month": "August", "percentage_allocation": "8"},
|
||||||
|
{"month": "September", "percentage_allocation": "8"},
|
||||||
|
{"month": "October", "percentage_allocation": "8"},
|
||||||
|
{"month": "November", "percentage_allocation": "10"},
|
||||||
|
{"month": "December", "percentage_allocation": "10"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
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")})
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def make_projects(cls):
|
||||||
|
records = [
|
||||||
|
{
|
||||||
|
"doctype": "Project",
|
||||||
|
"company": "_Test Company",
|
||||||
|
"project_name": "_Test Project",
|
||||||
|
"status": "Open",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
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")}))
|
||||||
|
|||||||
Reference in New Issue
Block a user