def test_signal_when_user_logout_manual(monkeypatch, django_user_model):
    session = SessionStore()
    session['fake_session_key'] = 'fake-session_value'
    session.save()
    assert SessionStore(session_key=session.session_key) is not None

    factory = RequestFactory()
    request = factory.get('/logout')
    request.session = session

    # Create a fake session ticket and make sure it exists in the db
    session_ticket = SessionTicket.objects.create(
        session_key=session.session_key,
        ticket='fake-ticket'
    )

    user = django_user_model.objects.create_user('*****@*****.**', '')
    assert user is not None
    request.user = user

    callback_values = {}

    @receiver(cas_user_logout)
    def callback(sender, session, **kwargs):
        callback_values.update(kwargs)
        callback_values['session'] = dict(session)

    response = logout(request)
    assert request.user.is_anonymous() is True
    assert 'user' in callback_values
    assert callback_values['user'] == user
    assert 'session' in callback_values
    assert callback_values['session'].get('fake_session_key') == 'fake-session_value'
    assert 'ticket' in callback_values
    assert callback_values['ticket'] == 'fake-ticket'
示例#2
0
def test_signal_when_user_logout_manual(monkeypatch, django_user_model):
    session = SessionStore()
    session['fake_session_key'] = 'fake-session_value'
    session.save()
    assert SessionStore(session_key=session.session_key) is not None

    factory = RequestFactory()
    request = factory.get('/logout')
    request.session = session

    # Create a fake session ticket and make sure it exists in the db
    session_ticket = SessionTicket.objects.create(
        session_key=session.session_key, ticket='fake-ticket')

    user = django_user_model.objects.create_user('*****@*****.**', '')
    assert user is not None
    request.user = user

    callback_values = {}

    @receiver(cas_user_logout)
    def callback(sender, session, **kwargs):
        callback_values.update(kwargs)
        callback_values['session'] = dict(session)

    response = logout(request)
    assert request.user.is_anonymous() is True
    assert 'user' in callback_values
    assert callback_values['user'] == user
    assert 'session' in callback_values
    assert callback_values['session'].get(
        'fake_session_key') == 'fake-session_value'
    assert 'ticket' in callback_values
    assert callback_values['ticket'] == 'fake-ticket'
示例#3
0
def test_logout_completely(django_user_model, settings):
    """
    Test the case where the user logs out.
    """
    settings.CAS_LOGOUT_COMPLETELY = True

    factory = RequestFactory()
    request = factory.get('/logout/')
    # Create a session object from the middleware
    process_request_for_middleware(request, SessionMiddleware)

    user = django_user_model.objects.create_user('*****@*****.**', '')
    assert user is not None
    request.user = user

    response = logout(request)
    assert response.status_code == 302
    assert request.user.is_anonymous() is True
示例#4
0
def test_logout_completely(django_user_model, settings):
    """
    Test the case where the user logs out.
    """
    settings.CAS_LOGOUT_COMPLETELY = True

    factory = RequestFactory()
    request = factory.get('/logout/')
    # Create a session object from the middleware
    process_request_for_middleware(request, SessionMiddleware)

    user = django_user_model.objects.create_user('*****@*****.**', '')
    assert user is not None
    request.user = user

    response = logout(request)
    assert response.status_code == 302
    assert request.user.is_anonymous() is True
示例#5
0
def logout(request, **kwargs):
    return casviews.logout(request, **kwargs)
示例#6
0
def test_logout_delete_not_allowed():
    factory = RequestFactory()
    request = factory.delete('/logout/')
    response = logout(request)
    assert response.status_code == 405
示例#7
0
def test_logout_delete_not_allowed():
    factory = RequestFactory()
    request = factory.delete('/logout/')
    response = logout(request)
    assert response.status_code == 405
示例#8
0
def page_logout(request):
    if settings.CAS_AUTH:
        return cas_views.logout(request)
    else:
        logout(request)
        return page_login(request)
示例#9
0
def cas_logout(request):
    return cas_views.logout(request)
示例#10
0
文件: html.py 项目: zptime/interact
def page_logout(request):
    return cas_views.logout(request)