在龙卷风测试中拒绝连接

2024-10-01 15:31:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为我正在收集的Tornado代码库创建测试。我让项目运行良好,但我写的第一个测试是连接拒绝错误。在

代码如下:

import unittest, os, os.path, sys, urllib
import tornado.options
from tornado.options import options
from tornado.testing import AsyncHTTPTestCase


APP_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(APP_ROOT, '..'))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))

from main import Application

app = Application()

def clear_db(app=None):
    os.system("mysql -u user --password=pw --database=testdb < %s" % (os.path.join(APP_ROOT, 'db', 'schema.sql')))

class TestHandlerBase(AsyncHTTPTestCase):
    def setUp(self):
        clear_db()
        super(TestHandlerBase, self).setUp()

    def get_app(self):
        return app

    def get_http_port(self):
        return 5000

class TestRootHandler(TestHandlerBase):
    def test_redirect(self):
        response = self.fetch(
            '/',
            method='GET',
            follow_redirects=False)
        print response
        self.assertTrue(response.headers['Location'].endswith('/login'))

我得到的回答是:

^{pr2}$

你知道是什么导致了这个错误吗?我有没有遗漏一个步骤来让所有的东西都为考试而运转?谢谢!!!在


Tags: pathfromimportselfappdbosdef
2条回答

我同意科尔·麦克莱恩的回答

如果需要配置自定义URL,则重写下面的AsyncHTTPTestCase方法

def get_url(self, path):
    url = 'http://localhost:8080' + path
    return url

在这个场景中,默认情况下,这个URL是http://localhost:8080。在

不要重写get_http_port。每个测试都会设置一个带有新端口的新HTTP服务器,因此它不会每次都是5000个,即使您的设置就是这样。在

相关问题 更多 >

    热门问题