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,20 +36,20 @@ 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
4949
5050def test_unix_domain_adapter_ok ():
5151 with UnixSocketServerThread () as usock_thread :
52- session = requests_unixsocket . Session ('http+unix://' )
52+ session = Session ('http+unix://' )
5353 urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
5454 url = 'http+unix://%s/path/to/page' % urlencoded_usock
5555
@@ -65,7 +65,7 @@ def test_unix_domain_adapter_ok():
6565 assert r .headers ['X-Transport' ] == 'unix domain socket'
6666 assert r .headers ['X-Requested-Path' ] == '/path/to/page'
6767 assert r .headers ['X-Socket-Path' ] == usock_thread .usock
68- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
68+ assert isinstance (r .connection , UnixAdapter )
6969 assert r .url .lower () == url .lower ()
7070 if method == 'head' :
7171 assert r .text == ''
@@ -75,7 +75,7 @@ def test_unix_domain_adapter_ok():
7575
7676def test_unix_domain_adapter_alt_settings_1_ok ():
7777 with UnixSocketServerThread () as usock_thread :
78- session = requests_unixsocket . Session (
78+ session = Session (
7979 url_scheme = 'http+unix://' ,
8080 settings = alt_settings_1 ,
8181 )
@@ -93,7 +93,7 @@ def test_unix_domain_adapter_alt_settings_1_ok():
9393 assert r .headers ['X-Transport' ] == 'unix domain socket'
9494 assert r .headers ['X-Requested-Path' ] == '/path/to/page'
9595 assert r .headers ['X-Socket-Path' ] == usock_thread .usock
96- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
96+ assert isinstance (r .connection , UnixAdapter )
9797 assert r .url .lower () == url .lower ()
9898 if method == 'head' :
9999 assert r .text == ''
@@ -103,7 +103,7 @@ def test_unix_domain_adapter_alt_settings_1_ok():
103103
104104def test_unix_domain_adapter_url_with_query_params ():
105105 with UnixSocketServerThread () as usock_thread :
106- session = requests_unixsocket . Session ('http+unix://' )
106+ session = Session ('http+unix://' )
107107 urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
108108 url = ('http+unix://%s'
109109 '/containers/nginx/logs?timestamp=true' % urlencoded_usock )
@@ -121,7 +121,7 @@ def test_unix_domain_adapter_url_with_query_params():
121121 assert r .headers ['X-Requested-Path' ] == '/containers/nginx/logs'
122122 assert r .headers ['X-Requested-Query-String' ] == 'timestamp=true'
123123 assert r .headers ['X-Socket-Path' ] == usock_thread .usock
124- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
124+ assert isinstance (r .connection , UnixAdapter )
125125 assert r .url .lower () == url .lower ()
126126 if method == 'head' :
127127 assert r .text == ''
@@ -131,7 +131,7 @@ def test_unix_domain_adapter_url_with_query_params():
131131
132132def test_unix_domain_adapter_url_with_fragment ():
133133 with UnixSocketServerThread () as usock_thread :
134- session = requests_unixsocket . Session ('http+unix://' )
134+ session = Session ('http+unix://' )
135135 urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
136136 url = ('http+unix://%s'
137137 '/containers/nginx/logs#some-fragment' % urlencoded_usock )
@@ -148,7 +148,7 @@ def test_unix_domain_adapter_url_with_fragment():
148148 assert r .headers ['X-Transport' ] == 'unix domain socket'
149149 assert r .headers ['X-Requested-Path' ] == '/containers/nginx/logs'
150150 assert r .headers ['X-Socket-Path' ] == usock_thread .usock
151- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
151+ assert isinstance (r .connection , UnixAdapter )
152152 assert r .url .lower () == url .lower ()
153153 if method == 'head' :
154154 assert r .text == ''
@@ -157,7 +157,7 @@ def test_unix_domain_adapter_url_with_fragment():
157157
158158
159159def test_unix_domain_adapter_connection_error ():
160- session = requests_unixsocket . Session ('http+unix://' )
160+ session = Session ('http+unix://' )
161161
162162 for method in ['get' , 'post' , 'head' , 'patch' , 'put' , 'delete' , 'options' ]:
163163 with pytest .raises (requests .ConnectionError ):
@@ -166,7 +166,7 @@ def test_unix_domain_adapter_connection_error():
166166
167167
168168def test_unix_domain_adapter_connection_proxies_error ():
169- session = requests_unixsocket . Session ('http+unix://' )
169+ session = Session ('http+unix://' )
170170
171171 for method in ['get' , 'post' , 'head' , 'patch' , 'put' , 'delete' , 'options' ]:
172172 with pytest .raises (ValueError ) as excinfo :
@@ -179,7 +179,7 @@ def test_unix_domain_adapter_connection_proxies_error():
179179
180180def test_unix_domain_adapter_monkeypatch ():
181181 with UnixSocketServerThread () as usock_thread :
182- with requests_unixsocket . monkeypatch ('http+unix://' ):
182+ with monkeypatch ('http+unix://' ):
183183 urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
184184 url = 'http+unix://%s/path/to/page' % urlencoded_usock
185185
@@ -196,7 +196,7 @@ def test_unix_domain_adapter_monkeypatch():
196196 assert r .headers ['X-Requested-Path' ] == '/path/to/page'
197197 assert r .headers ['X-Socket-Path' ] == usock_thread .usock
198198 assert isinstance (r .connection ,
199- requests_unixsocket . UnixAdapter )
199+ UnixAdapter )
200200 assert r .url .lower () == url .lower ()
201201 if method == 'head' :
202202 assert r .text == ''
0 commit comments