Open picturedots opened 2 weeks ago
You might consider using Django’s standard django.test.client.Client
for your tests.
Additionally, Django now supports an asynchronous client django.test.client.AsyncClient
that can be beneficial for testing async views.
AttributeError: Mock object has no attribute 'session' This error is raised when using TestClient to test a login endpoint that uses
django.contrib.auth.login
because the mock request object as defined here https://github.com/vitalik/django-ninja/blob/master/ninja/testing/client.py#L128-L138 is missing a session attribute.Possible Solution I was able to solve this issue on my own by monkey patching the test client by defining a function like
and then using this new function to replace the
_build_request
function in my TestClient instance likeMaybe a better solution would be to use a SessionStore mock?