def test_add_default_permissions(self): """ Test that the default set of permissions are assigned when a new user is created. """ user = UserFactory() ok_(user.has_perm('users.can_share_website')) # Ensure permissions aren't overwritten for existing users. user.user_permissions = [] user.save() user = refresh_model(user) eq_(list(user.user_permissions.all()), [])
def test_add_default_permissions_does_not_overwrite(self): """ If a newly created user has some permissions already specified, do not overwrite them when adding the default permissions. """ permission = PermissionFactory.create() user = UserFactory() user.user_permissions = [permission] user.save() user = refresh_model(user) app_label = permission.content_type.app_label codename = permission.codename ok_(user.has_perm('%s.%s' % (app_label, codename)))