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_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_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_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_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_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_has_role(self): user = User.objects.create(username='******') self.assertFalse(has_role(user, 'scientist')) Scientist.assign(user) self.assertTrue(has_role(user, Scientist))