* 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
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
# License: MIT. See LICENSE
|
|
import frappe
|
|
from frappe.tests import IntegrationTestCase
|
|
from frappe.utils.data import add_to_date, today
|
|
|
|
|
|
class TestDocumentLocks(IntegrationTestCase):
|
|
def test_locking(self):
|
|
todo = frappe.get_doc(doctype="ToDo", description="test").insert()
|
|
todo_1 = frappe.get_doc("ToDo", todo.name)
|
|
|
|
todo.lock()
|
|
self.assertRaises(frappe.DocumentLockedError, todo_1.lock)
|
|
todo.unlock()
|
|
|
|
todo_1.lock()
|
|
self.assertRaises(frappe.DocumentLockedError, todo.lock)
|
|
todo_1.unlock()
|
|
|
|
def test_operations_on_locked_documents(self):
|
|
todo = frappe.get_doc(doctype="ToDo", description="testing operations").insert()
|
|
todo.lock()
|
|
|
|
with self.assertRaises(frappe.DocumentLockedError):
|
|
todo.description = "Random"
|
|
todo.save()
|
|
|
|
# Checking for persistant locks across all instances.
|
|
doc = frappe.get_doc("ToDo", todo.name)
|
|
self.assertEqual(doc.is_locked, True)
|
|
|
|
with self.assertRaises(frappe.DocumentLockedError):
|
|
doc.description = "Random"
|
|
doc.save()
|
|
|
|
doc.unlock()
|
|
self.assertEqual(doc.is_locked, False)
|
|
self.assertEqual(todo.is_locked, False)
|
|
|
|
def test_locks_auto_expiry(self):
|
|
todo = frappe.get_doc(doctype="ToDo", description=frappe.generate_hash()).insert()
|
|
todo.lock()
|
|
|
|
self.assertRaises(frappe.DocumentLockedError, todo.lock)
|
|
|
|
with self.freeze_time(add_to_date(today(), days=3)):
|
|
todo.lock()
|