Example #1
0
	def test_event_list(self):
		webnotes.set_user("*****@*****.**")
		res = webnotes.get_list("Event", filters=[["Event", "subject", "like", "_Test Event%"]], fields=["name", "subject"])
		self.assertEquals(len(res), 2)
		subjects = [r.subject for r in res]
		self.assertTrue("_Test Event 1" in subjects)
		self.assertTrue("_Test Event 3" in subjects)
		self.assertFalse("_Test Event 2" in subjects)
	def test_not_allowed_to_remove_self(self):
		self.add_restriction_to_user2()
		defname = get_properties("*****@*****.**", "Blog Post", "_test-blog-post")[0].name

		webnotes.set_user("*****@*****.**")

		# user cannot remove their own restriction
		self.assertRaises(webnotes.PermissionError, remove, 
			"*****@*****.**", defname, "Blog Post", "_test-blog-post")
	def test_owner_match_report(self):
		webnotes.conn.sql("""update tabDocPerm set `restricted`=1 where parent='Blog Post' 
			and ifnull(permlevel,0)=0""")
		webnotes.clear_cache(doctype="Blog Post")

		webnotes.set_user("*****@*****.**")

		names = [d.name for d in webnotes.get_list("Blog Post", fields=["name", "owner"])]
		self.assertTrue("_test-blog-post" in names)
		self.assertFalse("_test-blog-post-1" in names)
	def test_owner_match_bean(self):
		self.add_restricted_on_blogger()

		webnotes.set_user("*****@*****.**")

		post = webnotes.bean("Blog Post", "_test-blog-post")
		self.assertTrue(post.has_read_perm())

		post1 = webnotes.bean("Blog Post", "_test-blog-post-1")
		self.assertFalse(post1.has_read_perm())
Example #5
0
	def _add_employee_leave_approver(self, employee, leave_approver):
		temp_session_user = webnotes.session.user
		webnotes.set_user("Administrator")
		employee = webnotes.bean("Employee", employee)
		employee.doclist.append({
			"doctype": "Employee Leave Approver",
			"parentfield": "employee_leave_approvers",
			"leave_approver": leave_approver
		})
		employee.save()
		webnotes.set_user(temp_session_user)
	def test_not_allowed_to_restrict(self):
		self.add_restriction_to_user2()

		webnotes.set_user("*****@*****.**")

		# user can only access restricted blog post
		bean = webnotes.bean("Blog Post", "_test-blog-post")
		self.assertTrue(bean.has_read_perm())

		# and not this one
		bean = webnotes.bean("Blog Post", "_test-blog-post-1")
		self.assertFalse(bean.has_read_perm())
	def setUp(self):
		webnotes.conn.sql("""update tabDocPerm set `restricted`=0 where parent='Blog Post' 
			and ifnull(permlevel,0)=0""")
		webnotes.conn.sql("""update `tabBlog Post` set owner='*****@*****.**'
			where name='_test-blog-post'""")

		webnotes.clear_cache(doctype="Blog Post")
		
		profile = webnotes.bean("Profile", "*****@*****.**")
		profile.get_controller().add_roles("Website Manager")
		
		profile = webnotes.bean("Profile", "*****@*****.**")
		profile.get_controller().add_roles("Blogger")
		
		webnotes.set_user("*****@*****.**")
Example #8
0
	def _test_leave_approval_basic_case(self):
		self._clear_applications()
		
		# create leave application as Employee
		webnotes.set_user("*****@*****.**")
		application = self.get_application(test_records[1])
		application.doc.leave_approver = "*****@*****.**"
		application.insert()
		
		# submit leave application by Leave Approver
		webnotes.set_user("*****@*****.**")
		application.doc.status = "Approved"
		application.submit()
		self.assertEqual(webnotes.conn.get_value("Leave Application", application.doc.name,
			"docstatus"), 1)
Example #9
0
	def test_overlap(self):
		self._clear_roles()
		self._clear_applications()
		
		from webnotes.profile import add_role
		add_role("*****@*****.**", "Employee")
		add_role("*****@*****.**", "Leave Approver")
		
		webnotes.set_user("*****@*****.**")
		application = self.get_application(test_records[1])
		application.doc.leave_approver = "*****@*****.**"
		application.insert()
		
		application = self.get_application(test_records[1])
		application.doc.leave_approver = "*****@*****.**"
		self.assertRaises(OverlapError, application.insert)
Example #10
0
	def _test_leave_approval_invalid_leave_approver_insert(self):
		from hr.doctype.leave_application.leave_application import InvalidLeaveApproverError
		
		self._clear_applications()
		
		# add a different leave approver in the employee's list
		# should raise exception if not a valid leave approver
		self._add_employee_leave_approver("_T-Employee-0001", "*****@*****.**")
		
		# TODO - add [email protected] leave approver in employee's leave approvers list
		application = self.get_application(test_records[1])
		webnotes.set_user("*****@*****.**")
		
		application.doc.leave_approver = "*****@*****.**"
		self.assertRaises(InvalidLeaveApproverError, application.insert)
		
		webnotes.conn.sql("""delete from `tabEmployee Leave Approver` where parent=%s""",
			"_T-Employee-0001")
Example #11
0
	def _test_leave_approval_invalid_leave_approver_submit(self):
		self._clear_applications()
		self._add_employee_leave_approver("_T-Employee-0001", "*****@*****.**")
		
		# create leave application as employee
		# but submit as invalid leave approver - should raise exception
		webnotes.set_user("*****@*****.**")
		application = self.get_application(test_records[1])
		application.doc.leave_approver = "*****@*****.**"
		application.insert()
		webnotes.set_user("*****@*****.**")
		application.doc.status = "Approved"
		
		from webnotes.model.bean import BeanPermissionError
		self.assertRaises(BeanPermissionError, application.submit)
		
		webnotes.conn.sql("""delete from `tabEmployee Leave Approver` where parent=%s""",
			"_T-Employee-0001")
Example #12
0
	def test_block_list(self):
		self._clear_roles()
		
		from webnotes.profile import add_role
		add_role("*****@*****.**", "HR User")
			
		webnotes.conn.set_value("Department", "_Test Department", 
			"leave_block_list", "_Test Leave Block List")
		
		application = self.get_application(test_records[1])
		application.insert()
		application.doc.status = "Approved"
		self.assertRaises(LeaveDayBlockedError, application.submit)
		
		webnotes.set_user("*****@*****.**")

		# clear other applications
		webnotes.conn.sql("delete from `tabLeave Application`")
		
		application = self.get_application(test_records[1])
		self.assertTrue(application.insert())
Example #13
0
	def _test_leave_approval_valid_leave_approver_insert(self):
		self._clear_applications()
		self._add_employee_leave_approver("_T-Employee-0001", "*****@*****.**")
		
		original_department = webnotes.conn.get_value("Employee", "_T-Employee-0001", "department")
		webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", None)
		
		webnotes.set_user("*****@*****.**")
		application = self.get_application(test_records[1])
		application.doc.leave_approver = "*****@*****.**"
		application.insert()

		# change to valid leave approver and try to submit leave application
		webnotes.set_user("*****@*****.**")
		application.doc.status = "Approved"
		application.submit()
		self.assertEqual(webnotes.conn.get_value("Leave Application", application.doc.name,
			"docstatus"), 1)
			
		webnotes.conn.sql("""delete from `tabEmployee Leave Approver` where parent=%s""",
			"_T-Employee-0001")
		
		webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", original_department)
Example #14
0
	def test_global_block_list(self):
		self._clear_roles()

		from webnotes.profile import add_role
		add_role("*****@*****.**", "Employee")
		add_role("*****@*****.**", "Leave Approver")
				
		application = self.get_application(test_records[3])
		application.doc.leave_approver = "*****@*****.**"
		
		webnotes.conn.set_value("Leave Block List", "_Test Leave Block List", 
			"applies_to_all_departments", 1)
		webnotes.conn.set_value("Employee", "_T-Employee-0002", "department", 
			"_Test Department")
		
		webnotes.set_user("*****@*****.**")
		application.insert()
		
		webnotes.set_user("*****@*****.**")
		application.doc.status = "Approved"
		self.assertRaises(LeaveDayBlockedError, application.submit)
		
		webnotes.conn.set_value("Leave Block List", "_Test Leave Block List", 
			"applies_to_all_departments", 0)
	def test_allow_in_restriction(self):
		self.add_restricted_on_blogger()

		webnotes.set_user("*****@*****.**")
		bean = webnotes.bean("Blog Post", "_test-blog-post-1")
		self.assertFalse(bean.has_read_perm())

		webnotes.set_user("*****@*****.**")
		add("*****@*****.**", "Blog Post", "_test-blog-post-1")

		webnotes.set_user("*****@*****.**")
		bean = webnotes.bean("Blog Post", "_test-blog-post-1")

		self.assertTrue(bean.has_read_perm())
Example #16
0
	def test_allowed_private_if_in_event_user(self):
		webnotes.set_user("*****@*****.**")
		doc = webnotes.doc("Event", webnotes.conn.get_value("Event", {"subject":"_Test Event 3"}))
		self.assertTrue(webnotes.has_permission("Event", refdoc=doc))
Example #17
0
	def tearDown(self):
		webnotes.set_user("Administrator")
	def tearDown(self):
		webnotes.set_user("Administrator")
		clear_restrictions("Blog Category")
		clear_restrictions("Blog Post")
	def test_not_allowed_to_restrict(self):
		webnotes.set_user("*****@*****.**")
		
		# this user can't add restriction
		self.assertRaises(webnotes.PermissionError, add, 
			"*****@*****.**", "Blog Post", "_test-blog-post")
	def add_restriction_to_user2(self):
		webnotes.set_user("*****@*****.**")
		add("*****@*****.**", "Blog Post", "_test-blog-post")