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)
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)
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())
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)
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)
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'])
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())
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)
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())
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')
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')
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'
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'
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', )
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)
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)
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', )
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'
def test_get_group(self): self.assertEqual(Scientist.get_group().name, '_role_scientist') self.assertEqual(GeneticCounselor.get_group().name, '_role_genetic_counselor')
def test_get_permissions(self): self.assertEqual(len(Scientist.get_permissions()), 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())
def test_synchronize(self): call_command('synchronize_roles') perm = Permission.objects.get(codename='change_user') self.assertTrue(perm in Scientist.get_permissions())
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))
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))
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())
def test_get_permissions(self): self.assertEqual(len(Scientist.get_permissions()), 0)
def test_synchronize(self): call_command('synchronize_roles') perm = Permission.objects.get(codename='change_user') self.assertTrue(perm in Scientist.get_permissions())
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))