I'd like to know when testing views is it better to create a request object using RequestFactory().get() or Client().get() or calling the view directly
RequestFactory():
from django.test import RequestFactory
from django.urls import reverse
def test_profile_view(self):
p1 = mixer.blend(Profile)
path = reverse('profile', kwargs={'pk': p1.id})
request = RequestFactory().get(path)
request.user = p1.user
response2 = views.profile_view(request, pk=p1.id)
assert response.status_code == 200
assert response.streaming == False
assert response2.charset == 'utf-8'
assert response2.status_code == 200
Client():
from django.test import Client
class TestView():
def test_profile_view(self):
p1 = mixer.blend(Profile)
path = reverse('profile', kwargs={'pk': p1.id})
response= Client().get(path)
response.user = p1.user
response2 = views.profile_view(request, pk=p1.id)
assert response.status_code == 200
assert response.streaming == False
assert response2.charset == 'utf-8'
assert response2.status_code == 200
and would like to understand the difference.