Ticket #12747: 0002-Test-that-the-custom-response-shows-up-on-the-WSGI-l.patch

File 0002-Test-that-the-custom-response-shows-up-on-the-WSGI-l.patch, 3.0 KB (added by gisle, 15 years ago)

Test that the custom response shows up on the WSGI level as well

  • new file tests/regressiontests/wsgi/tests.py

    From ed18cc83ad6e3e93cb7c4aca9a964feb7f0765fd Mon Sep 17 00:00:00 2001
    From: Gisle Aas <gisle@aas.no>
    Date: Tue, 23 Feb 2010 09:19:24 -0500
    Subject: [PATCH 2/2] Test that the custom response shows up on the WSGI level as well
    
    ---
     tests/regressiontests/wsgi/tests.py    |   24 ++++++++++++++++++++++++
     tests/regressiontests/wsgi/urls.py     |    5 +++++
     tests/regressiontests/wsgi/views.py    |    4 ++++
     tests/urls.py                          |    3 +++
     4 files changed, 36 insertions(+), 0 deletions(-)
     create mode 100644 tests/regressiontests/wsgi/__init__.py
     create mode 100644 tests/regressiontests/wsgi/models.py
     create mode 100644 tests/regressiontests/wsgi/tests.py
     create mode 100644 tests/regressiontests/wsgi/urls.py
     create mode 100644 tests/regressiontests/wsgi/views.py
    
    diff --git a/tests/regressiontests/wsgi/__init__.py b/tests/regressiontests/wsgi/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/wsgi/models.py b/tests/regressiontests/wsgi/models.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/wsgi/tests.py b/tests/regressiontests/wsgi/tests.py
    new file mode 100644
    index 0000000..3d62129
    - +  
     1from unittest import TestCase
     2from django.core.handlers.wsgi import WSGIHandler
     3
     4class Tests(TestCase):
     5    def test_custom_status(self):
     6        class Object(object): pass
     7        response = Object()
     8
     9        def start_response(status, headers):
     10            response.status = status
     11            response.headers = headers
     12
     13        app = WSGIHandler()
     14        content = app({
     15            'REQUEST_METHOD': 'GET',
     16            'PATH_INFO': '/wsgi/custom_status/',
     17            'SERVER_NAME': 'localhost',
     18            'SERVER_PORT': '80',
     19            'SERVER_PROTOCOL': 'HTTP/1.0',
     20        }, start_response)
     21        response.content = "".join(content)
     22
     23        self.assertEqual(response.status, "220 Pretty good")
     24        self.assertEqual(response.content, "Hello")
  • new file tests/regressiontests/wsgi/urls.py

    diff --git a/tests/regressiontests/wsgi/urls.py b/tests/regressiontests/wsgi/urls.py
    new file mode 100644
    index 0000000..26d8ea2
    - +  
     1from django.conf.urls.defaults import *
     2
     3urlpatterns = patterns('',
     4    (r'^custom_status/', 'regressiontests.wsgi.views.custom_status'),
     5)
  • new file tests/regressiontests/wsgi/views.py

    diff --git a/tests/regressiontests/wsgi/views.py b/tests/regressiontests/wsgi/views.py
    new file mode 100644
    index 0000000..deecfd9
    - +  
     1from django.http import HttpResponse
     2
     3def custom_status(request):
     4    return HttpResponse("Hello", status="220 Pretty good")
  • tests/urls.py

    diff --git a/tests/urls.py b/tests/urls.py
    index 01d6408..eed06c2 100644
    a b urlpatterns = patterns('',  
    4141
    4242    # special headers views
    4343    (r'special_headers/', include('regressiontests.special_headers.urls')),
     44
     45    # try to run the wsgi handler directly
     46    (r'wsgi/', include('regressiontests.wsgi.urls'))
    4447)
Back to Top