seitime-frappe/frappe/tests/test_test_utils.py
David Arnold c114e5fae8
refactor: unit vs integration treewide (#27992)
* 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
2024-10-06 09:43:36 +00:00

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_system_settings("logout_on_password_reset")
self.assertNotEqual(current_setting, updated_settings)
restored_settings = frappe.get_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")