everyone!
I can't figure out how the sessions work in Django.
I have a shop, an anonymous user's shopping cart is bound to session_key.
The session key is taken from the request object.
def _check_session(self, request) -> int | str:
session_key = getattr(request.session, ‘session_key’, None)
if session_key:
return session_key
else:
request.session.create()
return request.session.session_key
I'm writing tests, one test adds items to the basket, I take the anonymous user client and make a post request to add, everything is ok.
Then in the second test, I take the same anonymous client, make a get request to get the contents of the basket.
But in this request the request object has no session_key.
Why in the second test, the request object does not contain a session_key? The client is the same.
These two tests are written within one TestCase.