-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add itest_store.py to test file storage
- Loading branch information
1 parent
3d1452f
commit 2a0b789
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Never gonna give you up. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import pytest | ||
|
||
from aleph.sdk.client import AuthenticatedAlephHttpClient | ||
from aleph.sdk.query.filters import MessageFilter | ||
from tests.integration.toolkit import has_messages, try_until | ||
|
||
from .config import REFERENCE_NODE, TARGET_NODE | ||
|
||
|
||
async def create_store_on_target(account, emitter_node: str, receiver_node: str): | ||
""" | ||
Create a POST message on the target node, then fetch it from the reference node and download the file. | ||
""" | ||
with open("tests/integration/fixtures/testStore.txt", "rb") as f: | ||
file_content = f.read() | ||
async with AuthenticatedAlephHttpClient( | ||
account=account, api_server=emitter_node | ||
) as tx_session: | ||
store_message, message_status = await tx_session.create_store( | ||
file_content=file_content, | ||
extra_fields={"test": "test"}, | ||
) | ||
|
||
async with AuthenticatedAlephHttpClient( | ||
account=account, api_server=receiver_node | ||
) as rx_session: | ||
responses = await try_until( | ||
rx_session.get_messages, | ||
has_messages, | ||
timeout=5, | ||
message_filter=MessageFilter( | ||
hashes=[store_message.item_hash], | ||
), | ||
) | ||
|
||
message_from_target = responses.messages[0] | ||
assert store_message.item_hash == message_from_target.item_hash | ||
|
||
async with AuthenticatedAlephHttpClient( | ||
account=account, api_server=receiver_node | ||
) as rx_session: | ||
store_content = await rx_session.download_file(store_message.content.item_hash) | ||
assert store_content == file_content | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_message_on_target(fixture_account): | ||
""" | ||
Attempts to create a new message on the target node and verifies if the message can be fetched from | ||
the reference node. | ||
""" | ||
await create_store_on_target( | ||
fixture_account, emitter_node=TARGET_NODE, receiver_node=REFERENCE_NODE | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_message_on_reference(fixture_account): | ||
""" | ||
Attempts to create a new message on the reference node and verifies if the message can be fetched from | ||
the target node. | ||
""" | ||
await create_store_on_target( | ||
fixture_account, emitter_node=REFERENCE_NODE, receiver_node=TARGET_NODE | ||
) |