mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
fix #1249: catch exceptions when requesting with disabling allow_redirects
This commit is contained in:
+6
-2
@@ -1,12 +1,16 @@
|
|||||||
# Release History
|
# Release History
|
||||||
|
|
||||||
|
## 3.1.10 (2022-04-18)
|
||||||
|
|
||||||
|
- fix #1249: catch exceptions when requesting with disabling allow_redirects
|
||||||
|
|
||||||
## 3.1.9 (2022-04-17)
|
## 3.1.9 (2022-04-17)
|
||||||
|
|
||||||
- fix #1174: pydantic validation error when body is None
|
- fix #1174: pydantic validation error when body is None
|
||||||
- fix #1209: only convert jmespath path for some fields in white list
|
- fix #1209: only convert jmespath path for some fields in white list
|
||||||
- fix #1233: parse upload info with session variables
|
- fix #1233: parse upload info with session variables
|
||||||
- fix #1246: catch exceptions when getting socket address failed
|
- fix #1246: catch exceptions caused by GA report failure
|
||||||
- fix #1247: catch exceptions caused by GA report failure
|
- fix #1247: catch exceptions when getting socket address failed
|
||||||
|
|
||||||
## 3.1.8 (2022-03-22)
|
## 3.1.8 (2022-03-22)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
__version__ = "3.1.9"
|
__version__ = "3.1.10"
|
||||||
__description__ = "One-stop solution for HTTP(S) testing."
|
__description__ = "One-stop solution for HTTP(S) testing."
|
||||||
|
|
||||||
# import firstly for monkey patch if needed
|
# import firstly for monkey patch if needed
|
||||||
|
|||||||
@@ -189,10 +189,11 @@ class HttpSession(requests.Session):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
server_ip, server_port = response.raw._connection.sock.getpeername()
|
server_ip, server_port = response.raw._connection.sock.getpeername()
|
||||||
except Exception:
|
|
||||||
self.data.address.server_ip = server_ip
|
self.data.address.server_ip = server_ip
|
||||||
self.data.address.server_port = server_port
|
self.data.address.server_port = server_port
|
||||||
logger.debug(f"server IP: {server_ip}, Port: {server_port}")
|
logger.debug(f"server IP: {server_ip}, Port: {server_port}")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# get length of the response content
|
# get length of the response content
|
||||||
content_size = int(dict(response.headers).get("content-length") or 0)
|
content_size = int(dict(response.headers).get("content-length") or 0)
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "httprunner"
|
name = "httprunner"
|
||||||
version = "3.1.9"
|
version = "3.1.10"
|
||||||
description = "One-stop solution for HTTP(S) testing."
|
description = "One-stop solution for HTTP(S) testing."
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
readme = "docs/README.md"
|
readme = "docs/README.md"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import unittest
|
|||||||
|
|
||||||
from httprunner import loader
|
from httprunner import loader
|
||||||
from httprunner.cli import main_run
|
from httprunner.cli import main_run
|
||||||
|
from httprunner.client import HttpSession
|
||||||
from httprunner.runner import HttpRunner
|
from httprunner.runner import HttpRunner
|
||||||
|
|
||||||
|
|
||||||
@@ -38,3 +39,68 @@ class TestHttpRunner(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.exists("tests/data/debugtalk.py"))
|
self.assertTrue(os.path.exists("tests/data/debugtalk.py"))
|
||||||
self.assertTrue(os.path.exists("tests/data/a_b_c/T1_test.py"))
|
self.assertTrue(os.path.exists("tests/data/a_b_c/T1_test.py"))
|
||||||
self.assertTrue(os.path.exists("tests/data/a_b_c/T2_3_test.py"))
|
self.assertTrue(os.path.exists("tests/data/a_b_c/T2_3_test.py"))
|
||||||
|
|
||||||
|
|
||||||
|
class TestHttpSession(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.session = HttpSession()
|
||||||
|
|
||||||
|
def test_request_http(self):
|
||||||
|
self.session.request("get", "http://httpbin.org/get")
|
||||||
|
address = self.session.data.address
|
||||||
|
self.assertGreater(len(address.server_ip), 0)
|
||||||
|
self.assertEqual(address.server_port, 80)
|
||||||
|
self.assertGreater(len(address.client_ip), 0)
|
||||||
|
self.assertGreater(address.client_port, 10000)
|
||||||
|
|
||||||
|
def test_request_https(self):
|
||||||
|
self.session.request("get", "https://httpbin.org/get")
|
||||||
|
address = self.session.data.address
|
||||||
|
self.assertGreater(len(address.server_ip), 0)
|
||||||
|
self.assertEqual(address.server_port, 443)
|
||||||
|
self.assertGreater(len(address.client_ip), 0)
|
||||||
|
self.assertGreater(address.client_port, 10000)
|
||||||
|
|
||||||
|
def test_request_http_allow_redirects(self):
|
||||||
|
self.session.request(
|
||||||
|
"get",
|
||||||
|
"http://httpbin.org/redirect-to?url=https%3A%2F%2Fgithub.com",
|
||||||
|
allow_redirects=True)
|
||||||
|
address = self.session.data.address
|
||||||
|
self.assertNotEqual(address.server_ip, "N/A")
|
||||||
|
self.assertEqual(address.server_port, 443)
|
||||||
|
self.assertNotEqual(address.server_ip, "N/A")
|
||||||
|
self.assertGreater(address.client_port, 10000)
|
||||||
|
|
||||||
|
def test_request_https_allow_redirects(self):
|
||||||
|
self.session.request(
|
||||||
|
"get",
|
||||||
|
"https://httpbin.org/redirect-to?url=https%3A%2F%2Fgithub.com",
|
||||||
|
allow_redirects=True)
|
||||||
|
address = self.session.data.address
|
||||||
|
self.assertNotEqual(address.server_ip, "N/A")
|
||||||
|
self.assertEqual(address.server_port, 443)
|
||||||
|
self.assertNotEqual(address.server_ip, "N/A")
|
||||||
|
self.assertGreater(address.client_port, 10000)
|
||||||
|
|
||||||
|
def test_request_http_not_allow_redirects(self):
|
||||||
|
self.session.request(
|
||||||
|
"get",
|
||||||
|
"http://httpbin.org/redirect-to?url=https%3A%2F%2Fgithub.com",
|
||||||
|
allow_redirects=False)
|
||||||
|
address = self.session.data.address
|
||||||
|
self.assertEqual(address.server_ip, "N/A")
|
||||||
|
self.assertEqual(address.server_port, 0)
|
||||||
|
self.assertEqual(address.client_ip, "N/A")
|
||||||
|
self.assertEqual(address.client_port, 0)
|
||||||
|
|
||||||
|
def test_request_https_not_allow_redirects(self):
|
||||||
|
self.session.request(
|
||||||
|
"get",
|
||||||
|
"https://httpbin.org/redirect-to?url=https%3A%2F%2Fgithub.com",
|
||||||
|
allow_redirects=False)
|
||||||
|
address = self.session.data.address
|
||||||
|
self.assertEqual(address.server_ip, "N/A")
|
||||||
|
self.assertEqual(address.server_port, 0)
|
||||||
|
self.assertEqual(address.client_ip, "N/A")
|
||||||
|
self.assertEqual(address.client_port, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user