Ticket #21740: client_mutable_argument_fix_02.patch

File client_mutable_argument_fix_02.patch, 3.4 KB (added by Aloïs Guillopé, 8 years ago)
  • django/test/client.py

    diff --git a/django/test/client.py b/django/test/client.py
    index 5dbc3e3..cdc63a5 100644
    a b class RequestFactory(object): 
    276276            path = path.encode('utf-8').decode('iso-8859-1')
    277277        return path
    278278
    279     def get(self, path, data={}, secure=False, **extra):
     279    def get(self, path, data=None, secure=False, **extra):
    280280        "Construct a GET request."
    281281
     282        if not data:
     283          data = {}
     284
    282285        r = {
    283286            'QUERY_STRING': urlencode(data, doseq=True),
    284287        }
    285288        r.update(extra)
    286289        return self.generic('GET', path, secure=secure, **r)
    287290
    288     def post(self, path, data={}, content_type=MULTIPART_CONTENT,
     291    def post(self, path, data=None, content_type=MULTIPART_CONTENT,
    289292             secure=False, **extra):
    290293        "Construct a POST request."
    291294
     295        if not data:
     296            data = {}
     297
    292298        post_data = self._encode_data(data, content_type)
    293299
    294300        return self.generic('POST', path, post_data, content_type,
    295301                            secure=secure, **extra)
    296302
    297     def head(self, path, data={}, secure=False, **extra):
     303    def head(self, path, data=None, secure=False, **extra):
    298304        "Construct a HEAD request."
    299305
     306        if not data:
     307            data= {}
     308
    300309        r = {
    301310            'QUERY_STRING': urlencode(data, doseq=True),
    302311        }
    class Client(RequestFactory): 
    460469            signals.template_rendered.disconnect(dispatch_uid=signal_uid)
    461470            got_request_exception.disconnect(dispatch_uid="request-exception")
    462471
    463     def get(self, path, data={}, follow=False, secure=False, **extra):
     472    def get(self, path, data=None, follow=False, secure=False, **extra):
    464473        """
    465474        Requests a response from the server using GET.
    466475        """
    class Client(RequestFactory): 
    470479            response = self._handle_redirects(response, **extra)
    471480        return response
    472481
    473     def post(self, path, data={}, content_type=MULTIPART_CONTENT,
     482    def post(self, path, data=None, content_type=MULTIPART_CONTENT,
    474483             follow=False, secure=False, **extra):
    475484        """
    476485        Requests a response from the server using POST.
    class Client(RequestFactory): 
    482491            response = self._handle_redirects(response, **extra)
    483492        return response
    484493
    485     def head(self, path, data={}, follow=False, secure=False, **extra):
     494    def head(self, path, data=None, follow=False, secure=False, **extra):
    486495        """
    487496        Request a response from the server using HEAD.
    488497        """
  • tests/test_client/tests.py

    diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py
    index 5fa6360..2a71ba5 100644
    a b class ClientTest(TestCase): 
    6565        self.assertTemplateNotUsed(response, 'Empty GET Template')
    6666        self.assertTemplateUsed(response, 'Empty POST Template')
    6767
     68    def test_no_post(self):
     69        "POST an empty dictionary to a view"
     70        response = self.client.post('/test_client/post_view/')
     71
     72        # Check some response details
     73        self.assertEqual(response.status_code, 200)
     74        self.assertEqual(response.templates[0].name, 'Empty POST Template')
     75        self.assertTemplateNotUsed(response, 'Empty GET Template')
     76        self.assertTemplateUsed(response, 'Empty POST Template')
     77
    6878    def test_post(self):
    6979        "POST some data to a view"
    7080        post_data = {
Back to Top