11
11
import requests
12
12
from requests .compat import urlparse
13
13
14
- import requests_unixsocket
14
+ from requests_unixsocket import monkeypatch , Session , Settings , UnixAdapter
15
15
from requests_unixsocket .testutils import UnixSocketServerThread
16
16
17
17
@@ -36,13 +36,13 @@ def get_sock_prefix(path):
36
36
sockpath , tail = os .path .split (sockpath )
37
37
reqpath_parts .append (tail )
38
38
39
- return requests_unixsocket . UnixAdapter . Settings .ParseResult (
39
+ return Settings .ParseResult (
40
40
sockpath = sockpath ,
41
41
reqpath = '/' + os .path .join (* reversed (reqpath_parts )),
42
42
)
43
43
44
44
45
- alt_settings_1 = requests_unixsocket . UnixAdapter . Settings (
45
+ alt_settings_1 = Settings (
46
46
urlparse = lambda url : get_sock_prefix (urlparse (url ).path ),
47
47
)
48
48
@@ -62,7 +62,7 @@ def test_use_UnixAdapter_directly():
62
62
63
63
def test_unix_domain_adapter_ok ():
64
64
with UnixSocketServerThread () as usock_thread :
65
- session = requests_unixsocket . Session ('http+unix://' )
65
+ session = Session ('http+unix://' )
66
66
urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
67
67
url = 'http+unix://%s/path/to/page' % urlencoded_usock
68
68
@@ -78,7 +78,7 @@ def test_unix_domain_adapter_ok():
78
78
assert r .headers ['X-Transport' ] == 'unix domain socket'
79
79
assert r .headers ['X-Requested-Path' ] == '/path/to/page'
80
80
assert r .headers ['X-Socket-Path' ] == usock_thread .usock
81
- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
81
+ assert isinstance (r .connection , UnixAdapter )
82
82
assert r .url .lower () == url .lower ()
83
83
if method == 'head' :
84
84
assert r .text == ''
@@ -88,7 +88,7 @@ def test_unix_domain_adapter_ok():
88
88
89
89
def test_unix_domain_adapter_alt_settings_1_ok ():
90
90
with UnixSocketServerThread () as usock_thread :
91
- session = requests_unixsocket . Session (
91
+ session = Session (
92
92
url_scheme = 'http+unix://' ,
93
93
settings = alt_settings_1 ,
94
94
)
@@ -106,7 +106,7 @@ def test_unix_domain_adapter_alt_settings_1_ok():
106
106
assert r .headers ['X-Transport' ] == 'unix domain socket'
107
107
assert r .headers ['X-Requested-Path' ] == '/path/to/page'
108
108
assert r .headers ['X-Socket-Path' ] == usock_thread .usock
109
- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
109
+ assert isinstance (r .connection , UnixAdapter )
110
110
assert r .url .lower () == url .lower ()
111
111
if method == 'head' :
112
112
assert r .text == ''
@@ -116,7 +116,7 @@ def test_unix_domain_adapter_alt_settings_1_ok():
116
116
117
117
def test_unix_domain_adapter_url_with_query_params ():
118
118
with UnixSocketServerThread () as usock_thread :
119
- session = requests_unixsocket . Session ('http+unix://' )
119
+ session = Session ('http+unix://' )
120
120
urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
121
121
url = ('http+unix://%s'
122
122
'/containers/nginx/logs?timestamp=true' % urlencoded_usock )
@@ -134,7 +134,7 @@ def test_unix_domain_adapter_url_with_query_params():
134
134
assert r .headers ['X-Requested-Path' ] == '/containers/nginx/logs'
135
135
assert r .headers ['X-Requested-Query-String' ] == 'timestamp=true'
136
136
assert r .headers ['X-Socket-Path' ] == usock_thread .usock
137
- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
137
+ assert isinstance (r .connection , UnixAdapter )
138
138
assert r .url .lower () == url .lower ()
139
139
if method == 'head' :
140
140
assert r .text == ''
@@ -144,7 +144,7 @@ def test_unix_domain_adapter_url_with_query_params():
144
144
145
145
def test_unix_domain_adapter_url_with_fragment ():
146
146
with UnixSocketServerThread () as usock_thread :
147
- session = requests_unixsocket . Session ('http+unix://' )
147
+ session = Session ('http+unix://' )
148
148
urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
149
149
url = ('http+unix://%s'
150
150
'/containers/nginx/logs#some-fragment' % urlencoded_usock )
@@ -161,7 +161,7 @@ def test_unix_domain_adapter_url_with_fragment():
161
161
assert r .headers ['X-Transport' ] == 'unix domain socket'
162
162
assert r .headers ['X-Requested-Path' ] == '/containers/nginx/logs'
163
163
assert r .headers ['X-Socket-Path' ] == usock_thread .usock
164
- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
164
+ assert isinstance (r .connection , UnixAdapter )
165
165
assert r .url .lower () == url .lower ()
166
166
if method == 'head' :
167
167
assert r .text == ''
@@ -170,7 +170,7 @@ def test_unix_domain_adapter_url_with_fragment():
170
170
171
171
172
172
def test_unix_domain_adapter_connection_error ():
173
- session = requests_unixsocket . Session ('http+unix://' )
173
+ session = Session ('http+unix://' )
174
174
175
175
for method in ['get' , 'post' , 'head' , 'patch' , 'put' , 'delete' , 'options' ]:
176
176
with pytest .raises (requests .ConnectionError ):
@@ -179,7 +179,7 @@ def test_unix_domain_adapter_connection_error():
179
179
180
180
181
181
def test_unix_domain_adapter_connection_proxies_error ():
182
- session = requests_unixsocket . Session ('http+unix://' )
182
+ session = Session ('http+unix://' )
183
183
184
184
for method in ['get' , 'post' , 'head' , 'patch' , 'put' , 'delete' , 'options' ]:
185
185
with pytest .raises (ValueError ) as excinfo :
@@ -192,7 +192,7 @@ def test_unix_domain_adapter_connection_proxies_error():
192
192
193
193
def test_unix_domain_adapter_monkeypatch ():
194
194
with UnixSocketServerThread () as usock_thread :
195
- with requests_unixsocket . monkeypatch ('http+unix://' ):
195
+ with monkeypatch ('http+unix://' ):
196
196
urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
197
197
url = 'http+unix://%s/path/to/page' % urlencoded_usock
198
198
@@ -209,7 +209,7 @@ def test_unix_domain_adapter_monkeypatch():
209
209
assert r .headers ['X-Requested-Path' ] == '/path/to/page'
210
210
assert r .headers ['X-Socket-Path' ] == usock_thread .usock
211
211
assert isinstance (r .connection ,
212
- requests_unixsocket . UnixAdapter )
212
+ UnixAdapter )
213
213
assert r .url .lower () == url .lower ()
214
214
if method == 'head' :
215
215
assert r .text == ''
0 commit comments