# Path: APITaxi_models2/unittest/factories.py
# class ADSFactory(BaseFactory):
#     class Meta:
#         model = ADS
# 
#     numero = factory.Sequence(lambda n: 'ads_number_%d' % n)
#     added_at = factory.LazyFunction(datetime.datetime.now)
#     added_by = factory.SubFactory(UserFactory)
#     insee = '75056'
#     vehicle = factory.SubFactory(VehicleFactory, descriptions__added_by=factory.SelfAttribute('...added_by'))
#     owner_type = 'individual'
#     owner_name = 'Owner ADS'
#     category = ''
#     added_via = 'api'
#     source = 'added_by'
# 
# class DriverFactory(BaseFactory):
#     class Meta:
#         model = Driver
# 
#     last_name = factory.Sequence(lambda n: 'Dupont %d' % n)
#     first_name = 'Jean'
#     birth_date = datetime.date(1978, 1, 11)
#     professional_licence = factory.Sequence(lambda n: 'LICENCE_PRO_%d' % n)
#     departement = factory.SubFactory(DepartementFactory)
#     added_via = 'api'
#     source = 'added_by'
# 
# class TaxiFactory(BaseFactory):
#     class Meta:
#         model = Taxi
# 
#     id = factory.Sequence(lambda n: 'TAXI_%d' % n)
#     vehicle = factory.SubFactory(VehicleFactory, descriptions__added_by=factory.SelfAttribute('...added_by'))
#     ads = factory.SubFactory(
#         ADSFactory,
#         added_by=factory.SelfAttribute('..added_by'),
#         vehicle=factory.SelfAttribute('..vehicle'),
#     )
#     added_at = factory.LazyFunction(datetime.datetime.now)
#     added_by = factory.SubFactory(UserFactory)
#     driver = factory.SubFactory(DriverFactory)
#     added_via = 'api'
#     source = 'added_by'
# 
# class VehicleFactory(BaseFactory):
#     class Meta:
#         model = Vehicle
# 
#     licence_plate = factory.Sequence(lambda n: "AB-%03d-CD" % n)
# 
#     @factory.post_generation
#     def descriptions(self, create, extracted, **kwargs):
#         """Create a VehicleDescription for this Vehicle."""
#         if not create or extracted is not None:
#             return extracted
#         return [VehicleDescriptionFactory(vehicle=self, **kwargs)]
# 
# class VehicleDescriptionFactory(BaseFactory):
#     class Meta:
#         model = VehicleDescription
# 
#     # Circular dependencies require to provide the full import path of the
#     # target.
#     vehicle = factory.SubFactory(__name__ + '.VehicleFactory')
#     constructor = 'Citroën'
#     model = 'C4 PICASSO'
#     added_at = factory.LazyFunction(datetime.datetime.now)
#     added_by = factory.SubFactory(UserFactory)
#     added_via = 'api'
#     source = 'added_by'
#     status = 'free'
# 
# class ZUPCFactory(BaseFactory):
#     class Meta:
#         model = ZUPC
#         sqlalchemy_get_or_create = ['nom']
# 
#     nom = 'Paris'
# 
#     zupc_id = factory.LazyAttribute(lambda o: str(uuid.uuid4()))
#     allowed = factory.LazyAttribute(lambda o: [TownFactory(), TownFactory(charenton=True)])
# 
#     class Params:
#         bordeaux = factory.Trait(
#             nom='Bordeaux',
#             allowed=factory.LazyAttribute(lambda o: [TownFactory(bordeaux=True)])
#         )


from datetime import datetime, timedelta
from sqlalchemy.orm import lazyload
from APITaxi_models2 import Taxi, VehicleDescription
from APITaxi_models2.unittest.factories import (
    ADSFactory,
    DriverFactory,
    TaxiFactory,
    VehicleFactory,
    VehicleDescriptionFactory,
    ZUPCFactory,
)
import time

        resp = admin.client.get('/taxis/%s' % taxi.id)
        assert resp.status_code == 200
        assert resp.json['data'][0]['operator'] == admin.user.email

    def test_ok(self, app, operateur, QueriesTracker):
        taxi = TaxiFactory(added_by=operateur.user)

        # Store taxi position
        app.redis.hset(
            'taxi:%s' % taxi.id,
            operateur.user.email,
            '1589567716 48.84 2.35 free phone 2'
        )

        with QueriesTracker() as qtracker:
            resp = operateur.client.get('/taxis/%s' % taxi.id)
            # SELECT permissions, SELECT taxi (joinedload all other resources)
            assert qtracker.count == 2

        assert resp.status_code == 200
        assert resp.json['data'][0]['last_update'] == 1589567716
        assert resp.json['data'][0]['position']['lat'] == 48.84
        assert resp.json['data'][0]['position']['lon'] == 2.35


class TestTaxiPut:
    def test_ok(self, app, operateur, QueriesTracker):
        def _set_taxi_status(status, hail=None, initial_status=None):
            vehicle = VehicleFactory(descriptions=[])

# Path: APITaxi_models2/unittest/factories.py
# class ADSFactory(BaseFactory):
#     class Meta:
#         model = ADS
# 
#     numero = factory.Sequence(lambda n: 'ads_number_%d' % n)
#     added_at = factory.LazyFunction(datetime.datetime.now)
#     added_by = factory.SubFactory(UserFactory)
#     insee = '75056'
#     vehicle = factory.SubFactory(VehicleFactory, descriptions__added_by=factory.SelfAttribute('...added_by'))
#     owner_type = 'individual'
#     owner_name = 'Owner ADS'
#     category = ''
#     added_via = 'api'
#     source = 'added_by'
# 
# class DriverFactory(BaseFactory):
#     class Meta:
#         model = Driver
# 
#     last_name = factory.Sequence(lambda n: 'Dupont %d' % n)
#     first_name = 'Jean'
#     birth_date = datetime.date(1978, 1, 11)
#     professional_licence = factory.Sequence(lambda n: 'LICENCE_PRO_%d' % n)
#     departement = factory.SubFactory(DepartementFactory)
#     added_via = 'api'
#     source = 'added_by'
# 
# class TaxiFactory(BaseFactory):
#     class Meta:
#         model = Taxi
# 
#     id = factory.Sequence(lambda n: 'TAXI_%d' % n)
#     vehicle = factory.SubFactory(VehicleFactory, descriptions__added_by=factory.SelfAttribute('...added_by'))
#     ads = factory.SubFactory(
#         ADSFactory,
#         added_by=factory.SelfAttribute('..added_by'),
#         vehicle=factory.SelfAttribute('..vehicle'),
#     )
#     added_at = factory.LazyFunction(datetime.datetime.now)
#     added_by = factory.SubFactory(UserFactory)
#     driver = factory.SubFactory(DriverFactory)
#     added_via = 'api'
#     source = 'added_by'
# 
# class VehicleFactory(BaseFactory):
#     class Meta:
#         model = Vehicle
# 
#     licence_plate = factory.Sequence(lambda n: "AB-%03d-CD" % n)
# 
#     @factory.post_generation
#     def descriptions(self, create, extracted, **kwargs):
#         """Create a VehicleDescription for this Vehicle."""
#         if not create or extracted is not None:
#             return extracted
#         return [VehicleDescriptionFactory(vehicle=self, **kwargs)]
# 
# class VehicleDescriptionFactory(BaseFactory):
#     class Meta:
#         model = VehicleDescription
# 
#     # Circular dependencies require to provide the full import path of the
#     # target.
#     vehicle = factory.SubFactory(__name__ + '.VehicleFactory')
#     constructor = 'Citroën'
#     model = 'C4 PICASSO'
#     added_at = factory.LazyFunction(datetime.datetime.now)
#     added_by = factory.SubFactory(UserFactory)
#     added_via = 'api'
#     source = 'added_by'
#     status = 'free'
# 
# class ZUPCFactory(BaseFactory):
#     class Meta:
#         model = ZUPC
#         sqlalchemy_get_or_create = ['nom']
# 
#     nom = 'Paris'
# 
#     zupc_id = factory.LazyAttribute(lambda o: str(uuid.uuid4()))
#     allowed = factory.LazyAttribute(lambda o: [TownFactory(), TownFactory(charenton=True)])
# 
#     class Params:
#         bordeaux = factory.Trait(
#             nom='Bordeaux',
#             allowed=factory.LazyAttribute(lambda o: [TownFactory(bordeaux=True)])
#         )


# Path: APITaxi2/tests/test_taxis.py
from datetime import datetime, timedelta
from sqlalchemy.orm import lazyload
from APITaxi_models2 import Taxi, VehicleDescription
from APITaxi_models2.unittest.factories import (
    ADSFactory,
    DriverFactory,
    TaxiFactory,
    VehicleFactory,
    VehicleDescriptionFactory,
    ZUPCFactory,
)
import time


        resp = admin.client.get('/taxis/%s' % taxi.id)
        assert resp.status_code == 200
        assert resp.json['data'][0]['operator'] == admin.user.email

    def test_ok(self, app, operateur, QueriesTracker):
        taxi = TaxiFactory(added_by=operateur.user)

        # Store taxi position
        app.redis.hset(
            'taxi:%s' % taxi.id,
            operateur.user.email,
            '1589567716 48.84 2.35 free phone 2'
        )

        with QueriesTracker() as qtracker:
            resp = operateur.client.get('/taxis/%s' % taxi.id)
            # SELECT permissions, SELECT taxi (joinedload all other resources)
            assert qtracker.count == 2

        assert resp.status_code == 200
        assert resp.json['data'][0]['last_update'] == 1589567716
        assert resp.json['data'][0]['position']['lat'] == 48.84
        assert resp.json['data'][0]['position']['lon'] == 2.35


class TestTaxiPut:
    def test_ok(self, app, operateur, QueriesTracker):
        def _set_taxi_status(status, hail=None, initial_status=None):
            vehicle = VehicleFactory(descriptions=[])

            VehicleDescriptionFactory(