Ejemplo n.º 1
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)
Ejemplo n.º 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)
Ejemplo n.º 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())
Ejemplo n.º 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)
Ejemplo n.º 5
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)
Ejemplo n.º 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'])
Ejemplo n.º 7
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())
Ejemplo n.º 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)
Ejemplo n.º 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())
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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'
Ejemplo n.º 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'
Ejemplo n.º 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', )
Ejemplo n.º 15
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)
Ejemplo n.º 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)
Ejemplo n.º 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', )
Ejemplo n.º 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'
Ejemplo n.º 19
0
 def test_get_group(self):
     self.assertEqual(Scientist.get_group().name, '_role_scientist')
     self.assertEqual(GeneticCounselor.get_group().name,
                      '_role_genetic_counselor')
Ejemplo n.º 20
0
 def test_get_permissions(self):
     self.assertEqual(len(Scientist.get_permissions()), 0)
Ejemplo n.º 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())
Ejemplo n.º 22
0
 def test_synchronize(self):
     call_command('synchronize_roles')
     perm = Permission.objects.get(codename='change_user')
     self.assertTrue(perm in Scientist.get_permissions())
Ejemplo n.º 23
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))
Ejemplo n.º 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))
Ejemplo n.º 25
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())
Ejemplo n.º 26
0
 def test_get_permissions(self):
     self.assertEqual(len(Scientist.get_permissions()), 0)
Ejemplo n.º 27
0
 def test_synchronize(self):
     call_command('synchronize_roles')
     perm = Permission.objects.get(codename='change_user')
     self.assertTrue(perm in Scientist.get_permissions())
Ejemplo n.º 28
0
 def test_get_group(self):
     self.assertEqual(Scientist.get_group().name, '_role_scientist')
     self.assertEqual(GeneticCounselor.get_group().name, '_role_genetic_counselor')
 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))