@@ -63,7 +63,7 @@ async def test_send_text_constructs_correct_payload_and_calls_post_internal(asyn
6363 expected_payload = {
6464 "to" : test_to ,
6565 "messageType" : "text" ,
66- "text" : { "body" : test_body } ,
66+ "text" : test_body ,
6767 "custom_param" : "test_val"
6868 }
6969 assert args [1 ] == expected_payload
@@ -89,13 +89,15 @@ async def test_send_image(async_client_with_mocked_post, success_api_response_da
8989 response = await client .send_image (to = test_to , url = test_url , caption = test_caption )
9090
9191 client ._post_internal .assert_called_once_with (
92- "/send-message" ,
92+ "/send-message" ,
9393 {
94- "to" : test_to ,
94+ "to" : test_to ,
9595 "messageType" : "image" ,
96- "image" : {"url" : test_url , "caption" : test_caption }
96+ "imageUrl" : test_url ,
97+ "text" : test_caption
9798 }
9899 )
100+ assert isinstance (response , WasenderSendResult )
99101 assert response .response .success == True
100102 assert response .response .message == success_api_response_data ["message" ]
101103 assert response .rate_limit .limit == rate_limit_data ["limit" ]
@@ -115,13 +117,15 @@ async def test_send_video(async_client_with_mocked_post, success_api_response_da
115117 response = await client .send_video (to = test_to , url = test_url , caption = test_caption )
116118
117119 client ._post_internal .assert_called_once_with (
118- "/send-message" ,
120+ "/send-message" ,
119121 {
120- "to" : test_to ,
122+ "to" : test_to ,
121123 "messageType" : "video" ,
122- "video" : {"url" : test_url , "caption" : test_caption }
124+ "videoUrl" : test_url ,
125+ "text" : test_caption
123126 }
124127 )
128+ assert isinstance (response , WasenderSendResult )
125129 assert response .response .success == True
126130 assert response .response .message == success_api_response_data ["message" ]
127131
@@ -141,13 +145,15 @@ async def test_send_document(async_client_with_mocked_post, success_api_response
141145 response = await client .send_document (to = test_to , url = test_url , filename = test_filename , caption = test_caption )
142146
143147 client ._post_internal .assert_called_once_with (
144- "/send-message" ,
148+ "/send-message" ,
145149 {
146- "to" : test_to ,
150+ "to" : test_to ,
147151 "messageType" : "document" ,
148- "document" : {"url" : test_url , "filename" : test_filename , "caption" : test_caption }
152+ "documentUrl" : test_url ,
153+ "text" : test_caption
149154 }
150155 )
156+ assert isinstance (response , WasenderSendResult )
151157 assert response .response .success == True
152158 assert response .response .message == success_api_response_data ["message" ]
153159
@@ -169,17 +175,17 @@ async def test_send_audio(async_client_with_mocked_post, success_api_response_da
169175 {
170176 "to" : test_to ,
171177 "messageType" : "audio" ,
172- "audio" : {"url" : test_url , "ptt" : False }
178+ "audioUrl" : test_url ,
179+ "ptt" : False
173180 }
174181 )
175- assert response_no_ptt .response .success is True
182+ assert isinstance (response_no_ptt , WasenderSendResult )
183+ assert response_no_ptt .response .data .message_id == success_api_response_data ["data" ]["messageId" ]
176184
177185 # Test Case 2: ptt = True
178- client ._post_internal .reset_mock () # Reset mock for a clean assertion
179- # Update message_id for distinct response if necessary, though not asserted here
180- updated_success_data = {** success_api_response_data , "data" : {** success_api_response_data ["data" ], "message_id" : "mock_audio_ptt_true" }}
181- client ._post_internal .return_value = {
182- "response" : updated_success_data , # Use potentially updated data
186+ client ._post_internal .reset_mock ()
187+ client ._post_internal .return_value = { # Assuming same response structure for simplicity
188+ "response" : success_api_response_data ,
183189 "rate_limit" : rate_limit_data
184190 }
185191 response_ptt = await client .send_audio (to = test_to , url = test_url , ptt = True )
@@ -188,10 +194,30 @@ async def test_send_audio(async_client_with_mocked_post, success_api_response_da
188194 {
189195 "to" : test_to ,
190196 "messageType" : "audio" ,
191- "audio" : {"url" : test_url , "ptt" : True }
197+ "audioUrl" : test_url ,
198+ "ptt" : True
199+ }
200+ )
201+ assert isinstance (response_ptt , WasenderSendResult )
202+ assert response_ptt .response .data .message_id == success_api_response_data ["data" ]["messageId" ]
203+
204+ # Test Case 3: ptt not provided (should default or not be included if None)
205+ client ._post_internal .reset_mock ()
206+ client ._post_internal .return_value = {
207+ "response" : success_api_response_data ,
208+ "rate_limit" : rate_limit_data
209+ }
210+ response_no_ptt_arg = await client .send_audio (to = test_to , url = test_url ) # ptt not passed
211+ client ._post_internal .assert_called_once_with (
212+ "/send-message" ,
213+ {
214+ "to" : test_to ,
215+ "messageType" : "audio" ,
216+ "audioUrl" : test_url # ptt should not be in payload if not provided
192217 }
193218 )
194- assert response_ptt .response .success is True
219+ assert isinstance (response_no_ptt_arg , WasenderSendResult )
220+ assert response_no_ptt_arg .response .data .message_id == success_api_response_data ["data" ]["messageId" ]
195221
196222@pytest .mark .asyncio
197223async def test_send_location (async_client_with_mocked_post , success_api_response_data , rate_limit_data ):
0 commit comments