我可以在LiveServerTestCase中使用jQuery.post()吗?

问题描述:

我在使用LiveServerTestCase,django-casper和casperjs编写包含javascript的视图的测试。通过客户端脚本的一半我有一个jQuery.post(url,callback_function(r){})行。我可以在LiveServerTestCase中使用jQuery.post()吗?

在测试过程中调用callback_function时,r为空。但是,当我正常运行应用程序,并在调用callback_function时通过相同的javascript步骤时,r具有期望的值。

这让我觉得有一个关于LiveServerTestCase的细节我很想让jQuery.post与它一起工作。任何人都可以阐明下一步我应该怎么做来调试这个问题?

我猜这是因为静态文件不在身边。在Django 1.7中,不再支持LiveServerTestCase提供静态文件。它被移动到testing.StaticLiveServerTestCase

尝试将您的测试类更改为子类StaticLiveServerTestCase