diff --git a/cas_server/tests.py b/cas_server/tests.py index 222596e..710b890 100644 --- a/cas_server/tests.py +++ b/cas_server/tests.py @@ -10,25 +10,25 @@ from cas_server import utils def get_login_page_params(): - client = Client() - response = client.get('/login') - form = response.context["form"] - params = {} - for field in form: - if field.value(): - params[field.name] = field.value() - else: - params[field.name] = "" - return client, params + client = Client() + response = client.get('/login') + form = response.context["form"] + params = {} + for field in form: + if field.value(): + params[field.name] = field.value() + else: + params[field.name] = "" + return client, params def get_auth_client(): - client, params = get_login_page_params() - params["username"] = settings.CAS_TEST_USER - params["password"] = settings.CAS_TEST_PASSWORD + client, params = get_login_page_params() + params["username"] = settings.CAS_TEST_USER + params["password"] = settings.CAS_TEST_PASSWORD - client.post('/login', params) - return client + client.post('/login', params) + return client def get_user_ticket_request(service): diff --git a/cas_server/utils.py b/cas_server/utils.py index 8a2a040..bd7e273 100644 --- a/cas_server/utils.py +++ b/cas_server/utils.py @@ -30,7 +30,7 @@ def context(params): return params -def JsonResponse(request, data): +def json_response(request, data): data["messages"] = [] for msg in messages.get_messages(request): data["messages"].append({'message': msg.message, 'level': msg.level_tag}) @@ -146,16 +146,16 @@ def gen_saml_id(): class PGTUrlHandler(BaseHTTPServer.BaseHTTPRequestHandler): PARAMS = {} - def do_GET(s): - s.send_response(200) - s.send_header(b"Content-type", "text/plain") - s.end_headers() - s.wfile.write(b"ok") - url = urlparse(s.path) + def do_GET(self): + self.send_response(200) + self.send_header(b"Content-type", "text/plain") + self.end_headers() + self.wfile.write(b"ok") + url = urlparse(self.path) params = dict(parse_qsl(url.query)) PGTUrlHandler.PARAMS.update(params) - def log_message(self, template, *args): + def log_message(self, *args): return @staticmethod diff --git a/cas_server/views.py b/cas_server/views.py index 37fe179..2b33a6c 100644 --- a/cas_server/views.py +++ b/cas_server/views.py @@ -35,7 +35,7 @@ import cas_server.utils as utils import cas_server.forms as forms import cas_server.models as models -from .utils import JsonResponse +from .utils import json_response from .models import ServiceTicket, ProxyTicket, ProxyGrantingTicket from .models import ServicePattern @@ -154,13 +154,13 @@ class LogoutView(View, LogoutMixin): 'url': url, 'session_nb': session_nb } - return JsonResponse(request, data) + return json_response(request, data) else: return redirect("cas_server:login") else: if self.ajax: data = {'status': 'success', 'detail': 'logout', 'session_nb': session_nb} - return JsonResponse(request, data) + return json_response(request, data) else: return render( request, @@ -253,7 +253,7 @@ class LoginView(View, LogoutMixin): raise EnvironmentError("invalid output for LoginView.process_post") return self.common() - def process_post(self, pytest=False): + def process_post(self): if not self.check_lt(): values = self.request.POST.copy() # if not set a new LT and fail @@ -330,7 +330,7 @@ class LoginView(View, LogoutMixin): ) if self.ajax: data = {"status": "error", "detail": "confirmation needed"} - return JsonResponse(self.request, data) + return json_response(self.request, data) else: warn_form = forms.WarnForm(initial={ 'service': self.service, @@ -357,7 +357,7 @@ class LoginView(View, LogoutMixin): return HttpResponseRedirect(redirect_url) else: data = {"status": "success", "detail": "auth", "url": redirect_url} - return JsonResponse(self.request, data) + return json_response(self.request, data) except ServicePattern.DoesNotExist: error = 1 messages.add_message( @@ -401,7 +401,7 @@ class LoginView(View, LogoutMixin): ) else: data = {"status": "error", "detail": "auth", "code": error} - return JsonResponse(self.request, data) + return json_response(self.request, data) def authenticated(self): """Processing authenticated users""" @@ -423,7 +423,7 @@ class LoginView(View, LogoutMixin): "detail": "login required", "url": utils.reverse_params("cas_server:login", params=self.request.GET) } - return JsonResponse(self.request, data) + return json_response(self.request, data) else: return utils.redirect_params("cas_server:login", params=self.request.GET) @@ -433,7 +433,7 @@ class LoginView(View, LogoutMixin): else: if self.ajax: data = {"status": "success", "detail": "logged"} - return JsonResponse(self.request, data) + return json_response(self.request, data) else: return render( self.request, @@ -476,7 +476,7 @@ class LoginView(View, LogoutMixin): "detail": "login required", "url": utils.reverse_params("cas_server:login", params=self.request.GET) } - return JsonResponse(self.request, data) + return json_response(self.request, data) else: return render( self.request,