1+ import pytest
2+ from typing import Dict
3+
4+ from stream_chat import StreamChat
5+
6+
7+ @pytest .mark .incremental
8+ class TestLiveLocations :
9+ def test_get_user_locations (self , client : StreamChat , random_user : Dict ):
10+ # First create a message to attach location to
11+ channel = client .channel ("messaging" , str (random_user ["id" ]))
12+ channel .create (random_user ["id" ])
13+
14+ # Create a message to attach location to
15+ shared_location = {
16+ "latitude" : 37.7749 ,
17+ "longitude" : - 122.4194 ,
18+ }
19+
20+ channel .send_message ({"text" : "Message with location" , "shared_location" : shared_location }, random_user ["id" ])
21+
22+ # Get user locations
23+ response = client .get_user_locations (random_user ["id" ])
24+
25+ assert "active_live_locations" in response
26+ assert isinstance (response ["active_live_locations" ], list )
27+
28+ def test_update_user_location (self , client : StreamChat , random_user : Dict ):
29+ # First create a message to attach location to
30+ channel = client .channel ("messaging" , str (random_user ["id" ]))
31+ channel .create (random_user ["id" ])
32+
33+ # Create a message to attach location to
34+ shared_location = {
35+ "latitude" : 37.7749 ,
36+ "longitude" : - 122.4194 ,
37+ }
38+
39+ msg = channel .send_message ({"text" : "Message with location" , "shared_location" : shared_location }, random_user ["id" ])
40+ message_id = msg ["message" ]["id" ]
41+
42+ # Update user location
43+ location_data = {
44+ "latitude" : 37.7749 ,
45+ "longitude" : - 122.4194 ,
46+ }
47+ response = client .update_user_location (message_id , location_data )
48+
49+ assert "shared_location" in response
50+ assert response ["shared_location" ]["latitude" ] == location_data ["latitude" ]
51+ assert response ["shared_location" ]["longitude" ] == location_data ["longitude" ]
52+
53+ # Get user locations to verify
54+ locations_response = client .get_user_locations (random_user ["id" ])
55+ assert "active_live_locations" in locations_response
56+ assert len (locations_response ["active_live_locations" ]) > 0
57+ location = locations_response ["active_live_locations" ][0 ]
58+ assert location ["latitude" ] == location_data ["latitude" ]
59+ assert location ["longitude" ] == location_data ["longitude" ]
60+
61+ # Cleanup
62+ try :
63+ channel .delete ()
64+ except Exception :
65+ pass
0 commit comments