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