test: automated test for running all stock reports (#27510) (#27522)

* 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)

Co-authored-by: Ankush Menat <ankush@iwebnotes.com>
This commit is contained in:
Frappe PR Bot
2021-09-15 22:23:07 +05:30
committed by GitHub
parent 0fb112107f
commit 8b3ef8e96e
2 changed files with 104 additions and 0 deletions

View File

@@ -3,8 +3,13 @@
import copy
from contextlib import contextmanager
from typing import Any, Dict, NewType, Optional
import frappe
from frappe.core.doctype.report.report import get_report_module_dotted_path
ReportFilters = Dict[str, Any]
ReportName = NewType("ReportName", str)
def create_test_contact_and_address():
@@ -78,3 +83,39 @@ def change_settings(doctype, settings_dict):
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)
report_data = report_execute_fn(report_filters)
if optional_filters:
for key, value in optional_filters.items():
filter_with_optional_param = report_filters.copy().update({key: value})
report_execute_fn(filter_with_optional_param)
return report_data