1111import requests
1212from requests .compat import urlparse
1313
14- import requests_unixsocket
14+ from requests_unixsocket import monkeypatch , Session , Settings , UnixAdapter
1515from requests_unixsocket .testutils import UnixSocketServerThread
1616
1717
@@ -36,13 +36,13 @@ def get_sock_prefix(path):
3636 sockpath , tail = os .path .split (sockpath )
3737 reqpath_parts .append (tail )
3838
39- return requests_unixsocket . UnixAdapter . Settings .ParseResult (
39+ return Settings .ParseResult (
4040 sockpath = sockpath ,
4141 reqpath = '/' + os .path .join (* reversed (reqpath_parts )),
4242 )
4343
4444
45- alt_settings_1 = requests_unixsocket . UnixAdapter . Settings (
45+ alt_settings_1 = Settings (
4646 urlparse = lambda url : get_sock_prefix (urlparse (url ).path ),
4747)
4848
@@ -62,7 +62,7 @@ def test_use_UnixAdapter_directly():
6262
6363def test_unix_domain_adapter_ok ():
6464 with UnixSocketServerThread () as usock_thread :
65- session = requests_unixsocket . Session ('http+unix://' )
65+ session = Session ('http+unix://' )
6666 urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
6767 url = 'http+unix://%s/path/to/page' % urlencoded_usock
6868
@@ -78,7 +78,7 @@ def test_unix_domain_adapter_ok():
7878 assert r .headers ['X-Transport' ] == 'unix domain socket'
7979 assert r .headers ['X-Requested-Path' ] == '/path/to/page'
8080 assert r .headers ['X-Socket-Path' ] == usock_thread .usock
81- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
81+ assert isinstance (r .connection , UnixAdapter )
8282 assert r .url .lower () == url .lower ()
8383 if method == 'head' :
8484 assert r .text == ''
@@ -88,7 +88,7 @@ def test_unix_domain_adapter_ok():
8888
8989def test_unix_domain_adapter_alt_settings_1_ok ():
9090 with UnixSocketServerThread () as usock_thread :
91- session = requests_unixsocket . Session (
91+ session = Session (
9292 url_scheme = 'http+unix://' ,
9393 settings = alt_settings_1 ,
9494 )
@@ -106,7 +106,7 @@ def test_unix_domain_adapter_alt_settings_1_ok():
106106 assert r .headers ['X-Transport' ] == 'unix domain socket'
107107 assert r .headers ['X-Requested-Path' ] == '/path/to/page'
108108 assert r .headers ['X-Socket-Path' ] == usock_thread .usock
109- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
109+ assert isinstance (r .connection , UnixAdapter )
110110 assert r .url .lower () == url .lower ()
111111 if method == 'head' :
112112 assert r .text == ''
@@ -116,7 +116,7 @@ def test_unix_domain_adapter_alt_settings_1_ok():
116116
117117def test_unix_domain_adapter_url_with_query_params ():
118118 with UnixSocketServerThread () as usock_thread :
119- session = requests_unixsocket . Session ('http+unix://' )
119+ session = Session ('http+unix://' )
120120 urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
121121 url = ('http+unix://%s'
122122 '/containers/nginx/logs?timestamp=true' % urlencoded_usock )
@@ -134,7 +134,7 @@ def test_unix_domain_adapter_url_with_query_params():
134134 assert r .headers ['X-Requested-Path' ] == '/containers/nginx/logs'
135135 assert r .headers ['X-Requested-Query-String' ] == 'timestamp=true'
136136 assert r .headers ['X-Socket-Path' ] == usock_thread .usock
137- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
137+ assert isinstance (r .connection , UnixAdapter )
138138 assert r .url .lower () == url .lower ()
139139 if method == 'head' :
140140 assert r .text == ''
@@ -144,7 +144,7 @@ def test_unix_domain_adapter_url_with_query_params():
144144
145145def test_unix_domain_adapter_url_with_fragment ():
146146 with UnixSocketServerThread () as usock_thread :
147- session = requests_unixsocket . Session ('http+unix://' )
147+ session = Session ('http+unix://' )
148148 urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
149149 url = ('http+unix://%s'
150150 '/containers/nginx/logs#some-fragment' % urlencoded_usock )
@@ -161,7 +161,7 @@ def test_unix_domain_adapter_url_with_fragment():
161161 assert r .headers ['X-Transport' ] == 'unix domain socket'
162162 assert r .headers ['X-Requested-Path' ] == '/containers/nginx/logs'
163163 assert r .headers ['X-Socket-Path' ] == usock_thread .usock
164- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
164+ assert isinstance (r .connection , UnixAdapter )
165165 assert r .url .lower () == url .lower ()
166166 if method == 'head' :
167167 assert r .text == ''
@@ -170,7 +170,7 @@ def test_unix_domain_adapter_url_with_fragment():
170170
171171
172172def test_unix_domain_adapter_connection_error ():
173- session = requests_unixsocket . Session ('http+unix://' )
173+ session = Session ('http+unix://' )
174174
175175 for method in ['get' , 'post' , 'head' , 'patch' , 'put' , 'delete' , 'options' ]:
176176 with pytest .raises (requests .ConnectionError ):
@@ -179,7 +179,7 @@ def test_unix_domain_adapter_connection_error():
179179
180180
181181def test_unix_domain_adapter_connection_proxies_error ():
182- session = requests_unixsocket . Session ('http+unix://' )
182+ session = Session ('http+unix://' )
183183
184184 for method in ['get' , 'post' , 'head' , 'patch' , 'put' , 'delete' , 'options' ]:
185185 with pytest .raises (ValueError ) as excinfo :
@@ -192,7 +192,7 @@ def test_unix_domain_adapter_connection_proxies_error():
192192
193193def test_unix_domain_adapter_monkeypatch ():
194194 with UnixSocketServerThread () as usock_thread :
195- with requests_unixsocket . monkeypatch ('http+unix://' ):
195+ with monkeypatch ('http+unix://' ):
196196 urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
197197 url = 'http+unix://%s/path/to/page' % urlencoded_usock
198198
@@ -209,7 +209,7 @@ def test_unix_domain_adapter_monkeypatch():
209209 assert r .headers ['X-Requested-Path' ] == '/path/to/page'
210210 assert r .headers ['X-Socket-Path' ] == usock_thread .usock
211211 assert isinstance (r .connection ,
212- requests_unixsocket . UnixAdapter )
212+ UnixAdapter )
213213 assert r .url .lower () == url .lower ()
214214 if method == 'head' :
215215 assert r .text == ''
0 commit comments