#34640: Add query_params argument to test Client methods
---------------------------------------------+------------------------
               Reporter:  Dan Strokirk       |          Owner:  nobody
                   Type:  New feature        |         Status:  new
              Component:  Testing framework  |        Version:  dev
               Severity:  Normal             |       Keywords:
           Triage Stage:  Unreviewed         |      Has patch:  0
    Needs documentation:  0                  |    Needs tests:  0
Patch needs improvement:  0                  |  Easy pickings:  0
                  UI/UX:  0                  |
---------------------------------------------+------------------------
 Using `Client.get` it’s currently very easy to add new query parameters to
 the fake request, you can simply provide them to data argument. Very nice
 and ergonomic.

 However, for the other HTTP methods, like post, this doesn’t work, since
 of course they use the same parameter for their form data. So adding a new
 argument to all methods would make it easier to test other HTTP methods.
 Since `request.GET` is getting renamed to `query_params`, that would be an
 excellent name for the new argument.

 This would make it possible to change this type of testing code:

 {{{
 url = reverse("view_name", args=[obj.id]) + f"?param={val}"
 self.client.post(url, data=data)
 }}}

 to this

 {{{
 url = reverse("view_name", args=[obj.id])
 self.client.post(url, query_params={"param": val"}, data=data)
 }}}

 `Client.get` would still support setting params via the `data` argument,
 to avoid unnecessary deprecation churn in old projects. Using both `data`
 and `query_params` together in `Client.get` would throw a `ValueError`.

 Taken from: https://forum.djangoproject.com/t/suggestion-adding-params-to-
 testclient-http-methods/21246/1

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34640>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070188975deace-795c4298-b7be-4d22-8fc2-c35fe9e15f2a-000000%40eu-central-1.amazonses.com.

Reply via email to