def test_coords(db): # make them have not added a location user1, token1 = generate_user(geom=None, geom_radius=None) user2, token2 = generate_user() with api_session(token2) as api: res = api.Ping(api_pb2.PingReq()) assert res.user.city == user2.city lat, lng = user2.coordinates or (0, 0) assert res.user.lat == lat assert res.user.lng == lng assert res.user.radius == user2.geom_radius with api_session(token2) as api: res = api.GetUser(api_pb2.GetUserReq(user=user1.username)) assert res.city == user1.city assert res.lat == 0.0 assert res.lng == 0.0 assert res.radius == 0.0 with real_jail_session(token1) as jail: res = jail.JailInfo(empty_pb2.Empty()) assert res.jailed assert res.has_not_added_location res = jail.SetLocation( jail_pb2.SetLocationReq( city="New York City", lat=40.7812, lng=-73.9647, radius=250, )) assert not res.jailed assert not res.has_not_added_location res = jail.JailInfo(empty_pb2.Empty()) assert not res.jailed assert not res.has_not_added_location with api_session(token2) as api: res = api.GetUser(api_pb2.GetUserReq(user=user1.username)) assert res.city == "New York City" assert res.lat == 40.7812 assert res.lng == -73.9647 assert res.radius == 250
def test_SetLocation(db): # make them have not added a location user1, token1 = generate_user(geom=None, geom_radius=None) with real_jail_session(token1) as jail: res = jail.JailInfo(empty_pb2.Empty()) assert res.jailed assert res.has_not_added_location res = jail.SetLocation( jail_pb2.SetLocationReq( city="New York City", lat=40.7812, lng=-73.9647, radius=250, ) ) assert not res.jailed assert not res.has_not_added_location res = jail.JailInfo(empty_pb2.Empty()) assert not res.jailed assert not res.has_not_added_location
def test_coords(db): # make them have not added a location user1, token1 = generate_user(geom=None, geom_radius=None) user2, token2 = generate_user() with api_session(token2) as api: res = api.Ping(api_pb2.PingReq()) assert res.user.city == user2.city lat, lng = user2.coordinates or (0, 0) assert res.user.lat == lat assert res.user.lng == lng assert res.user.radius == user2.geom_radius with api_session(token2) as api: res = api.GetUser(api_pb2.GetUserReq(user=user1.username)) assert res.city == user1.city assert res.lat == 0.0 assert res.lng == 0.0 assert res.radius == 0.0 # Check coordinate wrapping user3, token3 = generate_user(geom=create_coordinate(40.0, -180.5)) user4, token4 = generate_user(geom=create_coordinate(40.0, 20.0)) user5, token5 = generate_user(geom=create_coordinate(90.5, 20.0)) with api_session(token3) as api: res = api.GetUser(api_pb2.GetUserReq(user=user3.username)) assert res.lat == 40.0 assert res.lng == 179.5 with api_session(token4) as api: res = api.GetUser(api_pb2.GetUserReq(user=user4.username)) assert res.lat == 40.0 assert res.lng == 20.0 # PostGIS does not wrap longitude for latitude overflow with api_session(token5) as api: res = api.GetUser(api_pb2.GetUserReq(user=user5.username)) assert res.lat == 89.5 assert res.lng == 20.0 with real_jail_session(token1) as jail: res = jail.JailInfo(empty_pb2.Empty()) assert res.jailed assert res.has_not_added_location res = jail.SetLocation( jail_pb2.SetLocationReq( city="New York City", lat=40.7812, lng=-73.9647, radius=250, )) assert not res.jailed assert not res.has_not_added_location res = jail.JailInfo(empty_pb2.Empty()) assert not res.jailed assert not res.has_not_added_location with api_session(token2) as api: res = api.GetUser(api_pb2.GetUserReq(user=user1.username)) assert res.city == "New York City" assert res.lat == 40.7812 assert res.lng == -73.9647 assert res.radius == 250