开发者

How do I properly unit test a Django session?

The behavior of Django sessions changes between "standard" views code and test code, making it unclear how test code is written for sessions. Googling this yields two relevant discussions about this issue:

  1. Easier manipulation of sessions by test client

  2. test.Client.session.save() raises error for anonymous users

I'm confused because both tickets have different ways of dealing with this problem and they were both Accepted. I assume this means they were patched and the behavior is now dif开发者_如何学运维ferent. I also don't know to which versions these patches would pertain.

If I'm writing a unit test in Django 1.0, how would I set up my session store for sessions to work as they do in the browser?


I don't quite understand what do you mean by saying the behavior changes between "standard" view and "test" code, maybe you should elaborate on that.

but regarding how to test the session, I do think there are approaches.

  1. you have to understand how django session works, read the unit test for the session package you used in your application. this is regarding understand how server side works.
  2. you probably need to capture a few conversations between browser and server( using FIREBUG for example )

so the issue for you looks like that you are not passing session_id you get when you log in back to server when you talk to server. like put it in (POST,GET,COOKIES I don't quite remember that ).

The important thing here is understand how session works in HTTP, once you get that, you definitely have a clear idea about what is happening there, and make explainations accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜