Skip to content

Commit 21c63ef

Browse files
MHHukiewitzhoh
authored andcommitted
fix integration tests
1 parent ca3fb37 commit 21c63ef

File tree

5 files changed

+52
-50
lines changed

5 files changed

+52
-50
lines changed

src/aleph/sdk/client.py

+2
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ async def fetch_aggregate(self, address: str, key: str) -> Dict[str, Dict]:
475475
async with self.http_session.get(
476476
f"/api/v0/aggregates/{address}.json", params=params
477477
) as resp:
478+
resp.raise_for_status()
478479
result = await resp.json()
479480
data = result.get("data", dict())
480481
return data.get(key)
@@ -491,6 +492,7 @@ async def fetch_aggregates(
491492
f"/api/v0/aggregates/{address}.json",
492493
params=params,
493494
) as resp:
495+
resp.raise_for_status()
494496
result = await resp.json()
495497
data = result.get("data", dict())
496498
return data

tests/integration/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
TARGET_NODE = "http://163.172.70.92:4024"
1+
TARGET_NODE = "https://api1.aleph.im"
22
REFERENCE_NODE = "https://api2.aleph.im"
33
TEST_CHANNEL = "INTEGRATION_TESTS"

tests/integration/itest_forget.py

+40-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Callable, Dict
2-
31
import pytest
42
from aleph_message.models import PostMessage
53

@@ -14,21 +12,6 @@
1412
async def create_and_forget_post(
1513
account: Account, emitter_node: str, receiver_node: str, channel=TEST_CHANNEL
1614
) -> str:
17-
async def wait_matching_posts(
18-
item_hash: str,
19-
condition: Callable[[Dict], bool],
20-
timeout: int = 5,
21-
):
22-
async with AuthenticatedAlephClient(
23-
account=account, api_server=receiver_node
24-
) as rx_session:
25-
return await try_until(
26-
rx_session.get_posts,
27-
condition,
28-
timeout=timeout,
29-
hashes=[item_hash],
30-
)
31-
3215
async with AuthenticatedAlephClient(
3316
account=account, api_server=emitter_node
3417
) as tx_session:
@@ -38,13 +21,17 @@ async def wait_matching_posts(
3821
channel="INTEGRATION_TESTS",
3922
)
4023

41-
# Wait for the message to appear on the receiver. We don't check the values,
42-
# they're checked in other integration tests.
43-
get_post_response = await wait_matching_posts(
44-
post_message.item_hash,
45-
lambda response: len(response["posts"]) > 0,
46-
)
47-
print(get_post_response)
24+
async with AuthenticatedAlephClient(
25+
account=account, api_server=receiver_node
26+
) as rx_session:
27+
await try_until(
28+
rx_session.get_messages,
29+
lambda response: len(response.messages) > 0,
30+
timeout=5,
31+
message_filter=MessageFilter(
32+
hashes=[post_message.item_hash],
33+
),
34+
)
4835

4936
post_hash = post_message.item_hash
5037
reason = "This well thought-out content offends me!"
@@ -56,24 +43,40 @@ async def wait_matching_posts(
5643
reason=reason,
5744
channel=channel,
5845
)
59-
6046
assert forget_message.sender == account.get_address()
6147
assert forget_message.content.reason == reason
6248
assert forget_message.content.hashes == [post_hash]
6349

64-
print(forget_message)
65-
6650
# Wait until the message is forgotten
67-
forgotten_posts = await wait_matching_posts(
68-
post_hash,
69-
lambda response: "forgotten_by" in response["posts"][0],
70-
timeout=15,
71-
)
72-
73-
assert len(forgotten_posts["posts"]) == 1
74-
forgotten_post = forgotten_posts["posts"][0]
75-
assert forgotten_post["forgotten_by"] == [forget_message.item_hash]
76-
assert forgotten_post["item_content"] is None
51+
async with AuthenticatedAlephClient(
52+
account=account, api_server=receiver_node
53+
) as rx_session:
54+
await try_until(
55+
rx_session.get_messages,
56+
lambda response: len(response.messages) > 0,
57+
timeout=5,
58+
message_filter=MessageFilter(
59+
hashes=[forget_message.item_hash],
60+
),
61+
)
62+
63+
async with AuthenticatedAlephClient(
64+
account=account, api_server=receiver_node
65+
) as rx_session:
66+
forgotten_messages = await try_until(
67+
rx_session.get_messages,
68+
lambda response: len(response.messages) == 0,
69+
timeout=5,
70+
message_filter=MessageFilter(
71+
hashes=[post_hash],
72+
),
73+
)
74+
# TODO: Should we now receive any messages? It seems they are completely gone
75+
76+
assert len(forgotten_messages.messages) == 1
77+
forgotten_post = forgotten_messages.messages[0]
78+
assert forgotten_post.forgotten_by == [forget_message.item_hash]
79+
assert forgotten_post.item_content is None
7780
print(forgotten_post)
7881

7982
return post_hash

tests/integration/itest_posts.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
11
import pytest
2-
from aleph_message.models import MessagesResponse
32

43
from aleph.sdk.client import AuthenticatedAlephClient
4+
from aleph.sdk.models.message import MessageFilter
55
from tests.integration.toolkit import try_until
66

77
from .config import REFERENCE_NODE, TARGET_NODE
88

99

10-
async def create_message_on_target(
11-
fixture_account, emitter_node: str, receiver_node: str
12-
):
10+
async def create_message_on_target(account, emitter_node: str, receiver_node: str):
1311
"""
1412
Create a POST message on the target node, then fetch it from the reference node.
1513
"""
1614
async with AuthenticatedAlephClient(
17-
account=fixture_account, api_server=emitter_node
15+
account=account, api_server=emitter_node
1816
) as tx_session:
1917
post_message, message_status = await tx_session.create_post(
2018
post_content=None,
2119
post_type="POST",
2220
channel="INTEGRATION_TESTS",
2321
)
2422

25-
def response_contains_messages(response: MessagesResponse) -> bool:
26-
return len(response.messages) > 0
27-
2823
async with AuthenticatedAlephClient(
29-
account=fixture_account, api_server=receiver_node
24+
account=account, api_server=receiver_node
3025
) as rx_session:
3126
responses = await try_until(
3227
rx_session.get_messages,
33-
response_contains_messages,
28+
lambda response: len(response.messages) > 0,
3429
timeout=5,
35-
hashes=[post_message.item_hash],
30+
message_filter=MessageFilter(
31+
hashes=[post_message.item_hash],
32+
),
3633
)
3734

3835
message_from_target = responses.messages[0]

tests/integration/toolkit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async def try_until(
99
coroutine: Callable[..., Awaitable[T]],
1010
condition: Callable[[T], bool],
1111
timeout: float,
12-
time_between_attempts: float = 0.5,
12+
time_between_attempts: float = 1,
1313
*args,
1414
**kwargs,
1515
) -> T:

0 commit comments

Comments
 (0)