File tree Expand file tree Collapse file tree 5 files changed +19
-12
lines changed Expand file tree Collapse file tree 5 files changed +19
-12
lines changed Original file line number Diff line number Diff 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"
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -113,10 +113,10 @@ def messages() -> List[AlephMessage]:
113113
114114@pytest .fixture
115115def 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 }
Original file line number Diff line number Diff line change @@ -54,8 +54,9 @@ async def text(self):
5454
5555
5656class 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"
Original file line number Diff line number Diff line change 1313
1414from aleph .sdk .chains .ethereum import get_fallback_account
1515from 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
You can’t perform that action at this time.
0 commit comments