def test_not_final_path(self): """ The path to be consumed by the WSGI app must be the end of the original PATH_INFO. """ # Loading a WSGI-powered Django view: headers = [("X-SALUTATION", "Hey")] app = MockApp("206 One step at a time", headers) django_view = make_wsgi_view(app) # Running a request: environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/app1/wsgi-view/foo/bar") request = _make_request(**environ) # Checking the response. Note "/foo" is NOT the end of PATH_INFO: assert_raises(ApplicationCallError, django_view, request, "/foo")
def test_not_final_path(self): """ The path to be consumed by the WSGI app must be the end of the original PATH_INFO. """ # Loading a WSGI-powered Django view: headers = [("X-SALUTATION", "Hey")] app = MockApp("206 One step at a time", headers) django_view = make_wsgi_view(app) # Running a request: environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/app1/wsgi-view/foo/bar") request = _make_request(**environ) # Checking the response. Note "/foo" is NOT the end of PATH_INFO: self.assertRaises(ApplicationCallError, django_view, request, "/foo")
def test_right_path(self): """ The WSGI application view must work when called with the right path. """ # Loading a WSGI-powered Django view: headers = [("X-SALUTATION", "Hey")] app = MockApp("206 One step at a time", headers) django_view = make_wsgi_view(app) # Running a request: environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/app1/wsgi-view/foo/bar") request = _make_request(**environ) # Checking the response: django_response = django_view(request, "/foo/bar") self.assertEqual(django_response.status_code, 206) self.assertEqual(("X-SALUTATION", "Hey"), django_response._headers['x-salutation']) self.assertEqual(app.environ['PATH_INFO'], "/foo/bar") self.assertEqual(app.environ['SCRIPT_NAME'], "/dev/app1/wsgi-view")
def test_right_path(self): """ The WSGI application view must work when called with the right path. """ # Loading a WSGI-powered Django view: headers = [("X-SALUTATION", "Hey")] app = MockApp("206 One step at a time", headers) django_view = make_wsgi_view(app) # Running a request: environ = complete_environ(SCRIPT_NAME="/dev", PATH_INFO="/app1/wsgi-view/foo/bar") request = _make_request(**environ) # Checking the response: django_response = django_view(request, "/foo/bar") eq_(django_response.status_code, 206) eq_(("X-SALUTATION", "Hey"), django_response._headers['x-salutation']) eq_(app.environ['PATH_INFO'], "/foo/bar") eq_(app.environ['SCRIPT_NAME'], "/dev/app1/wsgi-view")
# license should accompany this distribution. THIS SOFTWARE IS PROVIDED "AS IS" # AND ANY AND ALL EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED, INCLUDING, BUT # NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST # INFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. # ############################################################################## """ URL definitions for the mock Django application. """ from django.conf.urls.defaults import patterns from twod.wsgi import make_wsgi_view from tests import MockApp from tests.fixtures.sampledjango import mock_view app = make_wsgi_view(MockApp("206 One step at a time", [("X-SALUTATION", "Hey")])) ok_app = make_wsgi_view(MockApp("200 OK", [("X-SALUTATION", "Hey")])) urlpatterns = patterns('', (r'^blog', mock_view), (r'^admin', mock_view), (r'^secret', mock_view), (r"wsgi-view-ok(/.*)?", ok_app), (r"wsgi-view(/.*)?", app), )
# Uncomment the next two lines to enable the admin: # from django.contrib import admin # admin.autodiscover() from .wsgi import application as wsgi_application service_modules = ['webservice'] ladon_application = LadonWSGIApplication(service_modules, [settings.BASE]) urlpatterns = patterns('', # Examples: # url(r'^$', 'example.views.home', name='home'), # url(r'^example/', include('example.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: # url(r'^admin/', include(admin.site.urls)), url(r'^api/rpc(/.*)$', csrf_exempt(make_wsgi_view(ladon_application))), url(r'^wsgi(/.*)$', make_wsgi_view(wsgi_application)), ) if settings.DEBUG: from django.conf.urls.static import static from django.contrib.staticfiles.urls import staticfiles_urlpatterns urlpatterns += staticfiles_urlpatterns() urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# AND ANY AND ALL EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED, INCLUDING, BUT # NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST # INFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. # ############################################################################## """ URL definitions for the mock Django application. """ from django.conf.urls.defaults import patterns from twod.wsgi import make_wsgi_view from tests import MockApp from tests.fixtures.sampledjango import mock_view app = make_wsgi_view( MockApp("206 One step at a time", [("X-SALUTATION", "Hey")])) ok_app = make_wsgi_view(MockApp("200 OK", [("X-SALUTATION", "Hey")])) urlpatterns = patterns( '', (r'^blog', mock_view), (r'^admin', mock_view), (r'^secret', mock_view), (r"wsgi-view-ok(/.*)?", ok_app), (r"wsgi-view(/.*)?", app), )