From 445c036bc93373d88ff7895b9bb155ec1e2d214d Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Tue, 4 Apr 2017 22:29:46 -0400 Subject: [PATCH] Test fetch full URL if applicable --- tornado/test/testing_test.py | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tornado/test/testing_test.py b/tornado/test/testing_test.py index b3d6d8c5b..21ae7833d 100644 --- a/tornado/test/testing_test.py +++ b/tornado/test/testing_test.py @@ -4,8 +4,9 @@ from __future__ import absolute_import, division, print_function from tornado import gen, ioloop from tornado.log import app_log -from tornado.testing import AsyncTestCase, gen_test, ExpectLog from tornado.test.util import unittest, skipBefore35, exec_test +from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, bind_unused_port, gen_test, ExpectLog +from tornado.web import Application import contextlib import os import traceback @@ -75,6 +76,40 @@ class AsyncTestCaseTest(AsyncTestCase): self.assertEqual(str(cm.exception), "error one") +class AsyncHTTPTestCaseTest(AsyncHTTPTestCase): + @classmethod + def setUpClass(cls): + super(AsyncHTTPTestCaseTest, cls).setUpClass() + # An unused port is bound so we can make requests upon it without + # impacting a real local web server. + cls.external_sock, cls.external_port = bind_unused_port() + + def get_app(self): + return Application() + + def test_fetch_segment(self): + path = '/path' + response = self.fetch(path) + self.assertEqual(response.request.url, self.get_url(path)) + + def test_fetch_full_http_url(self): + path = 'http://localhost:%d/path' % self.external_port + + response = self.fetch(path, request_timeout=0.1) + self.assertEqual(response.request.url, path) + + def test_fetch_full_https_url(self): + path = 'https://localhost:%d/path' % self.external_port + + response = self.fetch(path, request_timeout=0.1) + self.assertEqual(response.request.url, path) + + @classmethod + def tearDownClass(cls): + cls.external_sock.close() + super(AsyncHTTPTestCaseTest, cls).tearDownClass() + + class AsyncTestCaseWrapperTest(unittest.TestCase): def test_undecorated_generator(self): class Test(AsyncTestCase): -- 2.47.2