seitime-frappe/frappe/tests/test_test_utils.py
Ankush Menat caf415f13e
feat: get_settings (#32821)
* feat: get_settings

get_cached_value doesn't work well with singles because you either need
to pass `None` or repeat doctype name... both are awekward and easy to
shoot yourself in foot with.

* refactor: Use cached settings
2025-06-06 18:34:17 +05:30

45 lines
1.4 KiB
Python

from datetime import timedelta
import frappe
from frappe.tests import IntegrationTestCase
from frappe.utils.data import now_datetime
class TestTestUtils(IntegrationTestCase):
SHOW_TRANSACTION_COMMIT_WARNINGS = True
def test_document_assertions(self):
currency = frappe.new_doc("Currency")
currency.currency_name = "STONKS"
currency.smallest_currency_fraction_value = 0.420_001
currency.save()
self.assertDocumentEqual(currency.as_dict(), currency)
def test_thread_locals(self):
frappe.flags.temp_flag_to_be_discarded = True
def test_temp_setting_changes(self):
current_setting = frappe.get_system_settings("logout_on_password_reset")
with IntegrationTestCase.change_settings(
"System Settings", {"logout_on_password_reset": int(not current_setting)}
):
updated_settings = frappe.get_settings("System Settings", "logout_on_password_reset")
self.assertNotEqual(current_setting, updated_settings)
restored_settings = frappe.get_settings("System Settings", "logout_on_password_reset")
self.assertEqual(current_setting, restored_settings)
def test_time_freezing(self):
now = now_datetime()
tomorrow = now + timedelta(days=1)
with self.freeze_time(tomorrow):
self.assertEqual(now_datetime(), tomorrow)
def tearDownModule():
"""assertions for ensuring tests didn't leave state behind"""
assert "temp_flag_to_be_discarded" not in frappe.flags
assert not frappe.db.exists("Currency", "STONKS")