1+ import datetime
12from typing import Dict
23
34import pytest
78
89@pytest .mark .incremental
910class TestLiveLocations :
10- async def test_get_user_locations (self , client : StreamChatAsync , random_user : Dict ):
11- # First create a message to attach location to
12- channel = client .channel ("messaging" , str (random_user ["id" ]))
13- channel .create (random_user ["id" ])
11+ @pytest .fixture (autouse = True )
12+ @pytest .mark .asyncio
13+ async def setup_channel_for_shared_locations (self , channel ):
14+ await channel .update_partial (
15+ {"config_overrides" : {"shared_locations" : True }},
16+ )
17+ yield
18+ await channel .update_partial (
19+ {"config_overrides" : {"shared_locations" : False }},
20+ )
1421
22+ async def test_get_user_locations (
23+ self , client : StreamChatAsync , channel , random_user : Dict
24+ ):
1525 # Create a message to attach location to
26+ now = datetime .datetime .now (datetime .timezone .utc )
27+ one_hour_later = now + datetime .timedelta (hours = 1 )
1628 shared_location = {
29+ "created_by_device_id" : "test_device_id" ,
1730 "latitude" : 37.7749 ,
1831 "longitude" : - 122.4194 ,
32+ "end_at" : one_hour_later .isoformat (),
1933 }
2034
2135 channel .send_message (
@@ -30,26 +44,36 @@ async def test_get_user_locations(self, client: StreamChatAsync, random_user: Di
3044 assert isinstance (response ["active_live_locations" ], list )
3145
3246 async def test_update_user_location (
33- self , client : StreamChatAsync , random_user : Dict
47+ self , client : StreamChatAsync , channel , random_user : Dict
3448 ):
35- # First create a message to attach location to
36- channel = client .channel ("messaging" , str (random_user ["id" ]))
37- await channel .create (random_user ["id" ])
49+ # Create a message to attach location to
50+ now = datetime .datetime .now (datetime .timezone .utc )
51+ one_hour_later = now + datetime .timedelta (hours = 1 )
52+ shared_location = {
53+ "created_by_device_id" : "test_device_id" ,
54+ "latitude" : 37.7749 ,
55+ "longitude" : - 122.4194 ,
56+ "end_at" : one_hour_later .isoformat (),
57+ }
58+
3859 msg = await channel .send_message (
39- {"text" : "Message with location" }, random_user ["id" ]
60+ {"text" : "Message with location" , "shared_location" : shared_location },
61+ random_user ["id" ],
4062 )
4163 message_id = msg ["message" ]["id" ]
4264
4365 # Update user location
4466 location_data = {
67+ "created_by_device_id" : "test_device_id" ,
4568 "latitude" : 37.7749 ,
4669 "longitude" : - 122.4194 ,
4770 }
48- response = await client .update_user_location (message_id , location_data )
71+ response = await client .update_user_location (
72+ random_user ["id" ], message_id , location_data
73+ )
4974
50- assert "shared_location" in response
51- assert response ["shared_location" ]["latitude" ] == location_data ["latitude" ]
52- assert response ["shared_location" ]["longitude" ] == location_data ["longitude" ]
75+ assert response ["latitude" ] == location_data ["latitude" ]
76+ assert response ["longitude" ] == location_data ["longitude" ]
5377
5478 # Get user locations to verify
5579 locations_response = await client .get_user_locations (random_user ["id" ])
@@ -58,9 +82,3 @@ async def test_update_user_location(
5882 location = locations_response ["active_live_locations" ][0 ]
5983 assert location ["latitude" ] == location_data ["latitude" ]
6084 assert location ["longitude" ] == location_data ["longitude" ]
61-
62- # Cleanup
63- try :
64- await channel .delete ()
65- except Exception :
66- pass
0 commit comments