[minor] optimized webnotes.has_permission

This commit is contained in:
Anand Doshi 2013-11-13 14:44:28 +05:30
parent 9259f6e5ce
commit cd3914a06f

View File

@ -8,7 +8,7 @@ from hr.doctype.leave_application.leave_application import LeaveDayBlockedError,
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 @@ class TestLeaveApplication(unittest.TestCase):
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 @@ class TestLeaveApplication(unittest.TestCase):
"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 @@ class TestLeaveApplication(unittest.TestCase):
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 @@ class TestLeaveApplication(unittest.TestCase):
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 @@ class TestLeaveApplication(unittest.TestCase):
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 @@ class TestLeaveApplication(unittest.TestCase):
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 @@ class TestLeaveApplication(unittest.TestCase):
# 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 @@ class TestLeaveApplication(unittest.TestCase):
# 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 @@ class TestLeaveApplication(unittest.TestCase):
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,