Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantage of using RequestsClient() over APIClient()?

I am writing unittest for Django-rest-framework API endpoints. In version 3.5, they have added RequestsClient(). Documentation says -

Rather than sending any HTTP requests to the network, this interface will coerce all outgoing requests into WSGI, and call into your application directly.

From my understanding, I think RequestsClient() is useful for the network request from different servers. Not sure if it has any advantage in the same server? Also Is there any advantage of using RequestsClient() over APIClient() ?

like image 361
Md. Al-Amin Avatar asked Dec 14 '22 02:12

Md. Al-Amin


1 Answers

Is there any advantage of using RequestsClient() over APIClient()

This is a higher lever of test. RequestsClient will test against your stack from the WSGI layer which APIClient bypasses. This also means that tests that uses authentication or CSRF will be looking more like what happens with real requests.

like image 70
Linovia Avatar answered Jun 10 '23 04:06

Linovia