Skip to content

Commit 19a30a3

Browse files
committed
Refactor: Rename UserSession -> AlephClient
1 parent 47f1099 commit 19a30a3

File tree

12 files changed

+45
-48
lines changed

12 files changed

+45
-48
lines changed

examples/httpgateway.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from aleph.sdk.chains.common import get_fallback_private_key
99
from aleph.sdk.chains.ethereum import ETHAccount
10-
from aleph.sdk.user_session import AuthenticatedUserSession
10+
from aleph.sdk.client import AuthenticatedAlephClient
1111

1212
app = web.Application()
1313
routes = web.RouteTableDef()
@@ -32,7 +32,7 @@ async def source_post(request):
3232
return web.json_response(
3333
{"status": "error", "message": "unauthorized secret"}
3434
)
35-
async with AuthenticatedUserSession(
35+
async with AuthenticatedAlephClient(
3636
account=app["account"], api_server="https://api2.aleph.im"
3737
) as session:
3838
message, _status = await session.create_post(

examples/metrics.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111
from aleph_message.models import AlephMessage
1212

1313
from aleph.sdk.chains.ethereum import get_fallback_account
14+
from aleph.sdk.client import AuthenticatedAlephClient, AuthenticatedUserSessionSync
1415
from aleph.sdk.conf import settings
1516
from aleph.sdk.types import MessageStatus
16-
from aleph.sdk.user_session import (
17-
AuthenticatedUserSession,
18-
AuthenticatedUserSessionSync,
19-
)
2017

2118

2219
def get_sysinfo():
@@ -73,7 +70,7 @@ def collect_metrics():
7370

7471
def main():
7572
account = get_fallback_account()
76-
with AuthenticatedUserSession(
73+
with AuthenticatedAlephClient(
7774
account=account, api_server=settings.API_HOST
7875
) as session:
7976
while True:

examples/mqtt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from aleph.sdk.chains.common import get_fallback_private_key
1212
from aleph.sdk.chains.ethereum import ETHAccount
13+
from aleph.sdk.client import AuthenticatedAlephClient
1314
from aleph.sdk.conf import settings
14-
from aleph.sdk.user_session import AuthenticatedUserSession
1515

1616

1717
def get_input_data(value):
@@ -27,7 +27,7 @@ def get_input_data(value):
2727

2828

2929
def send_metrics(account, metrics):
30-
with AuthenticatedUserSession(
30+
with AuthenticatedAlephClient(
3131
account=account, api_server=settings.API_HOST
3232
) as session:
3333
return session.create_aggregate(
@@ -100,7 +100,7 @@ async def gateway(
100100
if not userdata["received"]:
101101
await client.reconnect()
102102

103-
async with AuthenticatedUserSession(
103+
async with AuthenticatedAlephClient(
104104
account=account, api_server=settings.API_HOST
105105
) as session:
106106
for key, value in state.items():

examples/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
from aleph.sdk.chains.common import get_fallback_private_key
77
from aleph.sdk.chains.ethereum import ETHAccount
8+
from aleph.sdk.client import AuthenticatedAlephClient
89
from aleph.sdk.conf import settings
910
from aleph.sdk.types import MessageStatus
10-
from aleph.sdk.user_session import AuthenticatedUserSession
1111

1212
DEFAULT_SERVER = "https://api2.aleph.im"
1313

@@ -23,7 +23,7 @@ async def print_output_hash(message: StoreMessage, status: MessageStatus):
2323

2424

2525
async def do_upload(account, engine, channel, filename=None, file_hash=None):
26-
async with AuthenticatedUserSession(
26+
async with AuthenticatedAlephClient(
2727
account=account, api_server=settings.API_HOST
2828
) as session:
2929
print(filename, account.get_address())

src/aleph/sdk/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pkg_resources import DistributionNotFound, get_distribution
22

3-
from aleph.sdk.user_session import AuthenticatedUserSession, UserSession
3+
from aleph.sdk.client import AlephClient, AuthenticatedAlephClient
44

55
try:
66
# Change here if project is renamed and does not equal the package name
@@ -11,4 +11,4 @@
1111
finally:
1212
del get_distribution, DistributionNotFound
1313

14-
__all__ = ["AuthenticatedUserSession", "UserSession"]
14+
__all__ = ["AlephClient", "AuthenticatedAlephClient"]

src/aleph/sdk/user_session.py renamed to src/aleph/sdk/client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def async_wrapper(f):
7171
Copies the docstring of wrapped functions.
7272
"""
7373

74-
wrapped = getattr(AuthenticatedUserSession, f.__name__)
74+
wrapped = getattr(AuthenticatedAlephClient, f.__name__)
7575
f.__doc__ = wrapped.__doc__
7676

7777

@@ -95,7 +95,7 @@ def func_caller(*args, **kwargs):
9595
async def run_async_watcher(
9696
*args, output_queue: queue.Queue, api_server: str, **kwargs
9797
):
98-
async with UserSession(api_server=api_server) as session:
98+
async with AlephClient(api_server=api_server) as session:
9999
async for message in session.watch_messages(*args, **kwargs):
100100
output_queue.put(message)
101101

@@ -122,7 +122,7 @@ class UserSessionSync:
122122
>>> return self._wrap(self.async_session.func)(*args, **kwargs)
123123
"""
124124

125-
def __init__(self, async_session: "UserSession"):
125+
def __init__(self, async_session: "AlephClient"):
126126
self.async_session = async_session
127127

128128
def _wrap(self, method: Callable[..., Awaitable[T]], *args, **kwargs):
@@ -272,9 +272,9 @@ def watch_messages(
272272

273273

274274
class AuthenticatedUserSessionSync(UserSessionSync):
275-
async_session: "AuthenticatedUserSession"
275+
async_session: "AuthenticatedAlephClient"
276276

277-
def __init__(self, async_session: "AuthenticatedUserSession"):
277+
def __init__(self, async_session: "AuthenticatedAlephClient"):
278278
super().__init__(async_session=async_session)
279279

280280
def ipfs_push(self, content: Mapping) -> str:
@@ -436,7 +436,7 @@ def submit(
436436
)
437437

438438

439-
class UserSession:
439+
class AlephClient:
440440
api_server: str
441441
http_session: aiohttp.ClientSession
442442

@@ -455,7 +455,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
455455
except RuntimeError:
456456
asyncio.run(close_fut)
457457

458-
async def __aenter__(self) -> "UserSession":
458+
async def __aenter__(self) -> "AlephClient":
459459
return self
460460

461461
async def __aexit__(self, exc_type, exc_val, exc_tb):
@@ -807,7 +807,7 @@ async def watch_messages(
807807
break
808808

809809

810-
class AuthenticatedUserSession(UserSession):
810+
class AuthenticatedAlephClient(AlephClient):
811811
account: Account
812812

813813
BROADCAST_MESSAGE_FIELDS = {
@@ -829,7 +829,7 @@ def __init__(self, account: Account, api_server: str):
829829
def __enter__(self) -> "AuthenticatedUserSessionSync":
830830
return AuthenticatedUserSessionSync(async_session=self)
831831

832-
async def __aenter__(self) -> "AuthenticatedUserSession":
832+
async def __aenter__(self) -> "AuthenticatedAlephClient":
833833
return self
834834

835835
async def ipfs_push(self, content: Mapping) -> str:

tests/integration/itest_aggregates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import pytest
55

6+
from aleph.sdk.client import AuthenticatedAlephClient
67
from aleph.sdk.types import Account
7-
from aleph.sdk.user_session import AuthenticatedUserSession
88
from tests.integration.toolkit import try_until
99

1010
from .config import REFERENCE_NODE, TARGET_NODE
@@ -18,7 +18,7 @@ async def create_aggregate_on_target(
1818
receiver_node: str,
1919
channel="INTEGRATION_TESTS",
2020
):
21-
async with AuthenticatedUserSession(
21+
async with AuthenticatedAlephClient(
2222
account=account, api_server=emitter_node
2323
) as tx_session:
2424
aggregate_message, message_status = await tx_session.create_aggregate(
@@ -38,7 +38,7 @@ async def create_aggregate_on_target(
3838
assert aggregate_message.content.address == account.get_address()
3939
assert aggregate_message.content.content == content
4040

41-
async with AuthenticatedUserSession(
41+
async with AuthenticatedAlephClient(
4242
account=account, api_server=receiver_node
4343
) as rx_session:
4444
aggregate_from_receiver = await try_until(

tests/integration/itest_forget.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import pytest
44

5+
from aleph.sdk.client import AuthenticatedAlephClient
56
from aleph.sdk.types import Account
6-
from aleph.sdk.user_session import AuthenticatedUserSession
77

88
from .config import REFERENCE_NODE, TARGET_NODE, TEST_CHANNEL
99
from .toolkit import try_until
@@ -17,7 +17,7 @@ async def wait_matching_posts(
1717
condition: Callable[[Dict], bool],
1818
timeout: int = 5,
1919
):
20-
async with AuthenticatedUserSession(
20+
async with AuthenticatedAlephClient(
2121
account=account, api_server=receiver_node
2222
) as rx_session:
2323
return await try_until(
@@ -27,7 +27,7 @@ async def wait_matching_posts(
2727
hashes=[item_hash],
2828
)
2929

30-
async with AuthenticatedUserSession(
30+
async with AuthenticatedAlephClient(
3131
account=account, api_server=emitter_node
3232
) as tx_session:
3333
post_message, message_status = await tx_session.create_post(
@@ -46,7 +46,7 @@ async def wait_matching_posts(
4646

4747
post_hash = post_message.item_hash
4848
reason = "This well thought-out content offends me!"
49-
async with AuthenticatedUserSession(
49+
async with AuthenticatedAlephClient(
5050
account=account, api_server=emitter_node
5151
) as tx_session:
5252
forget_message, forget_status = await tx_session.forget(
@@ -103,7 +103,7 @@ async def test_forget_a_forget_message(fixture_account):
103103

104104
# TODO: this test should be moved to the PyAleph API tests, once a framework is in place.
105105
post_hash = await create_and_forget_post(fixture_account, TARGET_NODE, TARGET_NODE)
106-
async with AuthenticatedUserSession(
106+
async with AuthenticatedAlephClient(
107107
account=fixture_account, api_server=TARGET_NODE
108108
) as session:
109109
get_post_response = await session.get_posts(hashes=[post_hash])

tests/integration/itest_posts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from aleph_message.models import MessagesResponse
33

4-
from aleph.sdk.user_session import AuthenticatedUserSession
4+
from aleph.sdk.client import AuthenticatedAlephClient
55
from tests.integration.toolkit import try_until
66

77
from .config import REFERENCE_NODE, TARGET_NODE
@@ -13,7 +13,7 @@ async def create_message_on_target(
1313
"""
1414
Create a POST message on the target node, then fetch it from the reference node.
1515
"""
16-
async with AuthenticatedUserSession(
16+
async with AuthenticatedAlephClient(
1717
account=fixture_account, api_server=emitter_node
1818
) as tx_session:
1919
post_message, message_status = await tx_session.create_post(
@@ -25,7 +25,7 @@ async def create_message_on_target(
2525
def response_contains_messages(response: MessagesResponse) -> bool:
2626
return len(response.messages) > 0
2727

28-
async with AuthenticatedUserSession(
28+
async with AuthenticatedAlephClient(
2929
account=fixture_account, api_server=receiver_node
3030
) as rx_session:
3131
responses = await try_until(

tests/unit/test_asynchronous.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
StoreMessage,
1111
)
1212

13+
from aleph.sdk.client import AuthenticatedAlephClient
1314
from aleph.sdk.types import Account, MessageStatus, StorageEnum
14-
from aleph.sdk.user_session import AuthenticatedUserSession
1515

1616

1717
@pytest.fixture
1818
def mock_session_with_post_success(
1919
ethereum_account: Account,
20-
) -> AuthenticatedUserSession:
20+
) -> AuthenticatedAlephClient:
2121
class MockResponse:
2222
def __init__(self, sync: bool):
2323
self.sync = sync
@@ -48,12 +48,12 @@ async def text(self):
4848
sync=kwargs.get("sync", False)
4949
)
5050

51-
user_session = AuthenticatedUserSession(
51+
client = AuthenticatedAlephClient(
5252
account=ethereum_account, api_server="http://localhost"
5353
)
54-
user_session.http_session = http_session
54+
client.http_session = http_session
5555

56-
return user_session
56+
return client
5757

5858

5959
@pytest.mark.asyncio

0 commit comments

Comments
 (0)