Skip to content

Commit 10afbd3

Browse files
committed
fix testing problem; reformat
1 parent 6bf3144 commit 10afbd3

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

src/aleph/sdk/models.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class Post(BaseModel):
3737
)
3838
address: str = Field(description="The address of the sender of the POST message")
3939
ref: Optional[str] = Field(description="Other message referenced by this one")
40-
channel: Optional[str] = Field(description="The channel where the POST message was published")
40+
channel: Optional[str] = Field(
41+
description="The channel where the POST message was published"
42+
)
4143
created: datetime = Field(description="The time when the POST message was created")
4244
last_updated: datetime = Field(
4345
description="The time when the POST message was last updated"

src/aleph/sdk/node/post.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def message_to_post(message: PostMessage) -> Post:
5858
"ref": message.content.ref if hasattr(message.content, "ref") else None,
5959
"channel": message.channel,
6060
"created": datetime.fromtimestamp(message.time),
61-
"last_updated": datetime.fromtimestamp(message.time)
61+
"last_updated": datetime.fromtimestamp(message.time),
6262
}
6363
)
6464

tests/unit/conftest.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ def messages() -> List[AlephMessage]:
113113

114114
@pytest.fixture
115115
def raw_messages_response(messages):
116-
return {
117-
"messages": [message.dict() for message in messages],
116+
return lambda page: {
117+
"messages": [message.dict() for message in messages] if page == 1 else [],
118118
"pagination_item": "messages",
119-
"pagination_page": 1,
120-
"pagination_per_page": 20,
121-
"pagination_total": 2,
119+
"pagination_page": page,
120+
"pagination_per_page": max(len(messages), 20),
121+
"pagination_total": len(messages) if page == 1 else 0,
122122
}

tests/unit/test_node.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ async def text(self):
5454

5555

5656
class MockGetResponse:
57-
def __init__(self, response):
58-
self.response = response
57+
def __init__(self, response_message, page=1):
58+
self.response_message = response_message
59+
self.page = page
5960

6061
async def __aenter__(self):
6162
return self
@@ -72,7 +73,7 @@ def raise_for_status(self):
7273
raise Exception("Bad status code")
7374

7475
async def json(self):
75-
return self.response
76+
return self.response_message(self.page)
7677

7778

7879
@pytest.fixture
@@ -92,7 +93,10 @@ def mock_session_with_two_messages(
9293
sync=kwargs.get("sync", False),
9394
)
9495
http_session.get = MagicMock()
95-
http_session.get.return_value = MockGetResponse(raw_messages_response)
96+
http_session.get.side_effect = lambda *args, **kwargs: MockGetResponse(
97+
response_message=raw_messages_response,
98+
page=kwargs.get("params", {}).get("page", 1),
99+
)
96100

97101
client = AuthenticatedAlephClient(
98102
account=ethereum_account, api_server="http://localhost"

tests/unit/test_node_get.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
from aleph.sdk.chains.ethereum import get_fallback_account
1515
from aleph.sdk.exceptions import MessageNotFoundError
16-
from aleph.sdk.node import MessageCache, message_to_post
16+
from aleph.sdk.node import MessageCache
17+
from aleph.sdk.node.post import message_to_post
1718

1819

1920
@pytest.mark.asyncio

0 commit comments

Comments
 (0)