]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Test fetch full URL if applicable 2002/head
authorAndrew Rabert <draje@nullsum.net>
Wed, 5 Apr 2017 02:29:46 +0000 (22:29 -0400)
committerAndrew Rabert <draje@nullsum.net>
Sat, 20 May 2017 19:20:43 +0000 (15:20 -0400)
tornado/test/testing_test.py

index b3d6d8c5bb7db45930ef88fdefe67f1765c1bac8..21ae7833d577da8bae63b26a48ca096c33e99352 100644 (file)
@@ -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):