测试 Django Facebook 应用程序
我正在使用 Fandjango 制作一个 Django 应用程序,并尝试使用 Django 的测试框架对其进行单元测试。唯一的事情是,为了有效地进行测试,我需要 Facebook 在每个请求中发送一个“signed_request”参数。现在,我正在记录我的服务器从 Facebook 收到的请求,并复制+粘贴我收到的signed_request 令牌,但这一次只能工作几个小时。
有没有一种简单的方法可以处理这个问题,而无需模拟整个 Facebook API?
谢谢!
I'm making a Django app with Fandjango and I'm trying to unit test it with Django's test framework. The only thing is, in order to test effectively I need a "signed_request" parameter that Facebook sends with every request. Right now I'm logging the requests my server gets from Facebook and copying + pasting the signed_request token I get, but that only works for a few hours at a time.
Is there a simple way to handle this without doing a mock of the whole Facebook API?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用测试用户:
http://developers.facebook.com/docs/test_users/
我认为访问令牌永远不会过期,或者至少在您删除测试用户之前。
You can use Test Users:
http://developers.facebook.com/docs/test_users/
I think the access token never expires, or at less until you delete the Test User.
嗯,我知道也可以仅使用 OAuth 而不使用 Javascript SDK 来进行完全服务器端身份验证。在这种情况下,您应该能够自己获取有效的令牌。我认为有一些库可以用于此目的,例如:
http://pypi .python.org/pypi/django-social-auth/
但是请注意,我自己从未这样做过,所以这更多的是一个建议,而不是一个明确的答案。
编辑
似乎social-auth有一些测试功能,能够自动登录Facebook帐户。您可能可以从那里复制代码。
Well, I understand it's also possible to authenticate fully server side, using just OAuth without Javascript SDK. In that case you should be able to aquire a valid token yourself. There are, I think some libraries that can be used for that like:
http://pypi.python.org/pypi/django-social-auth/
However please note, I've never done this myself so it's more of a suggestion, than a definite answer.
EDIT
It seems like social-auth has some testing functionality that is capable of automatically signing in to a facebook account. You could probably copy the code from there.