test_views_logout.py 2.1 KB
Newer Older
Valentin Samir's avatar
Valentin Samir committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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
Valentin Samir's avatar
Valentin Samir committed
16
@dummy_user(username="test", session_key="test_session")
Valentin Samir's avatar
Valentin Samir committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
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
Valentin Samir's avatar
Valentin Samir committed
37
@dummy_user(username="test", session_key="test_session")
Valentin Samir's avatar
Valentin Samir committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
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
Valentin Samir's avatar
Valentin Samir committed
60
@dummy_user(username="test", session_key="test_session")
Valentin Samir's avatar
Valentin Samir committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
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")