示例#1
0
 def test_da_3(self):
     u"""更新记录1 REJECT"""
     
     ThreadUser.set_current_user(self.da)
     with self.assertRaises(PermissionDenied):
         self.d1.demo = "aewfaefawe"
         self.d1.save()
示例#2
0
 def test_ad_5(self):
     u"""删除记录1,2,6,7 ACCESS"""
     
     ThreadUser.set_current_user(self.ad)
     self.d1.delete()
     self.d2.delete()
     self.d6.delete()
     self.d7.delete()
示例#3
0
 def test_db_1(self):
     u"""添加更新记录    ACCESS"""
     
     ThreadUser.set_current_user(self.db)
     demos = AuthDemoModel_1.objects.all().order_by('id')
     assert demos[0] == self.d4
     assert demos[1] == self.d5
     assert demos[2] == self.d8
示例#4
0
 def test_aa_1(self):
     u"""添加更新记录n    ACCESS"""
     
     ThreadUser.set_current_user(self.aa)
     demo = AuthDemoModel_1.objects.create(demo = "awefaeaefae")
     assert demo.owner == self.aa
     assert demo.team == self.ta
     demo.demo = "aewfojiaewfie"
     demo.save()
示例#5
0
 def test_cb_1(self):
     u"""添加更新记录    ACCESS"""
     
     ThreadUser.set_current_user(self.cb)
     demo = AuthDemoModel_1.objects.create(demo = "awefaeaefae")
     assert demo.owner.id == self.cb.id
     assert demo.team.id == self.ta.id
     demo.demo = "aefaefaefewa"
     demo.save()
示例#6
0
 def test_cb_4(self):
     u"""更新记录1,2,8 REJECT"""
     
     ThreadUser.set_current_user(self.cb)
     with self.assertRaises(PermissionDenied):
         self.d1.demo = "aewfaefawe"
         self.d1.save()
     with self.assertRaises(PermissionDenied):
         self.d2.demo = "aewfaefawe"
         self.d2.save()
示例#7
0
 def test_cb_3(self):
     u"""更新记录4,5,7    ACCESS"""
     
     ThreadUser.set_current_user(self.cb)
     self.d4.demo = "aewfojiaewfie"
     self.d4.save()
     self.d5.demo = "aewfojiaewfie"
     self.d5.save()
     self.d7.demo = "aewfojiaewfie"
     self.d7.save()
示例#8
0
 def test_ad_3(self):
     u"""更新记录2,4 REJECT"""
     
     ThreadUser.set_current_user(self.ad)
     with self.assertRaises(PermissionDenied):
         self.d4.demo = "aewfaefawe"
         self.d4.save()
     with self.assertRaises(PermissionDenied):
         self.d5.demo = "aewfaefawe"
         self.d5.save()
示例#9
0
 def test_aa_4(self):
     u"""查看记录 1,2,3,6,7"""
     
     ThreadUser.set_current_user(self.aa)
     demos = AuthDemoModel_1.objects.all().order_by('id')
     assert demos[0] == self.d1
     assert demos[1] == self.d2
     assert demos[2] == self.d3
     assert demos[3] == self.d6
     assert demos[4] == self.d7
示例#10
0
 def test_ad_2(self):
     u"""更新记录1,2,3,6,7    ACCESS"""
     
     ThreadUser.set_current_user(self.ad)
     self.d1.demo = "aewfojiaewfie"
     self.d1.save()
     self.d2.demo = "aewfojiaewfie"
     self.d2.save()
     self.d3.demo = "aewfojiaewfie"
     self.d3.save()
     self.d6.demo = "aewfojiaewfie"
     self.d6.save()
     self.d7.demo = "aewfojiaewfie"
     self.d7.save()
示例#11
0
 def test_da_2(self):
     u"""查看记录 8"""
     
     ThreadUser.set_current_user(self.da)
     demos = AuthDemoModel_1.objects.all().order_by('id')
     assert demos.count()==0
示例#12
0
 def test_da_1(self):
     u"""添加更新记录    ACCESS"""
     
     ThreadUser.set_current_user(self.da)
     with self.assertRaises(PermissionDenied):
         demo = AuthDemoModel_1.objects.create(demo = "awefaeaefae")
示例#13
0
 def test_cb_2(self):
     u"""查看记录 ALL"""
     
     ThreadUser.set_current_user(self.cb)
     demos = AuthDemoModel_1.objects.all().order_by('id')
     assert demos.count()>=7
示例#14
0
 def test_aa_2(self):
     u"""更新记录1    ACCESS"""
     
     ThreadUser.set_current_user(self.aa)
     self.d1.demo = "aewfojiaewfie"
     self.d1.save()
示例#15
0
 def test_ac_6(self):
     u"""删除记录4 REJECT"""
     
     ThreadUser.set_current_user(self.ac)
     with self.assertRaises(PermissionDenied):
         self.d4.delete()
示例#16
0
 def test_ac_1(self):
     u"""添加记录    REJECT"""
     
     ThreadUser.set_current_user(self.ac)
     with self.assertRaises(PermissionDenied):
         demo = AuthDemoModel_1.objects.create(demo = "awefaeaefae")
示例#17
0
 def test_aa_5(self):
     u"""删除记录1 REJECT"""
     
     ThreadUser.set_current_user(self.aa)
     with self.assertRaises(PermissionDenied):
         self.d1.delete()
示例#18
0
 def setUp(self):
      
     # Create Stand Auths
     perm_null   = AuthPermission.objects.create(code_name = 'NULL', display_name = 'NULL')
     perm_view   = AuthPermission.objects.create(code_name = 'View', display_name = 'View')
     perm_add    = AuthPermission.objects.create(code_name = 'Add', display_name = 'Add')
     perm_edit   = AuthPermission.objects.create(code_name = 'Edit', display_name = 'Edit')
     perm_delete = AuthPermission.objects.create(code_name = 'Delete', display_name = 'Delete')
     
     # Create Test User Role ( use django group )
     self.employee   = UserRole.objects.create(name = "Employee")
     self.manager    = UserRole.objects.create(name = "Manager")
     self.guest      = UserRole.objects.create(name = "Guest")
     
     # Setup permission for AuthDemoModel_1
     employee_perm = PermissionConfigure.objects.create(role = self.employee, 
                                                        content_type = ContentType.objects.get_for_model(AuthDemoModel_1))
     employee_perm.model_permissions.add(perm_add)
     employee_perm.owner_permissions.add(perm_view)
     employee_perm.owner_permissions.add(perm_edit)
     employee_perm.team_permissions.add(perm_view)
     employee_perm.other_permissions.add(perm_null)
     
     manager_perm = PermissionConfigure.objects.create(role = self.manager,
                                                       content_type = ContentType.objects.get_for_model(AuthDemoModel_1))
     manager_perm.model_permissions.add(perm_null)
     manager_perm.owner_permissions.add(perm_view)
     manager_perm.team_permissions.add(perm_view)
     manager_perm.team_permissions.add(perm_edit)
     manager_perm.team_permissions.add(perm_delete)
     manager_perm.other_permissions.add(perm_view)
     
     guest_perm = PermissionConfigure.objects.create(role = self.guest,
                                                       content_type = ContentType.objects.get_for_model(AuthDemoModel_1))
     guest_perm.model_permissions.add(perm_add)
     guest_perm.owner_permissions.add(perm_view)
     guest_perm.owner_permissions.add(perm_edit)
     guest_perm.team_permissions.add(perm_null)
     guest_perm.other_permissions.add(perm_null)
     
     # Create Test Users
     self.root = User.objects.create(username = "******", is_staff = True, is_superuser = True)
     self.aa  = User.objects.create(username = "******", is_staff = True)
     self.ab  = User.objects.create(username = "******", is_staff = True)
     self.ac  = User.objects.create(username = "******", is_staff = True)
     self.ad  = User.objects.create(username = "******", is_staff = True)
     self.ba  = User.objects.create(username = "******", is_staff = True)
     self.bb  = User.objects.create(username = "******", is_staff = True)
     self.bc  = User.objects.create(username = "******", is_staff = True)
     self.ca  = User.objects.create(username = "******", is_staff = True)
     self.cb  = User.objects.create(username = "******", is_staff = True)
     self.da  = User.objects.create(username = "******", is_staff = True)
     self.db  = User.objects.create(username = "******", is_staff = True)
     
     # Create Test Teams
     self.ta  = UserTeam.objects.create(name = 'A')
     self.tb  = UserTeam.objects.create(name = 'B')
     
     # Add users to user team
     UserTeamRel.objects.create(user = self.aa, team = self.ta, role = self.employee, is_master = True)
     UserTeamRel.objects.create(user = self.ab, team = self.ta, role = self.employee, is_master = True)
     UserTeamRel.objects.create(user = self.ac, team = self.ta, role = self.manager, is_master = True)
     UserTeamRel.objects.create(user = self.ad, team = self.ta, role = self.employee, is_master = True)
     UserTeamRel.objects.create(user = self.ad, team = self.ta, role = self.manager, is_master = True)
     UserTeamRel.objects.create(user = self.ba, team = self.tb, role = self.employee, is_master = True)
     UserTeamRel.objects.create(user = self.bb, team = self.tb, role = self.employee, is_master = True)
     UserTeamRel.objects.create(user = self.bc, team = self.tb, role = self.manager, is_master = True)
     UserTeamRel.objects.create(user = self.ca, team = self.ta, role = self.employee, is_master = True)
     UserTeamRel.objects.create(user = self.ca, team = self.tb, role = self.employee, is_master = False)
     UserTeamRel.objects.create(user = self.cb, team = self.ta, role = self.employee, is_master = True)
     UserTeamRel.objects.create(user = self.cb, team = self.tb, role = self.manager, is_master = False)
     UserTeamRel.objects.create(user = self.db, team = self.ta, role = self.guest, is_master = True)
     UserTeamRel.objects.create(user = self.db, team = self.tb, role = self.employee, is_master = False)
     
     # Create Test DB Record
     ThreadUser.set_current_user(self.aa)
     self.d1  = AuthDemoModel_1.objects.create(id = 1, demo = "aaaaaaaaaa")
     ThreadUser.set_current_user(self.ab)
     self.d2  = AuthDemoModel_1.objects.create(id = 2, demo = "abababababab")
     ThreadUser.set_current_user(self.ad)
     self.d3  = AuthDemoModel_1.objects.create(id = 3, demo = "adadadadadad")
     ThreadUser.set_current_user(self.ba)
     self.d4  = AuthDemoModel_1.objects.create(id = 4, demo = "bababababab")
     ThreadUser.set_current_user(self.bb)
     self.d5  = AuthDemoModel_1.objects.create(id = 5, demo = "bbbbbbbbbb")
     ThreadUser.set_current_user(self.ca)
     self.d6  = AuthDemoModel_1.objects.create(id = 6, demo = "cacacacacacaca")
     ThreadUser.set_current_user(self.cb)
     self.d7  = AuthDemoModel_1.objects.create(id = 7, demo = "cbcbcbcbcbcb")
     ThreadUser.set_current_user(self.db)
     self.d8  = AuthDemoModel_1.objects.create(id = 8, demo = "dbdbdbdbdbdbdbd")
示例#19
0
 def test_ad_8(self):
     u"""删除记录5 REJECT"""
     
     ThreadUser.set_current_user(self.ad)
     with self.assertRaises(PermissionDenied):
         self.d5.delete()