# 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
            }]
        })
        assert resp.status_code == 404
        assert (resp.json['errors']['data']['0']['vehicle']['licence_plate']
                == ['Vehicle exists but has not been created by the user making the request'])

    def test_departement_not_found(self, operateur):
        ads = ADSFactory()
        driver = DriverFactory()
        vehicle_description = VehicleDescriptionFactory(added_by=operateur.user)

        resp = operateur.client.post('/taxis', json={
            'data': [{
                'ads': {
                    'insee': ads.insee,
                    'numero': ads.numero
                },
                'vehicle': {
                    'licence_plate': vehicle_description.vehicle.licence_plate
                },
                'driver': {
                    'professional_licence': driver.professional_licence,
                    'departement': 'xxx'
                }
            }]
        })
        assert resp.status_code == 404, resp.json
        assert resp.json['errors']['data']['0']['driver']['departement'] == ['Departement not found']

    def test_departement_ok_driver_invalid(self, operateur):

# 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

            }]
        })
        assert resp.status_code == 404
        assert (resp.json['errors']['data']['0']['vehicle']['licence_plate']
                == ['Vehicle exists but has not been created by the user making the request'])

    def test_departement_not_found(self, operateur):
        ads = ADSFactory()
        driver = DriverFactory()
        vehicle_description = VehicleDescriptionFactory(added_by=operateur.user)

        resp = operateur.client.post('/taxis', json={
            'data': [{
                'ads': {
                    'insee': ads.insee,
                    'numero': ads.numero
                },
                'vehicle': {
                    'licence_plate': vehicle_description.vehicle.licence_plate
                },
                'driver': {
                    'professional_licence': driver.professional_licence,
                    'departement': 'xxx'
                }
            }]
        })
        assert resp.status_code == 404, resp.json
        assert resp.json['errors']['data']['0']['driver']['departement'] == ['Departement not found']

    def test_departement_ok_driver_invalid(self, operateur):

        ads = ADSFactory()