seitime-frappe/frappe/tests/test_listview.py
Gavin D'souza e407b78506 chore: Drop dead and deprecated code
* Remove six for PY2 compatability since our dependencies are not, PY2
  is legacy.
* Removed usages of utils from future/past libraries since they are
  deprecated. This includes 'from __future__ ...' and 'from past...'
  statements.
* Removed compatibility imports for PY2, switched from six imports to
  standard library imports.
* Removed utils code blocks that handle operations depending on PY2/3
  versions.
* Removed 'from __future__ ...' lines from templates/code generators
* Used PY3 syntaxes in place of PY2 compatible blocks. eg: metaclass
2021-05-26 15:31:29 +05:30

61 lines
No EOL
2.6 KiB
Python

# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
import unittest
import frappe
import json
from frappe.desk.listview import get_list_settings, set_list_settings, get_group_by_count
class TestListView(unittest.TestCase):
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_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_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_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_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)