mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-07 15:25:19 +00:00
test: automated test for running all stock reports (#27510)
* test: automated test for running all stock reports
These test do not assert correctness, they just check that "execute" function
is working with sane filters.
* test: make report execution test modular
(cherry picked from commit 70c203d19e)
# Conflicts:
# erpnext/stock/report/test_reports.py
# erpnext/tests/utils.py
This commit is contained in:
@@ -37,6 +37,7 @@ REPORT_FILTER_TEST_CASES: List[Tuple[ReportName, ReportFilters]] = [
|
||||
},
|
||||
),
|
||||
("Warehouse wise Item Balance Age and Value", {"_optional": True}),
|
||||
<<<<<<< HEAD
|
||||
(
|
||||
"Item Variant Details",
|
||||
{
|
||||
@@ -54,6 +55,12 @@ REPORT_FILTER_TEST_CASES: List[Tuple[ReportName, ReportFilters]] = [
|
||||
("Stock Ledger Invariant Check", {"warehouse": "_Test Warehouse - _TC", "item": "_Test Item"}),
|
||||
("FIFO Queue vs Qty After Transaction Comparison", {"warehouse": "_Test Warehouse - _TC"}),
|
||||
("FIFO Queue vs Qty After Transaction Comparison", {"item_group": "All Item Groups"}),
|
||||
=======
|
||||
("Item Variant Details", {"item": "_Test Variant Item",}),
|
||||
("Total Stock Summary", {"group_by": "warehouse",}),
|
||||
("Batch Item Expiry Status", {}),
|
||||
("Stock Ageing", {"range1": 30, "range2": 60, "range3": 90, "_optional": True}),
|
||||
>>>>>>> 70c203d19e (test: automated test for running all stock reports (#27510))
|
||||
]
|
||||
|
||||
OPTIONAL_FILTERS = {
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
import copy
|
||||
from contextlib import contextmanager
|
||||
>>>>>>> 70c203d19e (test: automated test for running all stock reports (#27510))
|
||||
from typing import Any, Dict, NewType, Optional
|
||||
|
||||
import frappe
|
||||
@@ -81,6 +86,43 @@ def execute_script_report(
|
||||
)
|
||||
report_filters = frappe._dict(default_filters).copy().update(filters)
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
finally:
|
||||
# restore settings
|
||||
settings = frappe.get_doc(doctype)
|
||||
for key, value in previous_settings.items():
|
||||
setattr(settings, key, value)
|
||||
settings.save()
|
||||
|
||||
|
||||
def execute_script_report(
|
||||
report_name: ReportName,
|
||||
module: str,
|
||||
filters: ReportFilters,
|
||||
default_filters: Optional[ReportFilters] = None,
|
||||
optional_filters: Optional[ReportFilters] = None
|
||||
):
|
||||
"""Util for testing execution of a report with specified filters.
|
||||
|
||||
Tests the execution of report with default_filters + filters.
|
||||
Tests the execution using optional_filters one at a time.
|
||||
|
||||
Args:
|
||||
report_name: Human readable name of report (unscrubbed)
|
||||
module: module to which report belongs to
|
||||
filters: specific values for filters
|
||||
default_filters: default values for filters such as company name.
|
||||
optional_filters: filters which should be tested one at a time in addition to default filters.
|
||||
"""
|
||||
|
||||
if default_filters is None:
|
||||
default_filters = {}
|
||||
|
||||
report_execute_fn = frappe.get_attr(get_report_module_dotted_path(module, report_name) + ".execute")
|
||||
report_filters = frappe._dict(default_filters).copy().update(filters)
|
||||
|
||||
>>>>>>> 70c203d19e (test: automated test for running all stock reports (#27510))
|
||||
report_data = report_execute_fn(report_filters)
|
||||
|
||||
if optional_filters:
|
||||
|
||||
Reference in New Issue
Block a user