【问题标题】:How to run Django 1.6 LiveServerTestCase without HTTPS?如何在没有 HTTPS 的情况下运行 Django 1.6 LiveServerTestCase?
【发布时间】:2014-07-23 18:55:24
【问题描述】:

我有一个 Django 1.6 项目,我正在尝试在其中运行 LiveServerTestCase。但是,我的测试用例不需要 HTTPS,所以我想禁用它。有没有办法做到这一点?

我跑:

$ website/manage.py test website/tests.py:MySeleniumTests

Firefox 打开指向:

https://localhost:8081/

我可以在 8081 端口上运行安全服务器:

$ website/manage.py runserver_plus --cert cert 0.0.0.0:8081

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
'website.nucleus',
'website.blog',
'django_extensions',
'debug_toolbar',
'django_nose',
'django_coverage',
'tinymce',
'django_ztask',
'timezones',
'tracking',
'gunicorn',
'raven.contrib.django.raven_compat',
'social.apps.django_app.default',
'report_builder',
'bootstrapform',
'bootstrap3',

)

【问题讨论】:

  • 你的意思是浏览器打开https://...urls下的网页?你能展示你如何运行测试吗?谢谢。
  • 感谢您的回复。我用详细信息更新了问题。
  • 感谢您的更新。能否也显示INSTALLED_APPSMIDDLEWARE_CLASSES 设置?
  • 当我意识到我们安装了 SSL REDIRECT 中间件时,我开始发布 MIDDLEWARE_CLASSES。我对此发表了评论,瞧,实时服务器和我的硒测试开始工作了!如果您想写:寻找 SSL REDIRECT 中间件作为答案,我很乐意将其标记为已回答。感谢您的帮助!
  • 是的,这就是我问的原因,因为根据源代码,默认使用http协议。感谢您的更新:)

标签: python django http testing https


【解决方案1】:

默认情况下,Django 使用http:// 协议进行实时服务器测试,引用自source code

class LiveServerTestCase(TransactionTestCase):
    static_handler = _StaticFilesHandler

    @property
    def live_server_url(self):
        return 'http://%s:%s' % (
            self.server_thread.host, self.server_thread.port)

由于您看到测试中使用了https:// 协议,因此有些东西正在将您的请求重定向到https。检查您的MIDDLEWARE_CLASSES 设置。

例如,django-ssl-redirect 中间件可能是罪魁祸首。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 2015-05-01
    • 2015-03-01
    • 1970-01-01
    相关资源
    最近更新 更多