Merge pull request #17810 from gavindsouza/cov-tests-2

test: Update coverage exclusions
This commit is contained in:
gavin 2022-08-12 13:39:07 +05:30 committed by GitHub
commit bfef20752a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 49 deletions

View file

@ -8,10 +8,8 @@ from frappe.desk.moduleview import (
)
def get_modules_from_all_apps_for_user(user=None):
if not user:
user = frappe.session.user
def get_modules_from_all_apps_for_user(user: str = None) -> list[dict]:
user = user or frappe.session.user
all_modules = get_modules_from_all_apps()
global_blocked_modules = frappe.get_doc("User", "Administrator").get_blocked_modules()
user_blocked_modules = frappe.get_doc("User", user).get_blocked_modules()
@ -61,7 +59,7 @@ def get_all_empty_tables_by_module():
empty_tables_by_module = {}
for doctype, module in results:
if "tab" + doctype in empty_tables:
if f"tab{doctype}" in empty_tables:
if module in empty_tables_by_module:
empty_tables_by_module[module].append(doctype)
else:

View file

@ -32,11 +32,10 @@ def get_things_todo(as_list=False):
if as_list:
return data
else:
return data[0][0]
return data[0][0]
def get_todays_events(as_list=False):
def get_todays_events(as_list: bool = False):
"""Returns a count of todays events in calendar"""
from frappe.desk.doctype.event.event import get_events
from frappe.utils import nowdate

View file

@ -24,6 +24,15 @@ STANDARD_EXCLUSIONS = [
"*/patches/*",
]
# tested via commands' test suite
TESTED_VIA_CLI = [
"*/frappe/installer.py",
"*/frappe/build.py",
"*/frappe/database/__init__.py",
"*/frappe/database/db_manager.py",
"*/frappe/database/**/setup_db.py",
]
FRAPPE_EXCLUSIONS = [
"*/tests/*",
"*/commands/*",
@ -33,7 +42,7 @@ FRAPPE_EXCLUSIONS = [
"*frappe/setup.py",
"*/doctype/*/*_dashboard.py",
"*/patches/*",
]
] + TESTED_VIA_CLI
class CodeCoverage:

View file

@ -54,16 +54,3 @@ def get_db(host=None, user=None, password=None, port=None, read_only=False):
return frappe.database.mariadb.database.MariaDBDatabase(
host, user, password, port=port, read_only=read_only
)
def setup_help_database(help_db_name):
import frappe
if frappe.conf.db_type == "postgres":
import frappe.database.postgres.setup_db
return frappe.database.postgres.setup_db.setup_help_database(help_db_name)
else:
import frappe.database.mariadb.setup_db
return frappe.database.mariadb.setup_db.setup_help_database(help_db_name)

View file

@ -63,23 +63,6 @@ def setup_database(force, source_sql, verbose, no_mariadb_socket=False):
bootstrap_database(db_name, verbose, source_sql)
def setup_help_database(help_db_name):
dbman = DbManager(get_root_connection(frappe.flags.root_login, frappe.flags.root_password))
dbman.drop_database(help_db_name)
# make database
if not help_db_name in dbman.get_database_list():
try:
dbman.create_user(help_db_name, help_db_name)
except Exception as e:
# user already exists
if e.args[0] != 1396:
raise
dbman.create_database(help_db_name)
dbman.grant_all_privileges(help_db_name, help_db_name)
dbman.flush_privileges()
def drop_user_and_database(db_name, root_login, root_password):
frappe.local.db = get_root_connection(root_login, root_password)
dbman = DbManager(frappe.local.db)

View file

@ -75,15 +75,6 @@ def import_db_from_sql(source_sql=None, verbose=False):
)
def setup_help_database(help_db_name):
root_conn = get_root_connection(frappe.flags.root_login, frappe.flags.root_password)
root_conn.sql(f"DROP DATABASE IF EXISTS `{help_db_name}`")
root_conn.sql(f"DROP USER IF EXISTS {help_db_name}")
root_conn.sql(f"CREATE DATABASE `{help_db_name}`")
root_conn.sql(f"CREATE user {help_db_name} password '{help_db_name}'")
root_conn.sql("GRANT ALL PRIVILEGES ON DATABASE `{0}` TO {0}".format(help_db_name))
def get_root_connection(root_login=None, root_password=None):
if not frappe.local.flags.root_connection:
if not root_login:

View file

@ -205,7 +205,7 @@ def send_event_digest():
@frappe.whitelist()
def get_events(start, end, user=None, for_reminder=False, filters=None):
def get_events(start, end, user=None, for_reminder=False, filters=None) -> list[frappe._dict]:
if not user:
user = frappe.session.user

View file

@ -0,0 +1,17 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE
import unittest
import frappe
from frappe.config import get_modules_from_all_apps_for_user
class TestConfig(unittest.TestCase):
def test_get_modules(self):
frappe_modules = frappe.get_all("Module Def", filters={"app_name": "frappe"}, pluck="name")
all_modules_data = get_modules_from_all_apps_for_user()
first_module_entry = all_modules_data[0]
all_modules = [x["module_name"] for x in all_modules_data]
self.assertIn("links", first_module_entry)
self.assertIsInstance(all_modules_data, list)
self.assertFalse([x for x in frappe_modules if x not in all_modules])