[minor] optimized webnotes.has_permission
diff --git a/hr/doctype/leave_application/test_leave_application.py b/hr/doctype/leave_application/test_leave_application.py
index 7a900e3..48b502e 100644
--- a/hr/doctype/leave_application/test_leave_application.py
+++ b/hr/doctype/leave_application/test_leave_application.py
@@ -8,7 +8,7 @@
class TestLeaveApplication(unittest.TestCase):
def tearDown(self):
- webnotes.session.user = "Administrator"
+ webnotes.set_user("Administrator")
def _clear_roles(self):
webnotes.conn.sql("""delete from `tabUserRole` where parent in
@@ -19,7 +19,7 @@
def _add_employee_leave_approver(self, employee, leave_approver):
temp_session_user = webnotes.session.user
- webnotes.session.user = "Administrator"
+ webnotes.set_user("Administrator")
employee = webnotes.bean("Employee", employee)
employee.doclist.append({
"doctype": "Employee Leave Approver",
@@ -27,7 +27,7 @@
"leave_approver": leave_approver
})
employee.save()
- webnotes.session.user = temp_session_user
+ webnotes.set_user(temp_session_user)
def get_application(self, doclist):
application = webnotes.bean(copy=doclist)
@@ -49,7 +49,7 @@
application.doc.status = "Approved"
self.assertRaises(LeaveDayBlockedError, application.submit)
- webnotes.session.user = "test1@example.com"
+ webnotes.set_user("test1@example.com")
# clear other applications
webnotes.conn.sql("delete from `tabLeave Application`")
@@ -65,7 +65,7 @@
add_role("test@example.com", "Employee")
add_role("test2@example.com", "Leave Approver")
- webnotes.session.user = "test@example.com"
+ webnotes.set_user("test@example.com")
application = self.get_application(test_records[1])
application.doc.leave_approver = "test2@example.com"
application.insert()
@@ -89,10 +89,10 @@
webnotes.conn.set_value("Employee", "_T-Employee-0002", "department",
"_Test Department")
- webnotes.session.user = "test1@example.com"
+ webnotes.set_user("test1@example.com")
application.insert()
- webnotes.session.user = "test@example.com"
+ webnotes.set_user("test@example.com")
application.doc.status = "Approved"
self.assertRaises(LeaveDayBlockedError, application.submit)
@@ -116,13 +116,13 @@
self._clear_applications()
# create leave application as Employee
- webnotes.session.user = "test@example.com"
+ webnotes.set_user("test@example.com")
application = self.get_application(test_records[1])
application.doc.leave_approver = "test1@example.com"
application.insert()
# submit leave application by Leave Approver
- webnotes.session.user = "test1@example.com"
+ webnotes.set_user("test1@example.com")
application.doc.status = "Approved"
application.submit()
self.assertEqual(webnotes.conn.get_value("Leave Application", application.doc.name,
@@ -139,7 +139,7 @@
# TODO - add test2@example.com leave approver in employee's leave approvers list
application = self.get_application(test_records[1])
- webnotes.session.user = "test@example.com"
+ webnotes.set_user("test@example.com")
application.doc.leave_approver = "test1@example.com"
self.assertRaises(InvalidLeaveApproverError, application.insert)
@@ -153,11 +153,11 @@
# create leave application as employee
# but submit as invalid leave approver - should raise exception
- webnotes.session.user = "test@example.com"
+ webnotes.set_user("test@example.com")
application = self.get_application(test_records[1])
application.doc.leave_approver = "test2@example.com"
application.insert()
- webnotes.session.user = "test1@example.com"
+ webnotes.set_user("test1@example.com")
application.doc.status = "Approved"
from webnotes.model.bean import BeanPermissionError
@@ -173,13 +173,13 @@
original_department = webnotes.conn.get_value("Employee", "_T-Employee-0001", "department")
webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", None)
- webnotes.session.user = "test@example.com"
+ webnotes.set_user("test@example.com")
application = self.get_application(test_records[1])
application.doc.leave_approver = "test2@example.com"
application.insert()
# change to valid leave approver and try to submit leave application
- webnotes.session.user = "test2@example.com"
+ webnotes.set_user("test2@example.com")
application.doc.status = "Approved"
application.submit()
self.assertEqual(webnotes.conn.get_value("Leave Application", application.doc.name,