I am trying to test my create_user view in a django1.8 app. I have the following in a TestCase:
new_user = User.objects.get(username='test')
basic_user_group = Group.objects.get(name='basic_users')
self.assertIn(basic_user_group, new_user.groups.all()) # passes
print new_user.groups.all()
# [<Group: basic_users>]
print new_user.groups.first().permissions.all()
# [<Permission: foo_app | 'add_bar'>]
print new_user.get_all_permissions()
# set([]) # Why?
self.assertTrue(new_user.has_perm('foo_app.add_bar')) # fails
When I use the actual app to create a user then open up the shell to check has_perm('foo_app.add_bar'), it's True. What's going wrong in the test?
I am using django-guardian for object permissions. My settings.AUTHENTICATION_BACKENDS
is:
(
'guardian.backends.ObjectPermissionBackend',
'django.contrib.auth.backends.ModelBackend',
)
Aucun commentaire:
Enregistrer un commentaire