|
32 | 32 | from urllib3._collections import HTTPHeaderDict
|
33 | 33 |
|
34 | 34 | from elasticsearch import __versionstr__
|
| 35 | +from elasticsearch.compat import reraise_exceptions |
35 | 36 | from elasticsearch.connection import (
|
36 | 37 | Connection,
|
37 | 38 | RequestsHttpConnection,
|
38 | 39 | Urllib3HttpConnection,
|
39 | 40 | )
|
40 | 41 | from elasticsearch.exceptions import (
|
41 | 42 | ConflictError,
|
| 43 | + ConnectionError, |
42 | 44 | NotFoundError,
|
43 | 45 | RequestError,
|
44 | 46 | TransportError,
|
@@ -466,6 +468,21 @@ def test_surrogatepass_into_bytes(self):
|
466 | 468 | status, headers, data = con.perform_request("GET", "/")
|
467 | 469 | self.assertEqual(u"你好\uda6a", data)
|
468 | 470 |
|
| 471 | + @pytest.mark.skipif( |
| 472 | + not reraise_exceptions, reason="RecursionError isn't defined in Python <3.5" |
| 473 | + ) |
| 474 | + def test_recursion_error_reraised(self): |
| 475 | + conn = Urllib3HttpConnection() |
| 476 | + |
| 477 | + def urlopen_raise(*_, **__): |
| 478 | + raise RecursionError("Wasn't modified!") |
| 479 | + |
| 480 | + conn.pool.urlopen = urlopen_raise |
| 481 | + |
| 482 | + with pytest.raises(RecursionError) as e: |
| 483 | + conn.perform_request("GET", "/") |
| 484 | + assert str(e.value) == "Wasn't modified!" |
| 485 | + |
469 | 486 |
|
470 | 487 | class TestRequestsConnection(TestCase):
|
471 | 488 | def _get_mock_connection(
|
@@ -868,6 +885,21 @@ def test_surrogatepass_into_bytes(self):
|
868 | 885 | status, headers, data = con.perform_request("GET", "/")
|
869 | 886 | self.assertEqual(u"你好\uda6a", data)
|
870 | 887 |
|
| 888 | + @pytest.mark.skipif( |
| 889 | + not reraise_exceptions, reason="RecursionError isn't defined in Python <3.5" |
| 890 | + ) |
| 891 | + def test_recursion_error_reraised(self): |
| 892 | + conn = RequestsHttpConnection() |
| 893 | + |
| 894 | + def send_raise(*_, **__): |
| 895 | + raise RecursionError("Wasn't modified!") |
| 896 | + |
| 897 | + conn.session.send = send_raise |
| 898 | + |
| 899 | + with pytest.raises(RecursionError) as e: |
| 900 | + conn.perform_request("GET", "/") |
| 901 | + assert str(e.value) == "Wasn't modified!" |
| 902 | + |
871 | 903 |
|
872 | 904 | class TestConnectionHttpbin:
|
873 | 905 | """Tests the HTTP connection implementations against a live server E2E"""
|
@@ -942,6 +974,11 @@ def test_urllib3_connection(self):
|
942 | 974 | "User-Agent": user_agent,
|
943 | 975 | }
|
944 | 976 |
|
| 977 | + def test_urllib3_connection_error(self): |
| 978 | + conn = Urllib3HttpConnection("not.a.host.name") |
| 979 | + with pytest.raises(ConnectionError): |
| 980 | + conn.perform_request("GET", "/") |
| 981 | + |
945 | 982 | def test_requests_connection(self):
|
946 | 983 | # Defaults
|
947 | 984 | conn = RequestsHttpConnection("httpbin.org", port=443, use_ssl=True)
|
@@ -1003,3 +1040,8 @@ def test_requests_connection(self):
|
1003 | 1040 | "Header2": "value2",
|
1004 | 1041 | "User-Agent": user_agent,
|
1005 | 1042 | }
|
| 1043 | + |
| 1044 | + def test_requests_connection_error(self): |
| 1045 | + conn = RequestsHttpConnection("not.a.host.name") |
| 1046 | + with pytest.raises(ConnectionError): |
| 1047 | + conn.perform_request("GET", "/") |
0 commit comments