Opened 3 years ago

Closed 3 years ago

#21341 closed New feature (fixed)

Clean way of making https requests with test client

Reported by: Unai Zalakain Owned by: Unai Zalakain
Component: Testing framework Version: master
Severity: Normal Keywords: testing, client, https, secure
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is the current way of making an https request with the testing client:

from django.test import Client

client = Client()
client.get('/', {'wsgi.url_scheme': 'https'})

This is quite obscure and undocumented, something like client.get('/', secure=True) would be far cleaner. The way django.test.client.Client and django.test.client.RequestFactory are build, we would need to modify each request method in both of them.

Change History (10)

comment:1 Changed 3 years ago by Unai Zalakain

Summary: Add a secure kwarg to testing client request methodsClean way for making https request with test client

comment:2 Changed 3 years ago by Unai Zalakain

Summary: Clean way for making https request with test clientClean way of making https request with test client

comment:3 Changed 3 years ago by Unai Zalakain

Summary: Clean way of making https request with test clientClean way of making https requests with test client

comment:4 Changed 3 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted

comment:5 Changed 3 years ago by Unai Zalakain

Has patch: set

PR sent: https://github.com/django/django/pull/1820

All the request methods of django.test.client.Client receive a secure
argument that defaults to False indicating wether or not to make the
request through https.

comment:6 Changed 3 years ago by Unai Zalakain

This would make #13725 easier too.

comment:7 Changed 3 years ago by Unai Zalakain

Status: newassigned

comment:8 Changed 3 years ago by Aymeric Augustin

Triage Stage: AcceptedReady for checkin

This looks pretty good to me. I left a few comments on the pull request. I'm marking as RFC anyway because these comments are minor and could be made by the committer.

comment:9 Changed 3 years ago by Unai Zalakain

Thanks for the review, suggestions applied!

comment:10 Changed 3 years ago by Claude Paroz

Resolution: fixed
Status: assignedclosed

In: 99b681e227b5b7880d6edd0d8dd670034d431859

Fixed #21341 -- Eased https requests with the test client

Note: See TracTickets for help on using tickets.
Back to Top