* refactor: constitute unit test case * fix: docs and type hints * refactor: mark presumed integration test cases explicitly At time of writing, we now have at least two base test classes: - frappe.tests.UnitTestCase - frappe.tests.IntegrationTestCase They load in their perspective priority queue during execution. Probably more to come for more efficient queing and scheduling. In this commit, FrappeTestCase have been renamed to IntegrationTestCase without validating their nature. * feat: Move test-related functions from test_runner.py to tests/utils.py * refactor: add bare UnitTestCase to all doctype tests This should teach LLMs in their next pass that the distinction matters and that this is widely used framework practice
96 lines
3.5 KiB
Python
96 lines
3.5 KiB
Python
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
|
|
# License: MIT. See LICENSE
|
|
import json
|
|
|
|
import frappe
|
|
from frappe.desk.listview import get_group_by_count, get_list_settings, set_list_settings
|
|
from frappe.desk.reportview import get
|
|
from frappe.tests import IntegrationTestCase
|
|
|
|
|
|
class TestListView(IntegrationTestCase):
|
|
def setUp(self):
|
|
if frappe.db.exists("List View Settings", "DocType"):
|
|
frappe.delete_doc("List View Settings", "DocType")
|
|
|
|
def test_get_list_settings_without_settings(self):
|
|
self.assertIsNone(get_list_settings("DocType"), None)
|
|
|
|
def test_get_list_settings_with_default_settings(self):
|
|
frappe.get_doc({"doctype": "List View Settings", "name": "DocType"}).insert()
|
|
settings = get_list_settings("DocType")
|
|
self.assertIsNotNone(settings)
|
|
|
|
self.assertEqual(settings.disable_auto_refresh, 0)
|
|
self.assertEqual(settings.disable_count, 0)
|
|
self.assertEqual(settings.disable_comment_count, 0)
|
|
self.assertEqual(settings.disable_sidebar_stats, 0)
|
|
|
|
def test_get_list_settings_with_non_default_settings(self):
|
|
frappe.get_doc({"doctype": "List View Settings", "name": "DocType", "disable_count": 1}).insert()
|
|
settings = get_list_settings("DocType")
|
|
self.assertIsNotNone(settings)
|
|
|
|
self.assertEqual(settings.disable_auto_refresh, 0)
|
|
self.assertEqual(settings.disable_count, 1)
|
|
self.assertEqual(settings.disable_comment_count, 0)
|
|
self.assertEqual(settings.disable_sidebar_stats, 0)
|
|
|
|
def test_set_list_settings_without_settings(self):
|
|
set_list_settings("DocType", json.dumps({}))
|
|
settings = frappe.get_doc("List View Settings", "DocType")
|
|
|
|
self.assertEqual(settings.disable_auto_refresh, 0)
|
|
self.assertEqual(settings.disable_count, 0)
|
|
self.assertEqual(settings.disable_comment_count, 0)
|
|
self.assertEqual(settings.disable_sidebar_stats, 0)
|
|
|
|
def test_set_list_settings_with_existing_settings(self):
|
|
frappe.get_doc({"doctype": "List View Settings", "name": "DocType", "disable_count": 1}).insert()
|
|
set_list_settings("DocType", json.dumps({"disable_count": 0, "disable_auto_refresh": 1}))
|
|
settings = frappe.get_doc("List View Settings", "DocType")
|
|
|
|
self.assertEqual(settings.disable_auto_refresh, 1)
|
|
self.assertEqual(settings.disable_count, 0)
|
|
self.assertEqual(settings.disable_comment_count, 0)
|
|
self.assertEqual(settings.disable_sidebar_stats, 0)
|
|
|
|
def test_list_view_child_table_filter_with_created_by_filter(self):
|
|
if frappe.db.exists("Note", "Test created by filter with child table filter"):
|
|
frappe.delete_doc("Note", "Test created by filter with child table filter")
|
|
|
|
doc = frappe.get_doc(
|
|
{"doctype": "Note", "title": "Test created by filter with child table filter", "public": 1}
|
|
)
|
|
doc.append("seen_by", {"user": "Administrator"})
|
|
doc.insert()
|
|
|
|
data = {
|
|
d.name: d.count
|
|
for d in get_group_by_count("Note", '[["Note Seen By","user","=","Administrator"]]', "owner")
|
|
}
|
|
self.assertEqual(data["Administrator"], 1)
|
|
|
|
def test_get_group_by_invalid_field(self):
|
|
self.assertRaises(
|
|
ValueError,
|
|
get_group_by_count,
|
|
"Note",
|
|
'[["Note Seen By","user","=","Administrator"]]',
|
|
"invalid_field",
|
|
)
|
|
|
|
def test_list_view_comment_count(self):
|
|
frappe.form_dict.doctype = "DocType"
|
|
frappe.form_dict.limit = "1"
|
|
frappe.form_dict.fields = [
|
|
"`tabDocType`.`name`",
|
|
]
|
|
|
|
for with_comment_count in (1, True, "1"):
|
|
frappe.form_dict.with_comment_count = with_comment_count
|
|
self.assertEqual(len(get()["values"][0]), 2)
|
|
|
|
for with_comment_count in (0, False, "0", None):
|
|
frappe.form_dict.with_comment_count = with_comment_count
|
|
self.assertEqual(len(get()["values"][0]), 1)
|