def test_wharton_permission__permission_allowed(self, _call_wisp_api): """ Test Case - User does have permission """ request = Mock() request.META.get.return_value = 'remote_user_name' options = ['STAFF', 'WCIT'] decorated_func = wharton_permission(options) response = decorated_func(request) x = response(request) self.assertTrue(request.called) self.assertTrue(_call_wisp_api.called)
def test_wharton_permission__list_is_not_passed(self, _call_wisp_api): """ Test Case - argument is not a list """ request = Mock() request.META.get.return_value = 'remote_user_name' options = 'WCIT' decorated_func = wharton_permission(options) response = decorated_func(request) x = response(request) self.assertTrue(request.called) self.assertTrue(_call_wisp_api.called)
def test_wharton_permission__permission_bad_request(self, _call_wisp_api): """ Test Case - Bad request has occured """ request = Mock() request.META.get.return_value = 'remote_user_name' options = ['STAFF', 'WCIT'] decorated_func = wharton_permission(options) response = decorated_func(request) x = response(request) self.assertEqual(x.status_code, 400) self.assertTrue(str(x), 'No groups found for user remote_user_name')
def test_wharton_permission__permission_denied(self, _call_wisp_api): """ Test Case - User does not have permissions """ request = Mock() request.META.get.return_value = 'remote_user_name' options = ['STAFF', 'WCIT'] decorated_func = wharton_permission(options) response = decorated_func(request) with self.assertRaises(PermissionDenied) as cm: response(request) klass_name = cm.exception.__class__.__name__ self.assertEqual(klass_name, 'PermissionDenied')
def test_wharton_permission__permission_denied_no_remote_user(self): """ Test Case - There is no remote user """ request = Mock() request.META.get.return_value = None options = ['STAFF', 'WCIT'] decorated_func = wharton_permission(options) response = decorated_func(request) with self.assertRaises(PermissionDenied) as cm: response(request) klass_name = cm.exception.__class__.__name__ self.assertEqual(klass_name, 'PermissionDenied')