Ticket #15596: ticket15596.diff

File ticket15596.diff, 10.6 KB (added by Łukasz Rekucki, 14 years ago)
  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index 74a5afa..de71f68 100644
    a b class HttpRequest(object):  
    257257
    258258    def _load_post_and_files(self):
    259259        # Populates self._post and self._files
    260         if self.method != 'POST':
     260        if self.method not in ('POST', 'PUT'):
    261261            self._post, self._files = QueryDict('', encoding=self._encoding), MultiValueDict()
    262262            return
    263263        if self._read_started:
  • django/test/client.py

    diff --git a/django/test/client.py b/django/test/client.py
    index dd0d811..e5e7f0e 100644
    a b class RequestFactory(object):  
    214214        else:
    215215            return urllib.unquote(parsed[2])
    216216
    217     def get(self, path, data={}, **extra):
     217    def _getlike_request(self, method, path, data={}, **extra):
    218218        "Construct a GET request"
    219219
    220220        parsed = urlparse(path)
    class RequestFactory(object):  
    222222            'CONTENT_TYPE':    'text/html; charset=utf-8',
    223223            'PATH_INFO':       self._get_path(parsed),
    224224            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
    225             'REQUEST_METHOD': 'GET',
     225            'REQUEST_METHOD':  method,
    226226            'wsgi.input':      FakePayload('')
    227227        }
    228228        r.update(extra)
    229229        return self.request(**r)
    230230
    231     def post(self, path, data={}, content_type=MULTIPART_CONTENT,
    232              **extra):
    233         "Construct a POST request."
     231    def get(self, *args, **kwargs):
     232        return self._getlike_request("GET", *args, **kwargs)
     233
     234    def head(self, *args, **kwargs):
     235        return self._getlike_request("HEAD", *args, **kwargs)
     236
     237    def options(self, *args, **kwargs):
     238        return self._getlike_request("OPTIONS", *args, **kwargs)
     239
     240    def delete(self, *args, **kwargs):
     241        return self._getlike_request("DELETE", *args, **kwargs)
    234242
     243    def _postlike_request(self, method, path, data={}, content_type=MULTIPART_CONTENT, **extra):
    235244        if content_type is MULTIPART_CONTENT:
    236245            post_data = encode_multipart(BOUNDARY, data)
    237246        else:
    class RequestFactory(object):  
    249258            'CONTENT_TYPE':   content_type,
    250259            'PATH_INFO':      self._get_path(parsed),
    251260            'QUERY_STRING':   parsed[4],
    252             'REQUEST_METHOD': 'POST',
    253             'wsgi.input':     FakePayload(post_data),
    254         }
    255         r.update(extra)
    256         return self.request(**r)
    257 
    258     def head(self, path, data={}, **extra):
    259         "Construct a HEAD request."
    260 
    261         parsed = urlparse(path)
    262         r = {
    263             'CONTENT_TYPE':    'text/html; charset=utf-8',
    264             'PATH_INFO':       self._get_path(parsed),
    265             'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
    266             'REQUEST_METHOD': 'HEAD',
    267             'wsgi.input':      FakePayload('')
    268         }
    269         r.update(extra)
    270         return self.request(**r)
    271 
    272     def options(self, path, data={}, **extra):
    273         "Constrict an OPTIONS request"
    274 
    275         parsed = urlparse(path)
    276         r = {
    277             'PATH_INFO':       self._get_path(parsed),
    278             'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
    279             'REQUEST_METHOD': 'OPTIONS',
    280             'wsgi.input':      FakePayload('')
    281         }
    282         r.update(extra)
    283         return self.request(**r)
    284 
    285     def put(self, path, data={}, content_type=MULTIPART_CONTENT,
    286             **extra):
    287         "Construct a PUT request."
    288 
    289         if content_type is MULTIPART_CONTENT:
    290             post_data = encode_multipart(BOUNDARY, data)
    291         else:
    292             post_data = data
    293 
    294         # Make `data` into a querystring only if it's not already a string. If
    295         # it is a string, we'll assume that the caller has already encoded it.
    296         query_string = None
    297         if not isinstance(data, basestring):
    298             query_string = urlencode(data, doseq=True)
    299 
    300         parsed = urlparse(path)
    301         r = {
    302             'CONTENT_LENGTH': len(post_data),
    303             'CONTENT_TYPE':   content_type,
    304             'PATH_INFO':      self._get_path(parsed),
    305             'QUERY_STRING':   query_string or parsed[4],
    306             'REQUEST_METHOD': 'PUT',
     261            'REQUEST_METHOD': method,
    307262            'wsgi.input':     FakePayload(post_data),
    308263        }
    309264        r.update(extra)
    310265        return self.request(**r)
    311266
    312     def delete(self, path, data={}, **extra):
    313         "Construct a DELETE request."
     267    def post(self, *args, **kwargs):
     268        return self._postlike_request("POST", *args, **kwargs)
    314269
    315         parsed = urlparse(path)
    316         r = {
    317             'PATH_INFO':       self._get_path(parsed),
    318             'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
    319             'REQUEST_METHOD': 'DELETE',
    320             'wsgi.input':      FakePayload('')
    321         }
    322         r.update(extra)
    323         return self.request(**r)
     270    def put(self, *args, **kwargs):
     271        return self._postlike_request("PUT", *args, **kwargs)
    324272
    325273
    326274class Client(RequestFactory):
  • tests/modeltests/test_client/models.py

    diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py
    index 0960929..a4789fb 100644
    a b rather than the HTML rendered to the end-user.  
    2323from django.conf import settings
    2424from django.core import mail
    2525from django.test import Client, TestCase, RequestFactory
     26from django.utils import unittest
    2627
    2728from views import get_view
    2829
    class ClientTest(TestCase):  
    445446        self.assertEqual(mail.outbox[1].to[0], 'second@example.com')
    446447        self.assertEqual(mail.outbox[1].to[1], 'third@example.com')
    447448
     449
    448450class CSRFEnabledClientTests(TestCase):
    449451    def setUp(self):
    450452        # Enable the CSRF middleware for this test
    class RequestFactoryTest(TestCase):  
    487489        response = get_view(request)
    488490
    489491        self.assertEqual(response.status_code, 200)
    490         self.assertContains(response, 'This is a test')
     492        self.assertContains(response, 'This is a test')
     493 No newline at end of file
  • tests/regressiontests/generic_views/edit.py

    diff --git a/tests/regressiontests/generic_views/edit.py b/tests/regressiontests/generic_views/edit.py
    index 923578d..9fdfe83 100644
    a b class UpdateViewTests(TestCase):  
    111111        self.assertRedirects(res, 'http://testserver/list/authors/')
    112112        self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (xkcd)>'])
    113113
    114     @expectedFailure
    115114    def test_update_put(self):
    116115        a = Author.objects.create(
    117116            name='Randall Munroe',
  • tests/regressiontests/test_client_regress/models.py

    diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
    index 8f39961..9ebf3d2 100644
    a b class RequestMethodStringDataTests(TestCase):  
    744744
    745745class QueryStringTests(TestCase):
    746746    def test_get_like_requests(self):
    747         for method_name in ('get','head','options','put','delete'):
     747        for method_name in ('get','head','options','delete'):
    748748            # A GET-like request can pass a query string as data
    749749            method = getattr(self.client, method_name)
    750750            response = method("/test_client_regress/request_data/", data={'foo':'whiz'})
    class QueryStringTests(TestCase):  
    768768            self.assertEqual(response.context['request-bar'], 'bang')
    769769
    770770    def test_post_like_requests(self):
    771         # A POST-like request can pass a query string as data
    772         response = self.client.post("/test_client_regress/request_data/", data={'foo':'whiz'})
    773         self.assertEqual(response.context['get-foo'], None)
    774         self.assertEqual(response.context['post-foo'], 'whiz')
     771        for method_name in ('post', 'put'):
     772            # A POST-like request can pass a query string as data
     773            method = getattr(self.client, method_name)
     774            response = method("/test_client_regress/request_data/", data={'foo':'whiz'})
     775            self.assertEqual(response.context['get-foo'], None)
     776            self.assertEqual(response.context['post-foo'], 'whiz')
    775777
    776         # A POST-like request can pass a query string as part of the URL
    777         response = self.client.post("/test_client_regress/request_data/?foo=whiz")
    778         self.assertEqual(response.context['get-foo'], 'whiz')
    779         self.assertEqual(response.context['post-foo'], None)
    780         self.assertEqual(response.context['request-foo'], 'whiz')
     778            # A POST-like request can pass a query string as part of the URL
     779            response = method("/test_client_regress/request_data/?foo=whiz")
     780            self.assertEqual(response.context['get-foo'], 'whiz')
     781            self.assertEqual(response.context['post-foo'], None)
     782            self.assertEqual(response.context['request-foo'], 'whiz')
    781783
    782         # POST data provided in the URL augments actual form data
    783         response = self.client.post("/test_client_regress/request_data/?foo=whiz", data={'foo':'bang'})
    784         self.assertEqual(response.context['get-foo'], 'whiz')
    785         self.assertEqual(response.context['post-foo'], 'bang')
    786         self.assertEqual(response.context['request-foo'], 'bang')
     784            # POST data provided in the URL augments actual form data
     785            response = method("/test_client_regress/request_data/?foo=whiz", data={'foo':'bang'})
     786            self.assertEqual(response.context['get-foo'], 'whiz')
     787            self.assertEqual(response.context['post-foo'], 'bang')
     788            self.assertEqual(response.context['request-foo'], 'bang')
    787789
    788         response = self.client.post("/test_client_regress/request_data/?foo=whiz", data={'bar':'bang'})
    789         self.assertEqual(response.context['get-foo'], 'whiz')
    790         self.assertEqual(response.context['get-bar'], None)
    791         self.assertEqual(response.context['post-foo'], None)
    792         self.assertEqual(response.context['post-bar'], 'bang')
    793         self.assertEqual(response.context['request-foo'], 'whiz')
    794         self.assertEqual(response.context['request-bar'], 'bang')
     790            response = method("/test_client_regress/request_data/?foo=whiz", data={'bar':'bang'})
     791            self.assertEqual(response.context['get-foo'], 'whiz')
     792            self.assertEqual(response.context['get-bar'], None)
     793            self.assertEqual(response.context['post-foo'], None)
     794            self.assertEqual(response.context['post-bar'], 'bang')
     795            self.assertEqual(response.context['request-foo'], 'whiz')
     796            self.assertEqual(response.context['request-bar'], 'bang')
    795797
    796798class UnicodePayloadTests(TestCase):
    797799    def test_simple_unicode_payload(self):
Back to Top