django-cas-server/tests/test_views_logout.py

81 lines
2.1 KiB
Python
Raw Normal View History

2015-06-12 21:57:11 +00:00
from __future__ import absolute_import
from .init import *
from django.test import RequestFactory
import os
import pytest
from cas_server.views import LogoutView
from cas_server import models
from .dummy import *
@pytest.mark.django_db
2015-06-21 16:56:16 +00:00
@dummy_user(username="test", session_key="test_session")
2015-06-12 21:57:11 +00:00
def test_logout_view():
factory = RequestFactory()
request = factory.get('/logout')
request.session = DummySession()
request.session["authenticated"] = True
request.session["username"] = "test"
request.session["warn"] = False
logout = LogoutView()
response = logout.get(request)
assert response.status_code == 200
assert not request.session.get("authenticated")
assert not request.session.get("username")
assert not request.session.get("warn")
@pytest.mark.django_db
2015-06-21 16:56:16 +00:00
@dummy_user(username="test", session_key="test_session")
2015-06-12 21:57:11 +00:00
def test_logout_view_url():
factory = RequestFactory()
request = factory.get('/logout?url=https://www.example.com')
request.session = DummySession()
request.session["authenticated"] = True
request.session["username"] = "test"
request.session["warn"] = False
logout = LogoutView()
response = logout.get(request)
assert response.status_code == 302
assert response['Location'] == 'https://www.example.com'
assert not request.session.get("authenticated")
assert not request.session.get("username")
assert not request.session.get("warn")
@pytest.mark.django_db
2015-06-21 16:56:16 +00:00
@dummy_user(username="test", session_key="test_session")
2015-06-12 21:57:11 +00:00
def test_logout_view_service():
factory = RequestFactory()
request = factory.get('/logout?service=https://www.example.com')
request.session = DummySession()
request.session["authenticated"] = True
request.session["username"] = "test"
request.session["warn"] = False
logout = LogoutView()
response = logout.get(request)
assert response.status_code == 302
assert response['Location'] == 'https://www.example.com'
assert not request.session.get("authenticated")
assert not request.session.get("username")
assert not request.session.get("warn")