示例#1
0
文件: tests.py 项目: bitcpf/djangoage
from django.core.cache import cache
from django.core.handlers.wsgi import WSGIRequest
from django.db import close_connection
from django.template import context

import mock

import session_csrf
from session_csrf import (anonymous_csrf, anonymous_csrf_exempt,
                          CsrfMiddleware, PREFIX)


urlpatterns = patterns('',
    ('^$', lambda r: http.HttpResponse()),
    ('^anon$', anonymous_csrf(lambda r: http.HttpResponse())),
    ('^no-anon-csrf$', anonymous_csrf_exempt(lambda r: http.HttpResponse())),
    ('^logout$', anonymous_csrf(lambda r: logout(r) or http.HttpResponse())),
)


class TestCsrfToken(django.test.TestCase):

    def setUp(self):
        self.client.handler = ClientHandler()
        User.objects.create_user('jbalogh', '*****@*****.**', 'password')
        self.save_ANON_ALWAYS = session_csrf.ANON_ALWAYS
        session_csrf.ANON_ALWAYS = False

    def tearDown(self):
        session_csrf.ANON_ALWAYS = self.save_ANON_ALWAYS
示例#2
0
from django.core.cache import cache
from django.core.handlers.wsgi import WSGIRequest
from django.db import close_connection
from django.template import context

import mock

import session_csrf
from session_csrf import (anonymous_csrf, anonymous_csrf_exempt,
                          CsrfMiddleware, prep_key)

urlpatterns = patterns(
    '',
    ('^$', lambda r: http.HttpResponse()),
    ('^anon$', anonymous_csrf(lambda r: http.HttpResponse())),
    ('^no-anon-csrf$', anonymous_csrf_exempt(lambda r: http.HttpResponse())),
    ('^logout$', anonymous_csrf(lambda r: logout(r) or http.HttpResponse())),
)


class TestCsrfToken(django.test.TestCase):
    def setUp(self):
        self.client.handler = ClientHandler()
        User.objects.create_user('jbalogh', '*****@*****.**', 'password')
        self.save_ANON_ALWAYS = session_csrf.ANON_ALWAYS
        session_csrf.ANON_ALWAYS = False

    def tearDown(self):
        session_csrf.ANON_ALWAYS = self.save_ANON_ALWAYS

    def login(self):
示例#3
0
文件: urls.py 项目: ashanan/badger2
    (r'', include('examples.urls')),

    (r'^badges/', include('badger_multiplayer.urls')),
    (r'^badges/', include('badger.urls')),
    
    (r'^comments/', include('django.contrib.comments.urls')),

    (r'^profiles/', include('profiles.urls')),

    (r'^accounts/', include('django.contrib.auth.urls')),    
    (r'^accounts/', include('registration.backends.default.urls')),

    (r'^admin/', include(admin.site.urls)),

    #(r'^browserid/', include('django_browserid.urls')),
    # HACK: CSRF troubles wth browserid auth
    url(r'^browserid/verify/', 
        anonymous_csrf_exempt(django_browserid.views.verify),
        name="browserid_verify"),

)

## In DEBUG mode, serve media files through Django.
if settings.DEBUG:
    # Remove leading and trailing slashes so the regex matches.
    media_url = settings.MEDIA_URL.lstrip('/').rstrip('/')
    urlpatterns += patterns('',
        (r'^%s/(?P<path>.*)$' % media_url, 'django.views.static.serve',
         {'document_root': settings.MEDIA_ROOT}),
    )
示例#4
0
from django.core.exceptions import ImproperlyConfigured

import session_csrf
from session_csrf import (anonymous_csrf, anonymous_csrf_exempt,
                          CsrfMiddleware, prep_key)
try:
    from unittest import mock
except ImportError:
    # Python 2.7 doesn't have unittest.mock, but it is available on PyPi
    import mock

urlpatterns = [
    url('^$', lambda r: http.HttpResponse()),
    url('^anon$', anonymous_csrf(lambda r: http.HttpResponse())),
    url('^no-anon-csrf$',
        anonymous_csrf_exempt(lambda r: http.HttpResponse())),
    url('^logout$',
        anonymous_csrf(lambda r: logout(r) or http.HttpResponse())),
]


class TestCsrfToken(django.test.TestCase):
    def setUp(self):
        self.client.handler = ClientHandler()
        User.objects.create_user('jbalogh', '*****@*****.**', 'password')
        self.save_ANON_ALWAYS = session_csrf.ANON_ALWAYS
        session_csrf.ANON_ALWAYS = False

    def tearDown(self):
        session_csrf.ANON_ALWAYS = self.save_ANON_ALWAYS