0

I have a unittest which access an internal api and which sets value in session.

eg.

def api_work(request):
    request.session['stuff'] = True

Now for me to test it:

def test_api(self):
    self.client.get(/api_work/)
    # self.client.session is empty dictionary

My question is if it's possible to use library like MagicMock to make self.client.session shadow the request.session?

James Lin
  • 25,028
  • 36
  • 133
  • 233
  • Maybe these can be useful http://stackoverflow.com/questions/4453764/how-do-i-modify-the-session-in-the-django-test-framework http://stackoverflow.com/questions/7502116/how-to-use-session-in-testcase-in-django ..... or maybe I've completely misunderstood your question :) – Michele d'Amico Mar 02 '15 at 23:16
  • @Micheled'Amico yeah I have been through those 2 already, my problem is the session data during the request is different to accessing `self.client.session` – James Lin Mar 03 '15 at 00:18

0 Answers0