Ticket #12522: 12522-tests.diff

File 12522-tests.diff, 2.9 KB (added by ramiro, 5 years ago)

Tests converted to unit tests

  • tests/regressiontests/requests/tests.py

    diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py
    a b  
    55from django.core.handlers.modpython import ModPythonRequest
    66from django.core.handlers.wsgi import WSGIRequest, LimitedStream
    77from django.http import HttpRequest, HttpResponse, parse_cookie
     8from django.test.client import MULTIPART_CONTENT, BOUNDARY, FakePayload, encode_multipart
    89from django.utils import unittest
    910from django.utils.http import cookie_date
    1011
     
    133134        request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
    134135        self.assertEqual(request.read(), 'name=value')
    135136
    136     def test_read_after_value(self):
     137    def test_read_after_POST(self):
    137138        """
    138139        Reading from request is allowed after accessing request contents as
    139         POST or raw_post_data.
     140        POST.
    140141        """
    141142        request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
    142143        self.assertEqual(request.POST, {u'name': [u'value']})
     144        self.assertEqual(request.read(), 'name=value')
     145
     146    def test_read_after_raw_post_data(self):
     147        """
     148        Reading from request is allowed after accessing request contents as
     149        raw_post_data.
     150        """
     151        request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
    143152        self.assertEqual(request.raw_post_data, 'name=value')
    144153        self.assertEqual(request.read(), 'name=value')
    145154
     
    156165    def test_read_by_lines(self):
    157166        request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
    158167        self.assertEqual(list(request), ['name=value'])
     168
     169    def test_POST_after_raw_post_data(self):
     170        post_data = encode_multipart(BOUNDARY,dict(testkey="testvalue"))
     171        env =  {
     172            'SERVER_PROTOCOL': 'HTTP/1.0',
     173            'REQUEST_METHOD': 'POST',
     174            'wsgi.input': FakePayload(post_data),
     175            'CONTENT_TYPE': MULTIPART_CONTENT,
     176            'CONTENT_LENGTH': len(post_data)
     177        }
     178        request = WSGIRequest(env)
     179        nop = request.raw_post_data  # Access the raw data
     180        self.assertEqual(request.POST['testkey'], 'testvalue') # POST still should be accesible
     181
     182    def test_raw_post_data_after_POST(self):
     183        post_data = encode_multipart(BOUNDARY,dict(testkey="testvalue"))
     184        env =  {
     185            'SERVER_PROTOCOL': 'HTTP/1.0',
     186            'REQUEST_METHOD': 'POST',
     187            'wsgi.input': FakePayload(post_data),
     188            'CONTENT_TYPE': MULTIPART_CONTENT,
     189            'CONTENT_LENGTH': len(post_data)
     190        }
     191        request = WSGIRequest(env)
     192        nop = request.POST['testkey'] # Access POST
     193        self.assertEqual(len(request.raw_post_data), len(post_data)) # raw_post_data still should be accesible
Back to Top