mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 11:04:02 +03:00
update testing.md - fixes related to RequestsClient (#5959)
* Include import for RequestsClient in the docs. * Use fully qualified URLs for `RequestsClient` in the docs.
This commit is contained in:
parent
a11938ce96
commit
8c03c49400
|
@ -201,6 +201,8 @@ live environment. (See "Live tests" below.)
|
||||||
This exposes exactly the same interface as if you were using a requests session
|
This exposes exactly the same interface as if you were using a requests session
|
||||||
directly.
|
directly.
|
||||||
|
|
||||||
|
from rest_framework.test import RequestsClient
|
||||||
|
|
||||||
client = RequestsClient()
|
client = RequestsClient()
|
||||||
response = client.get('http://testserver/users/')
|
response = client.get('http://testserver/users/')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -237,12 +239,12 @@ For example...
|
||||||
client = RequestsClient()
|
client = RequestsClient()
|
||||||
|
|
||||||
# Obtain a CSRF token.
|
# Obtain a CSRF token.
|
||||||
response = client.get('/homepage/')
|
response = client.get('http://testserver/homepage/')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
csrftoken = response.cookies['csrftoken']
|
csrftoken = response.cookies['csrftoken']
|
||||||
|
|
||||||
# Interact with the API.
|
# Interact with the API.
|
||||||
response = client.post('/organisations/', json={
|
response = client.post('http://testserver/organisations/', json={
|
||||||
'name': 'MegaCorp',
|
'name': 'MegaCorp',
|
||||||
'status': 'active'
|
'status': 'active'
|
||||||
}, headers={'X-CSRFToken': csrftoken})
|
}, headers={'X-CSRFToken': csrftoken})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user