def post_taxi_and_locate(self, lat=1, lon=1, user='******', float_=False, post_second=False, custom_ads=None): taxi = self.post_taxi(user=user, post_second=post_second, custom_ads=custom_ads) timestamp_type = float if float_ else int values = [timestamp_type(time.time()), lat, lon, 'free', 'd1', 1] redis_store.hset('taxi:{}'.format(taxi['id']), user, ' '.join(map(lambda v: str(v), values))) n = '{}:{}'.format(taxi['id'], user) redis_store.geoadd(current_app.config['REDIS_GEOINDEX'], lat, lon, n) redis_store.zadd(current_app.config['REDIS_TIMESTAMPS'], **{n:time.time()}) return taxi
def test_one_taxi_two_desc_one_non_free_but_timeout(self): self.add() id_taxi = self.post_taxi_and_locate(user='******', lat=2.3, lon=48.7)['id'] #This taxi is now not fresh for operateur_2 redis_store.zadd(current_app.config['REDIS_TIMESTAMPS'], **{'{}:user_operateur_2'.format(id_taxi):0.0}) r = self.put([{"status": "off"}], '/taxis/{}/'.format(id_taxi), user='******', role='operateur') self.assert200(r) r = self.get('/taxis/?lat=2.3&lon=48.7') self.assert200(r) #So we should have a taxi assert len(r.json['data']) == 1
def test_one_taxi_two_desc_one_non_free_but_timeout(self): self.add() id_taxi = self.post_taxi_and_locate(user='******', lat=2.3, lon=48.7)['id'] #This taxi is now not fresh for operateur_2 redis_store.zadd(current_app.config['REDIS_TIMESTAMPS'], **{'{}:user_operateur_2'.format(id_taxi):0.0}) from APITaxi.tasks import clean_geoindex_timestamps clean_geoindex_timestamps() r = self.put([{"status": "off"}], '/taxis/{}/'.format(id_taxi), user='******', role='operateur') self.assert200(r) r = self.get('/taxis/?lat=2.3&lon=48.7') self.assert200(r) #So we should have a taxi assert len(r.json['data']) == 1
def post_taxi_and_locate(self, lat=1, lon=1, user='******', float_=False, post_second=False, custom_ads=None): taxi = self.post_taxi(user=user, post_second=post_second, custom_ads=custom_ads) timestamp_type = float if float_ else int values = [timestamp_type(time.time()), lat, lon, 'free', 'd1', 1] redis_store.hset('taxi:{}'.format(taxi['id']), user, ' '.join(map(lambda v: str(v), values))) n = '{}:{}'.format(taxi['id'], user) redis_store.geoadd(current_app.config['REDIS_GEOINDEX'], lat, lon, n) redis_store.zadd(current_app.config['REDIS_TIMESTAMPS'], **{n: time.time()}) redis_store.geoadd(current_app.config['REDIS_GEOINDEX_ID'], lat, lon, taxi['id']) redis_store.zadd(current_app.config['REDIS_TIMESTAMPS_ID'], **{taxi['id']: time.time()}) return taxi