# Copyright (c) 2015, Xhive Global Ltd. and Contributors
# License: MIT. See LICENSE
import xhiveframework
from xhiveframework.tests.utils import XhiveFrameworkTestCase


class TestDocumentLocks(XhiveFrameworkTestCase):
	def test_locking(self):
		todo = xhiveframework.get_doc(dict(doctype="ToDo", description="test")).insert()
		todo_1 = xhiveframework.get_doc("ToDo", todo.name)

		todo.lock()
		self.assertRaises(xhiveframework.DocumentLockedError, todo_1.lock)
		todo.unlock()

		todo_1.lock()
		self.assertRaises(xhiveframework.DocumentLockedError, todo.lock)
		todo_1.unlock()
