Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add itest_store.py to test file storage #106

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/integration/fixtures/testStore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Never gonna give you up.
65 changes: 65 additions & 0 deletions tests/integration/itest_store.py
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
)
Loading