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,20 +36,20 @@ 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
49
49
50
50
def test_unix_domain_adapter_ok ():
51
51
with UnixSocketServerThread () as usock_thread :
52
- session = requests_unixsocket . Session ('http+unix://' )
52
+ session = Session ('http+unix://' )
53
53
urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
54
54
url = 'http+unix://%s/path/to/page' % urlencoded_usock
55
55
@@ -65,7 +65,7 @@ def test_unix_domain_adapter_ok():
65
65
assert r .headers ['X-Transport' ] == 'unix domain socket'
66
66
assert r .headers ['X-Requested-Path' ] == '/path/to/page'
67
67
assert r .headers ['X-Socket-Path' ] == usock_thread .usock
68
- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
68
+ assert isinstance (r .connection , UnixAdapter )
69
69
assert r .url .lower () == url .lower ()
70
70
if method == 'head' :
71
71
assert r .text == ''
@@ -75,7 +75,7 @@ def test_unix_domain_adapter_ok():
75
75
76
76
def test_unix_domain_adapter_alt_settings_1_ok ():
77
77
with UnixSocketServerThread () as usock_thread :
78
- session = requests_unixsocket . Session (
78
+ session = Session (
79
79
url_scheme = 'http+unix://' ,
80
80
settings = alt_settings_1 ,
81
81
)
@@ -93,7 +93,7 @@ def test_unix_domain_adapter_alt_settings_1_ok():
93
93
assert r .headers ['X-Transport' ] == 'unix domain socket'
94
94
assert r .headers ['X-Requested-Path' ] == '/path/to/page'
95
95
assert r .headers ['X-Socket-Path' ] == usock_thread .usock
96
- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
96
+ assert isinstance (r .connection , UnixAdapter )
97
97
assert r .url .lower () == url .lower ()
98
98
if method == 'head' :
99
99
assert r .text == ''
@@ -103,7 +103,7 @@ def test_unix_domain_adapter_alt_settings_1_ok():
103
103
104
104
def test_unix_domain_adapter_url_with_query_params ():
105
105
with UnixSocketServerThread () as usock_thread :
106
- session = requests_unixsocket . Session ('http+unix://' )
106
+ session = Session ('http+unix://' )
107
107
urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
108
108
url = ('http+unix://%s'
109
109
'/containers/nginx/logs?timestamp=true' % urlencoded_usock )
@@ -121,7 +121,7 @@ def test_unix_domain_adapter_url_with_query_params():
121
121
assert r .headers ['X-Requested-Path' ] == '/containers/nginx/logs'
122
122
assert r .headers ['X-Requested-Query-String' ] == 'timestamp=true'
123
123
assert r .headers ['X-Socket-Path' ] == usock_thread .usock
124
- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
124
+ assert isinstance (r .connection , UnixAdapter )
125
125
assert r .url .lower () == url .lower ()
126
126
if method == 'head' :
127
127
assert r .text == ''
@@ -131,7 +131,7 @@ def test_unix_domain_adapter_url_with_query_params():
131
131
132
132
def test_unix_domain_adapter_url_with_fragment ():
133
133
with UnixSocketServerThread () as usock_thread :
134
- session = requests_unixsocket . Session ('http+unix://' )
134
+ session = Session ('http+unix://' )
135
135
urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
136
136
url = ('http+unix://%s'
137
137
'/containers/nginx/logs#some-fragment' % urlencoded_usock )
@@ -148,7 +148,7 @@ def test_unix_domain_adapter_url_with_fragment():
148
148
assert r .headers ['X-Transport' ] == 'unix domain socket'
149
149
assert r .headers ['X-Requested-Path' ] == '/containers/nginx/logs'
150
150
assert r .headers ['X-Socket-Path' ] == usock_thread .usock
151
- assert isinstance (r .connection , requests_unixsocket . UnixAdapter )
151
+ assert isinstance (r .connection , UnixAdapter )
152
152
assert r .url .lower () == url .lower ()
153
153
if method == 'head' :
154
154
assert r .text == ''
@@ -157,7 +157,7 @@ def test_unix_domain_adapter_url_with_fragment():
157
157
158
158
159
159
def test_unix_domain_adapter_connection_error ():
160
- session = requests_unixsocket . Session ('http+unix://' )
160
+ session = Session ('http+unix://' )
161
161
162
162
for method in ['get' , 'post' , 'head' , 'patch' , 'put' , 'delete' , 'options' ]:
163
163
with pytest .raises (requests .ConnectionError ):
@@ -166,7 +166,7 @@ def test_unix_domain_adapter_connection_error():
166
166
167
167
168
168
def test_unix_domain_adapter_connection_proxies_error ():
169
- session = requests_unixsocket . Session ('http+unix://' )
169
+ session = Session ('http+unix://' )
170
170
171
171
for method in ['get' , 'post' , 'head' , 'patch' , 'put' , 'delete' , 'options' ]:
172
172
with pytest .raises (ValueError ) as excinfo :
@@ -179,7 +179,7 @@ def test_unix_domain_adapter_connection_proxies_error():
179
179
180
180
def test_unix_domain_adapter_monkeypatch ():
181
181
with UnixSocketServerThread () as usock_thread :
182
- with requests_unixsocket . monkeypatch ('http+unix://' ):
182
+ with monkeypatch ('http+unix://' ):
183
183
urlencoded_usock = requests .compat .quote_plus (usock_thread .usock )
184
184
url = 'http+unix://%s/path/to/page' % urlencoded_usock
185
185
@@ -196,7 +196,7 @@ def test_unix_domain_adapter_monkeypatch():
196
196
assert r .headers ['X-Requested-Path' ] == '/path/to/page'
197
197
assert r .headers ['X-Socket-Path' ] == usock_thread .usock
198
198
assert isinstance (r .connection ,
199
- requests_unixsocket . UnixAdapter )
199
+ UnixAdapter )
200
200
assert r .url .lower () == url .lower ()
201
201
if method == 'head' :
202
202
assert r .text == ''
0 commit comments