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_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): 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_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): 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_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_group(self): self.assertEqual(Scientist.get_group().name, '_role_scientist') self.assertEqual(GeneticCounselor.get_group().name, '_role_genetic_counselor')