django-cas-server/tests/test_views_validate.py

59 lines
1.5 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 Validate
from cas_server import models
from .dummy import *
@pytest.mark.django_db
2015-06-21 16:56:16 +00:00
@dummy_ticket(models.ServiceTicket, 'https://www.example.com', "ST-random")
2015-06-12 21:57:11 +00:00
def test_validate_view_ok():
factory = RequestFactory()
request = factory.get('/validate?ticket=ST-random&service=https://www.example.com')
request.session = DummySession()
validate = Validate()
response = validate.get(request)
assert response.status_code == 200
2015-06-21 16:56:16 +00:00
assert response.content == b"yes\n"
2015-06-12 21:57:11 +00:00
@pytest.mark.django_db
2015-06-21 16:56:16 +00:00
@dummy_ticket(models.ServiceTicket, 'https://www.example.com', "ST-random")
2015-06-12 21:57:11 +00:00
def test_validate_view_badservice():
factory = RequestFactory()
request = factory.get('/validate?ticket=ST-random&service=https://www.example2.com')
request.session = DummySession()
validate = Validate()
response = validate.get(request)
assert response.status_code == 200
2015-06-21 16:56:16 +00:00
assert response.content == b"no\n"
2015-06-12 21:57:11 +00:00
@pytest.mark.django_db
2015-06-21 16:56:16 +00:00
@dummy_ticket(models.ServiceTicket, 'https://www.example.com', "ST-random1")
2015-06-12 21:57:11 +00:00
def test_validate_view_badticket():
factory = RequestFactory()
request = factory.get('/validate?ticket=ST-random2&service=https://www.example.com')
request.session = DummySession()
validate = Validate()
response = validate.get(request)
assert response.status_code == 200
2015-06-21 16:56:16 +00:00
assert response.content == b"no\n"