def test_is_publisher_user_with_publisher_group(self): """ Verify that decorator works fine with user is part of publisher app group. """ func = Mock() decorated_func = publisher_user_required(func) request = RequestFactory() request.user = self.user self.user.groups.add(self.internal_user_group) decorated_func(request, self.user) self.assertTrue(func.called)
def test_require_is_publisher_user_without_group(self): """ Verify that decorator returns the error message if user is not part of any publisher group. """ func = Mock() decorated_func = publisher_user_required(func) request = RequestFactory() request.user = self.user response = decorated_func(request, self.user) self.assertContains(response, "Must be Publisher user to perform this action.", status_code=403) self.assertFalse(func.called)