コード例 #1
0
ファイル: test_roles.py プロジェクト: GenePeeks/django-hats
 def test_remove(self):
     user = User.objects.create(username='******')
     self.assertEqual(user.groups.count(), 0)
     Scientist.assign(user)
     self.assertEqual(user.groups.count(), 1)
     Scientist.remove(user)
     self.assertEqual(user.groups.count(), 0)
コード例 #2
0
 def test_rolefinder_by_user(self):
     user = User.objects.create(username='******')
     self.assertEqual(Scientist.get_users().count(), 0)
     Scientist.assign(user)
     self.assertEqual(RoleFinder.by_user(user)[0], Scientist)
     self.assertEqual(len(RoleFinder.by_user(user)), 1)
     Scientist.remove(user)
コード例 #3
0
 def test_add_permissions(self):
     perm = Permission.objects.create(
         codename='temp',
         name='Temporary',
         content_type=ContentType.objects.get_for_model(User))
     Scientist.add_permissions(perm)
     self.assertTrue(perm in Scientist.get_permissions())
コード例 #4
0
 def test_remove(self):
     user = User.objects.create(username='******')
     self.assertEqual(user.groups.count(), 0)
     Scientist.assign(user)
     self.assertEqual(user.groups.count(), 1)
     Scientist.remove(user)
     self.assertEqual(user.groups.count(), 0)
コード例 #5
0
ファイル: test_roles.py プロジェクト: GenePeeks/django-hats
 def test_rolefinder_by_user(self):
     user = User.objects.create(username='******')
     self.assertEqual(Scientist.get_users().count(), 0)
     Scientist.assign(user)
     self.assertEqual(RoleFinder.by_user(user)[0], Scientist)
     self.assertEqual(len(RoleFinder.by_user(user)), 1)
     Scientist.remove(user)
コード例 #6
0
 def test_roles_user(self):
     user = User.objects.create(username='******')
     Scientist.assign(user)
     request = RequestFactory().get('/test/')
     request.user = user
     context = roles(request)
     self.assertTrue(context['roles']['scientist'])
     self.assertTrue('scientist' in context['roles'])
コード例 #7
0
ファイル: test_roles.py プロジェクト: GenePeeks/django-hats
 def test_add_permissions(self):
     perm = Permission.objects.create(
         codename='temp',
         name='Temporary',
         content_type=ContentType.objects.get_for_model(User)
     )
     Scientist.add_permissions(perm)
     self.assertTrue(perm in Scientist.get_permissions())
コード例 #8
0
 def test_migrate_role(self):
     user = User.objects.create(username='******')
     GeneticCounselor.assign(user)
     self.assertEqual(GeneticCounselor.get_group().user_set.count(), 1)
     self.assertEqual(Scientist.get_group().user_set.count(), 0)
     migrate_role(GeneticCounselor.get_group(), Scientist)
     self.assertEqual(GeneticCounselor.get_group().user_set.count(), 0)
     self.assertEqual(Scientist.get_group().user_set.count(), 1)
コード例 #9
0
 def test_has_permission(self):
     user = User.objects.create(username='******')
     mixin = RoleRequiredMixin()
     mixin.request = Object()
     mixin.request.user = user
     mixin.role_required = Scientist
     self.assertFalse(mixin.has_permission())
     Scientist.assign(user)
     self.assertTrue(mixin.has_permission())
コード例 #10
0
 def test_migrate_role(self):
     user = User.objects.create(username='******')
     Group.objects.create(name='%s%s' % (Bootstrapper.prefix, 'old_role'))
     GeneticCounselor.assign(user)
     self.assertEqual(GeneticCounselor.get_group().user_set.count(), 1)
     self.assertEqual(Scientist.get_group().user_set.count(), 0)
     call_command('migrate_role', old='GeneticCounselor', new='Scientist')
     self.assertEqual(GeneticCounselor.get_group().user_set.count(), 0)
     self.assertEqual(Scientist.get_group().user_set.count(), 1)
     call_command('migrate_role', old='OldRole', new='Scientist')
コード例 #11
0
 def test_migrate_role(self):
     user = User.objects.create(username='******')
     Group.objects.create(name='%s%s' % (Bootstrapper.prefix, 'old_role'))
     GeneticCounselor.assign(user)
     self.assertEqual(GeneticCounselor.get_group().user_set.count(), 1)
     self.assertEqual(Scientist.get_group().user_set.count(), 0)
     call_command('migrate_role', old='GeneticCounselor', new='Scientist')
     self.assertEqual(GeneticCounselor.get_group().user_set.count(), 0)
     self.assertEqual(Scientist.get_group().user_set.count(), 1)
     call_command('migrate_role', old='OldRole', new='Scientist')
コード例 #12
0
 def test_synchronize_roles(self):
     group = Scientist.get_group()
     group.permissions.add(Permission.objects.create(codename='temporary', content_type=ContentType.objects.get_for_model(User)))
     permission_count = Permission.objects.count()
     Scientist.group = None
     Scientist._meta.name = '404'
     call_command('synchronize_roles')
     self.assertEqual(Group.objects.count(), 4)
     self.assertTrue(Group.objects.get(name__icontains=Scientist.get_slug()))
     self.assertEqual(Permission.objects.count(), permission_count)
     Scientist._meta.name = 'scientist'
コード例 #13
0
 def test_synchronize_roles(self):
     group = Scientist.get_group()
     group.permissions.add(
         Permission.objects.create(
             codename='temporary',
             content_type=ContentType.objects.get_for_model(User)))
     permission_count = Permission.objects.count()
     Scientist.group = None
     Scientist._meta.name = '404'
     call_command('synchronize_roles')
     self.assertEqual(Group.objects.count(), 4)
     self.assertTrue(
         Group.objects.get(name__icontains=Scientist.get_slug()))
     self.assertEqual(Permission.objects.count(), permission_count)
     Scientist._meta.name = 'scientist'
コード例 #14
0
 def test_cleanup_roles(self):
     group = Scientist.get_group()
     group.permissions.add(Permission.objects.create(codename='temporary', content_type=ContentType.objects.get_for_model(User)))
     permission_count = Permission.objects.count()
     Scientist.group = None
     Scientist._meta.name = '404'
     call_command('synchronize_roles')
     Scientist._meta.permissions = ()
     call_command('cleanup_roles')
     self.assertEqual(Group.objects.count(), 3)
     self.assertTrue(Group.objects.get(name__icontains=Scientist.get_slug()))
     self.assertRaises(Group.DoesNotExist, Group.objects.get, name__icontains='scientist')
     self.assertEqual(Permission.objects.count(), permission_count)
     Scientist._meta.name = 'scientist'
     Scientist._meta.permissions = ('change_user', )
コード例 #15
0
ファイル: test_roles.py プロジェクト: GenePeeks/django-hats
 def test_get_users(self):
     user = User.objects.create(username='******')
     self.assertEqual(Scientist.get_users().count(), 0)
     Scientist.assign(user)
     self.assertEqual(Scientist.get_users().count(), 1)
     Scientist.remove(user)
     self.assertEqual(Scientist.get_users().count(), 0)
コード例 #16
0
 def test_get_users(self):
     user = User.objects.create(username='******')
     self.assertEqual(Scientist.get_users().count(), 0)
     Scientist.assign(user)
     self.assertEqual(Scientist.get_users().count(), 1)
     Scientist.remove(user)
     self.assertEqual(Scientist.get_users().count(), 0)
コード例 #17
0
 def test_cleanup_roles(self):
     group = Scientist.get_group()
     group.permissions.add(
         Permission.objects.create(
             codename='temporary',
             content_type=ContentType.objects.get_for_model(User)))
     permission_count = Permission.objects.count()
     Scientist.group = None
     Scientist._meta.name = '404'
     call_command('synchronize_roles')
     Scientist._meta.permissions = ()
     call_command('cleanup_roles')
     self.assertEqual(Group.objects.count(), 3)
     self.assertTrue(
         Group.objects.get(name__icontains=Scientist.get_slug()))
     self.assertRaises(Group.DoesNotExist,
                       Group.objects.get,
                       name__icontains='scientist')
     self.assertEqual(Permission.objects.count(), permission_count)
     Scientist._meta.name = 'scientist'
     Scientist._meta.permissions = ('change_user', )
コード例 #18
0
 def test_synchronize_roles(self):
     roles = Bootstrapper.get_roles()
     group = Scientist.get_group()
     group.permissions.add(
         Permission.objects.create(
             codename='temporary',
             content_type=ContentType.objects.get_for_model(User)))
     permission_count = Permission.objects.count()
     Scientist.group = None
     Scientist._meta.name = '404'
     synchronize_roles(roles)
     self.assertEqual(Group.objects.count(), 4)
     self.assertTrue(
         Group.objects.get(name__icontains=Scientist.get_slug()))
     self.assertEqual(Permission.objects.count(), permission_count)
     _permissions = Scientist._meta.permissions
     Scientist._meta.permissions = ()
     synchronize_roles(roles)
     self.assertEqual(Scientist.get_group().permissions.count(), 0)
     Scientist._meta.permissions = _permissions
     synchronize_roles(roles)
     Scientist._meta.name = 'scientist'
コード例 #19
0
 def test_get_group(self):
     self.assertEqual(Scientist.get_group().name, '_role_scientist')
     self.assertEqual(GeneticCounselor.get_group().name,
                      '_role_genetic_counselor')
コード例 #20
0
 def test_get_permissions(self):
     self.assertEqual(len(Scientist.get_permissions()), 0)
コード例 #21
0
 def test_assign(self):
     user = User.objects.create(username='******')
     self.assertEqual(user.groups.count(), 0)
     Scientist.assign(user)
     self.assertEqual(user.groups.count(), 1)
     self.assertEqual(user.groups.first(), Scientist.get_group())
コード例 #22
0
ファイル: test_roles.py プロジェクト: GenePeeks/django-hats
 def test_synchronize(self):
     call_command('synchronize_roles')
     perm = Permission.objects.get(codename='change_user')
     self.assertTrue(perm in Scientist.get_permissions())
コード例 #23
0
ファイル: test_roles.py プロジェクト: GenePeeks/django-hats
 def test_check_membership(self):
     user = User.objects.create(username='******')
     self.assertFalse(Scientist.check_membership(user))
     Scientist.assign(user)
     self.assertTrue(Scientist.check_membership(user))
コード例 #24
0
 def test_check_membership(self):
     user = User.objects.create(username='******')
     self.assertFalse(Scientist.check_membership(user))
     Scientist.assign(user)
     self.assertTrue(Scientist.check_membership(user))
コード例 #25
0
ファイル: test_roles.py プロジェクト: GenePeeks/django-hats
 def test_assign(self):
     user = User.objects.create(username='******')
     self.assertEqual(user.groups.count(), 0)
     Scientist.assign(user)
     self.assertEqual(user.groups.count(), 1)
     self.assertEqual(user.groups.first(), Scientist.get_group())
コード例 #26
0
ファイル: test_roles.py プロジェクト: GenePeeks/django-hats
 def test_get_permissions(self):
     self.assertEqual(len(Scientist.get_permissions()), 0)
コード例 #27
0
 def test_synchronize(self):
     call_command('synchronize_roles')
     perm = Permission.objects.get(codename='change_user')
     self.assertTrue(perm in Scientist.get_permissions())
コード例 #28
0
ファイル: test_roles.py プロジェクト: GenePeeks/django-hats
 def test_get_group(self):
     self.assertEqual(Scientist.get_group().name, '_role_scientist')
     self.assertEqual(GeneticCounselor.get_group().name, '_role_genetic_counselor')
コード例 #29
0
 def test_has_role(self):
     user = User.objects.create(username='******')
     self.assertFalse(has_role(user, 'scientist'))
     Scientist.assign(user)
     self.assertTrue(has_role(user, Scientist))