chore: cleanup frappe.connect invocations
This commit is contained in:
parent
e7284be5a3
commit
c57bc94ead
7 changed files with 9 additions and 33 deletions
|
|
@ -772,12 +772,11 @@ def run_tests(
|
|||
click.secho(f"bench --site {site} set-config allow_tests true", fg="green")
|
||||
return
|
||||
|
||||
frappe.init(site=site)
|
||||
|
||||
frappe.flags.skip_before_tests = skip_before_tests
|
||||
frappe.flags.skip_test_records = skip_test_records
|
||||
|
||||
ret = frappe.test_runner.main(
|
||||
site,
|
||||
app,
|
||||
module,
|
||||
doctype,
|
||||
|
|
|
|||
|
|
@ -11,10 +11,3 @@ class TestForm(FrappeTestCase):
|
|||
results = get_linked_docs("Role", "System Manager", linkinfo=get_linked_doctypes("Role"))
|
||||
self.assertTrue("User" in results)
|
||||
self.assertTrue("DocType" in results)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import unittest
|
||||
|
||||
frappe.connect()
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@ from frappe.utils.dashboard import sync_dashboards
|
|||
from frappe.utils.synchronization import filelock
|
||||
|
||||
|
||||
def _is_scheduler_enabled() -> bool:
|
||||
def _is_scheduler_enabled(site) -> bool:
|
||||
enable_scheduler = False
|
||||
try:
|
||||
frappe.init(site=site)
|
||||
frappe.connect()
|
||||
enable_scheduler = cint(frappe.db.get_single_value("System Settings", "enable_scheduler"))
|
||||
except Exception:
|
||||
|
|
@ -78,7 +79,7 @@ def _new_site(
|
|||
|
||||
try:
|
||||
# enable scheduler post install?
|
||||
enable_scheduler = _is_scheduler_enabled()
|
||||
enable_scheduler = _is_scheduler_enabled(site)
|
||||
except Exception:
|
||||
enable_scheduler = False
|
||||
|
||||
|
|
|
|||
|
|
@ -41,9 +41,6 @@ def send_email(success, service_name, doctype, email_field, error_status=None):
|
|||
|
||||
|
||||
def get_recipients(doctype, email_field):
|
||||
if not frappe.db:
|
||||
frappe.connect()
|
||||
|
||||
return split_emails(frappe.db.get_value(doctype, None, email_field))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ def xmlrunner_wrapper(output):
|
|||
|
||||
|
||||
def main(
|
||||
site=None,
|
||||
app=None,
|
||||
module=None,
|
||||
doctype=None,
|
||||
|
|
@ -53,6 +54,10 @@ def main(
|
|||
):
|
||||
global unittest_runner
|
||||
|
||||
frappe.init(site=site)
|
||||
if not frappe.db:
|
||||
frappe.connect()
|
||||
|
||||
if doctype_list_path:
|
||||
app, doctype_list_path = doctype_list_path.split(os.path.sep, 1)
|
||||
with open(frappe.get_app_path(app, doctype_list_path)) as f:
|
||||
|
|
@ -69,9 +74,6 @@ def main(
|
|||
frappe.flags.print_messages = verbose
|
||||
frappe.flags.in_test = True
|
||||
|
||||
if not frappe.db:
|
||||
frappe.connect()
|
||||
|
||||
# workaround! since there is no separate test db
|
||||
frappe.clear_cache()
|
||||
scheduler_disabled_by_user = frappe.utils.scheduler.is_scheduler_disabled(verbose=False)
|
||||
|
|
@ -329,9 +331,6 @@ def _add_test(app, path, filename, verbose, test_suite=None):
|
|||
|
||||
|
||||
def make_test_records(doctype, verbose=0, force=False, commit=False):
|
||||
if not frappe.db:
|
||||
frappe.connect()
|
||||
|
||||
if frappe.flags.skip_test_records:
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -100,10 +100,3 @@ class TestFmtMoney(FrappeTestCase):
|
|||
frappe.db.set_value("Currency", "JPY", "symbol_on_right", 1)
|
||||
self.assertEqual(fmt_money(100.0, format="#,###.##", currency="JPY"), "100.00 ¥")
|
||||
self.assertEqual(fmt_money(100.0, format="#,###.##", currency="USD"), "$ 100.00")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import unittest
|
||||
|
||||
frappe.connect()
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -239,9 +239,6 @@ def get_translation_dict_from_file(path, lang, app, throw=False) -> dict[str, st
|
|||
|
||||
|
||||
def get_user_translations(lang):
|
||||
if not frappe.db:
|
||||
frappe.connect()
|
||||
|
||||
def _read_from_db():
|
||||
user_translations = {}
|
||||
translations = frappe.get_all(
|
||||
|
|
@ -1054,9 +1051,6 @@ def get_all_languages(with_language_name: bool = False) -> list:
|
|||
def get_all_language_with_name():
|
||||
return frappe.get_all("Language", ["language_code", "language_name"], {"enabled": 1})
|
||||
|
||||
if not frappe.db:
|
||||
frappe.connect()
|
||||
|
||||
if with_language_name:
|
||||
return frappe.cache.get_value("languages_with_name", get_all_language_with_name)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue