I'm writing my first django project and I'm trying to make it as basic as possible. Rather than authenticating users, for the time being, I'm using cookies to identify people (if my understanding of what I'm doing is correct). In my views.py, I have a method that does the following:
request.session["username"] = request.POST.get('username')
How do I set request.session["username"]
within tests.py?
request.session["username"] = "Barry"
doesn't seem to work, and neither does self.client.session["username"] = "Barry"
. I've been trying a few things that I saw at https://docs.djangoproject.com/en/1.9/topics/http/sessions/#using-sessions-out-of-views but there is a good chance that I haven't done it properly as I don't really understand what I'm doing. I also found this: Setting a session variable in django tests which gave me NameError: global name 'import_module' is not defined
when I tried to use it. Any help or suggest reading (preferably beginner level) is appreciated.