hexway-hive-api 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/PKG-INFO +5 -2
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/README.md +4 -1
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/clients/async_rest_client.py +34 -9
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/http_client/async_http_client.py +24 -4
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api.egg-info/PKG-INFO +5 -2
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/pyproject.toml +1 -1
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/tests/test_async_http_client.py +23 -0
- hexway_hive_api-0.2.4/tests/test_async_rest_client.py +245 -0
- hexway_hive_api-0.2.2/tests/test_async_rest_client.py +0 -111
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/LICENSE +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/__init__.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/clients/__init__.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/clients/rest_client.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/__init__.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/enums.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/error_handler.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/exceptions.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/http_client/__init__.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/http_client/exceptions.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/http_client/http_client.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/models/__init__.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/models/issue.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/models/project.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api.egg-info/SOURCES.txt +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api.egg-info/dependency_links.txt +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api.egg-info/requires.txt +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api.egg-info/top_level.txt +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/setup.cfg +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/tests/test_issue.py +0 -0
- {hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/tests/test_project.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hexway-hive-api
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Small wrapper for HexWay Hive API
|
|
5
5
|
Author-email: "@Cur1iosity" <Cur1iosity@protonmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/Cur1iosity/hexway-hive-api
|
|
@@ -82,4 +82,7 @@ asyncio.run(main())
|
|
|
82
82
|
|
|
83
83
|
``AsyncHTTPClient`` accepts an optional ``ssl`` context in its constructor or
|
|
84
84
|
through :meth:`update_params`. This context will be passed to all requests if no
|
|
85
|
-
``ssl`` argument is provided explicitly.
|
|
85
|
+
``ssl`` argument is provided explicitly. Verification of server certificates can
|
|
86
|
+
be toggled via the ``verify_ssl`` flag or ``verify`` parameter in
|
|
87
|
+
:meth:`update_params` and individual request methods. Disabling verification will
|
|
88
|
+
still keep TLS encryption enabled.
|
|
@@ -63,4 +63,7 @@ asyncio.run(main())
|
|
|
63
63
|
|
|
64
64
|
``AsyncHTTPClient`` accepts an optional ``ssl`` context in its constructor or
|
|
65
65
|
through :meth:`update_params`. This context will be passed to all requests if no
|
|
66
|
-
``ssl`` argument is provided explicitly.
|
|
66
|
+
``ssl`` argument is provided explicitly. Verification of server certificates can
|
|
67
|
+
be toggled via the ``verify_ssl`` flag or ``verify`` parameter in
|
|
68
|
+
:meth:`update_params` and individual request methods. Disabling verification will
|
|
69
|
+
still keep TLS encryption enabled.
|
{hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/clients/async_rest_client.py
RENAMED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
import ssl
|
|
5
|
+
|
|
6
|
+
import aiohttp
|
|
5
7
|
from contextlib import asynccontextmanager
|
|
6
8
|
from typing import Optional, MutableMapping, Union, Self, AsyncGenerator
|
|
7
9
|
from uuid import UUID
|
|
@@ -90,6 +92,13 @@ class AsyncRestClient:
|
|
|
90
92
|
context = self._make_ssl_context(cert)
|
|
91
93
|
self.http_client.update_params(ssl=context)
|
|
92
94
|
|
|
95
|
+
if self.http_client.session.closed:
|
|
96
|
+
proxies = self.http_client.proxies
|
|
97
|
+
ssl_context = self.http_client.ssl
|
|
98
|
+
await self.http_client.close()
|
|
99
|
+
self.http_client = AsyncHTTPClient(ssl=ssl_context)
|
|
100
|
+
self.http_client.proxies = proxies
|
|
101
|
+
|
|
93
102
|
self.server = server or self.server
|
|
94
103
|
self.api_url = api_url or self.api_url or self.make_api_url_from(self.server)
|
|
95
104
|
|
|
@@ -99,10 +108,18 @@ class AsyncRestClient:
|
|
|
99
108
|
if '@' not in username:
|
|
100
109
|
username = f'{username}@ro.ot'
|
|
101
110
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
111
|
+
try:
|
|
112
|
+
response = await self.http_client.session.post(
|
|
113
|
+
f"{self.api_url}/session",
|
|
114
|
+
json={
|
|
115
|
+
'userLogin': username,
|
|
116
|
+
'userPassword': password,
|
|
117
|
+
},
|
|
118
|
+
ssl=self.http_client.ssl,
|
|
119
|
+
)
|
|
120
|
+
except aiohttp.ClientError as e:
|
|
121
|
+
await self.http_client.close()
|
|
122
|
+
raise exceptions.RestConnectionError(f'Failed to connect: {e}') from e
|
|
106
123
|
|
|
107
124
|
cookie = response.cookies.get('BSESSIONID')
|
|
108
125
|
if not cookie:
|
|
@@ -113,11 +130,19 @@ class AsyncRestClient:
|
|
|
113
130
|
|
|
114
131
|
async def disconnect(self) -> bool:
|
|
115
132
|
"""Close connection and clean up client session."""
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
133
|
+
try:
|
|
134
|
+
await self.http_client.session.delete(f"{self.api_url}/session")
|
|
135
|
+
except aiohttp.ClientError:
|
|
136
|
+
# connection may already be closed by the server
|
|
137
|
+
pass
|
|
138
|
+
finally:
|
|
139
|
+
self.state = ClientState.DISCONNECTED
|
|
140
|
+
await self.http_client.clear_session()
|
|
141
|
+
proxies = self.http_client.proxies
|
|
142
|
+
ssl_context = self.http_client.ssl
|
|
143
|
+
await self.http_client.close()
|
|
144
|
+
self.http_client.proxies = proxies
|
|
145
|
+
self.http_client.ssl = ssl_context
|
|
121
146
|
return True
|
|
122
147
|
|
|
123
148
|
@asynccontextmanager
|
|
@@ -18,18 +18,21 @@ SUCCESSFUL_STATUS_CODES = [status for status in HTTPStatus if 200 <= status < 30
|
|
|
18
18
|
|
|
19
19
|
class AsyncHTTPClient:
|
|
20
20
|
"""Asynchronous implementation of the HTTP client."""
|
|
21
|
-
def __init__(self, *, ssl: Optional[ssl.SSLContext] = None) -> None:
|
|
21
|
+
def __init__(self, *, ssl: Optional[ssl.SSLContext] = None, verify_ssl: bool = True) -> None:
|
|
22
22
|
"""Create ``aiohttp`` session used for all requests.
|
|
23
23
|
|
|
24
24
|
Parameters
|
|
25
25
|
----------
|
|
26
26
|
ssl : :class:`ssl.SSLContext` | None
|
|
27
27
|
Default SSL context applied to all requests.
|
|
28
|
+
verify_ssl : bool, optional
|
|
29
|
+
Flag controlling TLS certificate verification. ``True`` by default.
|
|
28
30
|
"""
|
|
29
31
|
|
|
30
32
|
self.session: aiohttp.ClientSession = aiohttp.ClientSession()
|
|
31
33
|
self._proxies: MutableMapping[str, str] = {}
|
|
32
34
|
self.ssl = ssl
|
|
35
|
+
self.verify_ssl = verify_ssl
|
|
33
36
|
|
|
34
37
|
async def _send(self, method: HTTPMethod, url: str, **kwargs) -> Union[dict, bytes, list]:
|
|
35
38
|
"""Internal helper performing HTTP request and parsing the response.
|
|
@@ -40,7 +43,20 @@ class AsyncHTTPClient:
|
|
|
40
43
|
proxy = self._proxies.get('https' if url.startswith('https') else 'http')
|
|
41
44
|
if proxy:
|
|
42
45
|
kwargs.setdefault('proxy', proxy)
|
|
43
|
-
|
|
46
|
+
|
|
47
|
+
verify = kwargs.pop("verify", kwargs.pop("verify_ssl", self.verify_ssl))
|
|
48
|
+
|
|
49
|
+
if not verify:
|
|
50
|
+
base_context = kwargs.get("ssl") or self.ssl
|
|
51
|
+
if base_context is not None:
|
|
52
|
+
context = ssl.SSLContext(base_context.protocol)
|
|
53
|
+
else:
|
|
54
|
+
context = ssl.create_default_context()
|
|
55
|
+
context.check_hostname = False
|
|
56
|
+
context.verify_mode = ssl.CERT_NONE
|
|
57
|
+
kwargs.setdefault("ssl", context)
|
|
58
|
+
else:
|
|
59
|
+
kwargs.setdefault("ssl", self.ssl)
|
|
44
60
|
try:
|
|
45
61
|
async with self.session.request(method, url, **kwargs) as response:
|
|
46
62
|
if response.status not in SUCCESSFUL_STATUS_CODES:
|
|
@@ -111,8 +127,12 @@ class AsyncHTTPClient:
|
|
|
111
127
|
|
|
112
128
|
def update_params(self, **kwargs) -> Self:
|
|
113
129
|
"""Update session parameters and store ``ssl`` for later use."""
|
|
114
|
-
if
|
|
115
|
-
self.ssl = kwargs[
|
|
130
|
+
if "ssl" in kwargs:
|
|
131
|
+
self.ssl = kwargs["ssl"]
|
|
132
|
+
if "verify" in kwargs or "verify_ssl" in kwargs:
|
|
133
|
+
self.verify_ssl = bool(kwargs.get("verify", kwargs.get("verify_ssl")))
|
|
134
|
+
kwargs.pop("verify", None)
|
|
135
|
+
kwargs.pop("verify_ssl", None)
|
|
116
136
|
self._update_params(**kwargs)
|
|
117
137
|
return self
|
|
118
138
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hexway-hive-api
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Small wrapper for HexWay Hive API
|
|
5
5
|
Author-email: "@Cur1iosity" <Cur1iosity@protonmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/Cur1iosity/hexway-hive-api
|
|
@@ -82,4 +82,7 @@ asyncio.run(main())
|
|
|
82
82
|
|
|
83
83
|
``AsyncHTTPClient`` accepts an optional ``ssl`` context in its constructor or
|
|
84
84
|
through :meth:`update_params`. This context will be passed to all requests if no
|
|
85
|
-
``ssl`` argument is provided explicitly.
|
|
85
|
+
``ssl`` argument is provided explicitly. Verification of server certificates can
|
|
86
|
+
be toggled via the ``verify_ssl`` flag or ``verify`` parameter in
|
|
87
|
+
:meth:`update_params` and individual request methods. Disabling verification will
|
|
88
|
+
still keep TLS encryption enabled.
|
|
@@ -60,3 +60,26 @@ def test_send_uses_default_ssl():
|
|
|
60
60
|
await client.close()
|
|
61
61
|
|
|
62
62
|
asyncio.run(run())
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_update_params_sets_verify_ssl():
|
|
66
|
+
async def run() -> None:
|
|
67
|
+
client = AsyncHTTPClient()
|
|
68
|
+
client.update_params(verify=False)
|
|
69
|
+
assert client.verify_ssl is False
|
|
70
|
+
await client.close()
|
|
71
|
+
|
|
72
|
+
asyncio.run(run())
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_send_respects_verify_flag():
|
|
76
|
+
async def run() -> None:
|
|
77
|
+
client = AsyncHTTPClient()
|
|
78
|
+
client.session = DummySession()
|
|
79
|
+
await client.get("https://example.com", verify=False)
|
|
80
|
+
context = client.session.kwargs.get("ssl")
|
|
81
|
+
assert isinstance(context, ssl.SSLContext)
|
|
82
|
+
assert context.verify_mode == ssl.CERT_NONE
|
|
83
|
+
await client.close()
|
|
84
|
+
|
|
85
|
+
asyncio.run(run())
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
from hexway_hive_api.clients.async_rest_client import AsyncRestClient
|
|
2
|
+
from hexway_hive_api.rest import exceptions
|
|
3
|
+
import aiohttp
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_make_api_url_from() -> None:
|
|
8
|
+
"""Ensure API URL is built correctly from server string."""
|
|
9
|
+
url = AsyncRestClient.make_api_url_from('https://hive.local')
|
|
10
|
+
assert url == 'https://hive.local:443/api'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_proxies_property() -> None:
|
|
14
|
+
"""Proxy configuration should be stored inside HTTP client."""
|
|
15
|
+
async def run() -> None:
|
|
16
|
+
client = AsyncRestClient()
|
|
17
|
+
client.proxies = {"http": "http://proxy"}
|
|
18
|
+
assert client.proxies.get("http") == "http://proxy"
|
|
19
|
+
await client.http_client.clear_session()
|
|
20
|
+
|
|
21
|
+
import asyncio
|
|
22
|
+
asyncio.run(run())
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_connect_handles_aiohttp_error() -> None:
|
|
26
|
+
"""Client should close session and raise ``RestConnectionError`` on aiohttp failure."""
|
|
27
|
+
|
|
28
|
+
class DummySession:
|
|
29
|
+
def __init__(self) -> None:
|
|
30
|
+
self.headers = {}
|
|
31
|
+
self.closed = False
|
|
32
|
+
|
|
33
|
+
async def post(self, *args, **kwargs):
|
|
34
|
+
raise aiohttp.ClientConnectionError("boom")
|
|
35
|
+
|
|
36
|
+
async def close(self):
|
|
37
|
+
self.closed = True
|
|
38
|
+
|
|
39
|
+
async def run() -> None:
|
|
40
|
+
client = AsyncRestClient()
|
|
41
|
+
old_session = client.http_client.session
|
|
42
|
+
dummy = DummySession()
|
|
43
|
+
client.http_client.session = dummy
|
|
44
|
+
await old_session.close()
|
|
45
|
+
|
|
46
|
+
with pytest.raises(exceptions.RestConnectionError):
|
|
47
|
+
await client.connect(server="http://test", api_url="http://test/api", username="u", password="p")
|
|
48
|
+
|
|
49
|
+
assert dummy.closed is True
|
|
50
|
+
|
|
51
|
+
import asyncio
|
|
52
|
+
asyncio.run(run())
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_disconnect_closes_session() -> None:
|
|
56
|
+
"""Client session should be closed after disconnect."""
|
|
57
|
+
|
|
58
|
+
class DummyResponse:
|
|
59
|
+
def __init__(self) -> None:
|
|
60
|
+
self.cookies = {"BSESSIONID": "cookie"}
|
|
61
|
+
|
|
62
|
+
async def json(self):
|
|
63
|
+
return {}
|
|
64
|
+
|
|
65
|
+
class DummySession:
|
|
66
|
+
def __init__(self) -> None:
|
|
67
|
+
self.headers = {}
|
|
68
|
+
self.closed = False
|
|
69
|
+
|
|
70
|
+
async def post(self, *args, **kwargs):
|
|
71
|
+
if self.closed:
|
|
72
|
+
raise RuntimeError("Session is closed")
|
|
73
|
+
return DummyResponse()
|
|
74
|
+
|
|
75
|
+
async def delete(self, *args, **kwargs):
|
|
76
|
+
if self.closed:
|
|
77
|
+
raise RuntimeError("Session is closed")
|
|
78
|
+
return DummyResponse()
|
|
79
|
+
|
|
80
|
+
async def close(self):
|
|
81
|
+
self.closed = True
|
|
82
|
+
|
|
83
|
+
async def run() -> None:
|
|
84
|
+
client = AsyncRestClient()
|
|
85
|
+
old_session = client.http_client.session
|
|
86
|
+
dummy = DummySession()
|
|
87
|
+
client.http_client.session = dummy
|
|
88
|
+
await old_session.close()
|
|
89
|
+
|
|
90
|
+
await client.connect(server="http://test", api_url="http://test/api", username="u", password="p")
|
|
91
|
+
await client.disconnect()
|
|
92
|
+
|
|
93
|
+
assert dummy.closed is True
|
|
94
|
+
assert client.http_client.session is dummy
|
|
95
|
+
assert client.http_client.session.closed is True
|
|
96
|
+
|
|
97
|
+
import asyncio
|
|
98
|
+
asyncio.run(run())
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_disconnect_handles_server_error() -> None:
|
|
102
|
+
"""Disconnect should recreate session even if server is already disconnected."""
|
|
103
|
+
|
|
104
|
+
class DummyResponse:
|
|
105
|
+
def __init__(self) -> None:
|
|
106
|
+
self.cookies = {"BSESSIONID": "cookie"}
|
|
107
|
+
|
|
108
|
+
async def json(self):
|
|
109
|
+
return {}
|
|
110
|
+
|
|
111
|
+
class DummySession:
|
|
112
|
+
def __init__(self) -> None:
|
|
113
|
+
self.headers = {}
|
|
114
|
+
self.closed = False
|
|
115
|
+
|
|
116
|
+
async def post(self, *args, **kwargs):
|
|
117
|
+
if self.closed:
|
|
118
|
+
raise RuntimeError("Session is closed")
|
|
119
|
+
return DummyResponse()
|
|
120
|
+
|
|
121
|
+
async def delete(self, *args, **kwargs):
|
|
122
|
+
raise aiohttp.ServerDisconnectedError()
|
|
123
|
+
|
|
124
|
+
async def close(self):
|
|
125
|
+
self.closed = True
|
|
126
|
+
|
|
127
|
+
async def run() -> None:
|
|
128
|
+
client = AsyncRestClient()
|
|
129
|
+
old_session = client.http_client.session
|
|
130
|
+
dummy = DummySession()
|
|
131
|
+
client.http_client.session = dummy
|
|
132
|
+
await old_session.close()
|
|
133
|
+
|
|
134
|
+
await client.connect(server="http://test", api_url="http://test/api", username="u", password="p")
|
|
135
|
+
await client.disconnect()
|
|
136
|
+
|
|
137
|
+
assert dummy.closed is True
|
|
138
|
+
assert client.http_client.session is dummy
|
|
139
|
+
assert client.http_client.session.closed is True
|
|
140
|
+
|
|
141
|
+
import asyncio
|
|
142
|
+
asyncio.run(run())
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_connect_after_disconnect() -> None:
|
|
146
|
+
"""Client should be able to reconnect after disconnect."""
|
|
147
|
+
|
|
148
|
+
class DummyResponse:
|
|
149
|
+
def __init__(self) -> None:
|
|
150
|
+
self.cookies = {"BSESSIONID": "cookie"}
|
|
151
|
+
|
|
152
|
+
async def json(self):
|
|
153
|
+
return {}
|
|
154
|
+
|
|
155
|
+
class DummySession:
|
|
156
|
+
def __init__(self) -> None:
|
|
157
|
+
self.headers = {}
|
|
158
|
+
self.closed = False
|
|
159
|
+
|
|
160
|
+
async def post(self, *args, **kwargs):
|
|
161
|
+
if self.closed:
|
|
162
|
+
raise RuntimeError("Session is closed")
|
|
163
|
+
return DummyResponse()
|
|
164
|
+
|
|
165
|
+
async def delete(self, *args, **kwargs):
|
|
166
|
+
if self.closed:
|
|
167
|
+
raise RuntimeError("Session is closed")
|
|
168
|
+
return DummyResponse()
|
|
169
|
+
|
|
170
|
+
async def close(self):
|
|
171
|
+
self.closed = True
|
|
172
|
+
|
|
173
|
+
async def run() -> None:
|
|
174
|
+
client = AsyncRestClient()
|
|
175
|
+
old_session = client.http_client.session
|
|
176
|
+
dummy1 = DummySession()
|
|
177
|
+
client.http_client.session = dummy1
|
|
178
|
+
await old_session.close()
|
|
179
|
+
|
|
180
|
+
await client.connect(server="http://test", api_url="http://test/api", username="u", password="p")
|
|
181
|
+
await client.disconnect()
|
|
182
|
+
|
|
183
|
+
assert dummy1.closed is True
|
|
184
|
+
assert client.http_client.session is dummy1
|
|
185
|
+
assert client.http_client.session.closed is True
|
|
186
|
+
|
|
187
|
+
dummy2 = DummySession()
|
|
188
|
+
client.http_client.session = dummy2
|
|
189
|
+
|
|
190
|
+
await client.connect(server="http://test", api_url="http://test/api", username="u", password="p")
|
|
191
|
+
|
|
192
|
+
assert dummy2.closed is False
|
|
193
|
+
assert client.http_client.session.headers.get("Cookie") == "BSESSIONID=cookie"
|
|
194
|
+
await client.http_client.session.close()
|
|
195
|
+
|
|
196
|
+
import asyncio
|
|
197
|
+
asyncio.run(run())
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def test_connect_uses_ssl_context(monkeypatch) -> None:
|
|
201
|
+
"""SSL context from ``cert`` parameter should be passed to requests."""
|
|
202
|
+
import ssl
|
|
203
|
+
|
|
204
|
+
async def run() -> None:
|
|
205
|
+
# avoid loading real certificate
|
|
206
|
+
monkeypatch.setattr(
|
|
207
|
+
AsyncRestClient,
|
|
208
|
+
"_make_ssl_context",
|
|
209
|
+
staticmethod(lambda cert: ssl.create_default_context()),
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
class DummyResponse:
|
|
213
|
+
def __init__(self) -> None:
|
|
214
|
+
self.cookies = {"BSESSIONID": "cookie"}
|
|
215
|
+
|
|
216
|
+
class DummySession:
|
|
217
|
+
def __init__(self) -> None:
|
|
218
|
+
self.headers = {}
|
|
219
|
+
self.captured = None
|
|
220
|
+
self.closed = False
|
|
221
|
+
|
|
222
|
+
async def post(self, *args, **kwargs):
|
|
223
|
+
self.captured = kwargs.get("ssl")
|
|
224
|
+
return DummyResponse()
|
|
225
|
+
|
|
226
|
+
async def close(self):
|
|
227
|
+
self.closed = True
|
|
228
|
+
|
|
229
|
+
client = AsyncRestClient(cert="path/to/cert.pem")
|
|
230
|
+
old_session = client.http_client.session
|
|
231
|
+
client.http_client.session = DummySession()
|
|
232
|
+
await old_session.close()
|
|
233
|
+
|
|
234
|
+
await client.connect(
|
|
235
|
+
server="https://hive.local",
|
|
236
|
+
api_url="https://hive.local/api",
|
|
237
|
+
username="u",
|
|
238
|
+
password="p",
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
assert isinstance(client.http_client.session.captured, ssl.SSLContext)
|
|
242
|
+
await client.http_client.session.close()
|
|
243
|
+
|
|
244
|
+
import asyncio
|
|
245
|
+
asyncio.run(run())
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
from hexway_hive_api.clients.async_rest_client import AsyncRestClient
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def test_make_api_url_from() -> None:
|
|
5
|
-
"""Ensure API URL is built correctly from server string."""
|
|
6
|
-
url = AsyncRestClient.make_api_url_from('https://hive.local')
|
|
7
|
-
assert url == 'https://hive.local:443/api'
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def test_proxies_property() -> None:
|
|
11
|
-
"""Proxy configuration should be stored inside HTTP client."""
|
|
12
|
-
async def run() -> None:
|
|
13
|
-
client = AsyncRestClient()
|
|
14
|
-
client.proxies = {"http": "http://proxy"}
|
|
15
|
-
assert client.proxies.get("http") == "http://proxy"
|
|
16
|
-
await client.http_client.clear_session()
|
|
17
|
-
|
|
18
|
-
import asyncio
|
|
19
|
-
asyncio.run(run())
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def test_disconnect_closes_session() -> None:
|
|
23
|
-
"""Client session should be closed after disconnect."""
|
|
24
|
-
|
|
25
|
-
class DummyResponse:
|
|
26
|
-
def __init__(self) -> None:
|
|
27
|
-
self.cookies = {"BSESSIONID": "cookie"}
|
|
28
|
-
|
|
29
|
-
async def json(self):
|
|
30
|
-
return {}
|
|
31
|
-
|
|
32
|
-
class DummySession:
|
|
33
|
-
def __init__(self) -> None:
|
|
34
|
-
self.headers = {}
|
|
35
|
-
self.closed = False
|
|
36
|
-
|
|
37
|
-
async def post(self, *args, **kwargs):
|
|
38
|
-
return DummyResponse()
|
|
39
|
-
|
|
40
|
-
async def delete(self, *args, **kwargs):
|
|
41
|
-
return DummyResponse()
|
|
42
|
-
|
|
43
|
-
async def close(self):
|
|
44
|
-
self.closed = True
|
|
45
|
-
|
|
46
|
-
async def run() -> None:
|
|
47
|
-
client = AsyncRestClient()
|
|
48
|
-
old_session = client.http_client.session
|
|
49
|
-
client.http_client.session = DummySession()
|
|
50
|
-
await old_session.close()
|
|
51
|
-
|
|
52
|
-
await client.connect(server="http://test", api_url="http://test/api", username="u", password="p")
|
|
53
|
-
await client.disconnect()
|
|
54
|
-
|
|
55
|
-
assert client.http_client.session.closed is True
|
|
56
|
-
|
|
57
|
-
import asyncio
|
|
58
|
-
asyncio.run(run())
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def test_connect_uses_ssl_context(monkeypatch) -> None:
|
|
62
|
-
"""SSL context from ``cert`` parameter should be passed to requests."""
|
|
63
|
-
import ssl
|
|
64
|
-
async def run() -> None:
|
|
65
|
-
captured = None
|
|
66
|
-
|
|
67
|
-
# avoid loading real certificate
|
|
68
|
-
monkeypatch.setattr(
|
|
69
|
-
AsyncRestClient,
|
|
70
|
-
"_make_ssl_context",
|
|
71
|
-
staticmethod(lambda cert: ssl.create_default_context()),
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
client = AsyncRestClient(cert="path/to/cert.pem")
|
|
75
|
-
|
|
76
|
-
async def dummy_request(self, method, url, **kwargs):
|
|
77
|
-
nonlocal captured
|
|
78
|
-
captured = kwargs.get("ssl")
|
|
79
|
-
class DummyResponse:
|
|
80
|
-
def __init__(self) -> None:
|
|
81
|
-
self.cookies = {"BSESSIONID": "cookie"}
|
|
82
|
-
|
|
83
|
-
async def json(self):
|
|
84
|
-
return {}
|
|
85
|
-
|
|
86
|
-
return DummyResponse()
|
|
87
|
-
|
|
88
|
-
from types import MethodType
|
|
89
|
-
|
|
90
|
-
monkeypatch.setattr(
|
|
91
|
-
client.http_client.session,
|
|
92
|
-
"request",
|
|
93
|
-
MethodType(dummy_request, client.http_client.session),
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
async def dummy_post(self, url, **kwargs):
|
|
97
|
-
return await self.request("POST", url, ssl=client.http_client.ssl, **kwargs)
|
|
98
|
-
|
|
99
|
-
monkeypatch.setattr(
|
|
100
|
-
client.http_client.session,
|
|
101
|
-
"post",
|
|
102
|
-
MethodType(dummy_post, client.http_client.session),
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
await client.connect(server="https://hive.local", api_url="https://hive.local/api", username="u", password="p")
|
|
106
|
-
|
|
107
|
-
assert isinstance(captured, ssl.SSLContext)
|
|
108
|
-
await client.http_client.session.close()
|
|
109
|
-
|
|
110
|
-
import asyncio
|
|
111
|
-
asyncio.run(run())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/http_client/__init__.py
RENAMED
|
File without changes
|
{hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/http_client/exceptions.py
RENAMED
|
File without changes
|
{hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/http_client/http_client.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hexway_hive_api-0.2.2 → hexway_hive_api-0.2.4}/hexway_hive_api.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|