# Path: APITaxi_models2/unittest/factories.py
# class DepartementFactory(BaseFactory):
#     class Meta:
#         model = Departement
#         sqlalchemy_get_or_create = ['numero']
# 
#     nom = factory.Sequence(lambda n: 'DEPARTEMENT_%d' % n)
#     numero = factory.Sequence(lambda n: '%d' % n)
# 
# 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'


from unittest import mock
from APITaxi_models2 import db, Driver
from APITaxi_models2.unittest.factories import DepartementFactory, DriverFactory
import psycopg2.errors
            }
        }]})
        assert resp.status_code == 404
        assert len(resp.json['errors']['data']['0']['departement']['nom']) > 0
        assert len(resp.json['errors']['data']['0']['departement']['numero']) > 0

    def test_already_exists(self, operateur):
        """POST to an existing driver doesn't create the driver."""
        assert Driver.query.count() == 0

        driver = DriverFactory(added_by=operateur.user)
        assert Driver.query.count() == 1

        # Driver already exists, Driver is updated but no new driver created
        resp = operateur.client.post('/drivers', json={'data': [{
            'first_name': driver.first_name,
            'last_name': driver.last_name,
            'professional_licence': driver.professional_licence,
            'departement': {
                'nom': driver.departement.nom,
                'numero': driver.departement.numero
            }
        }]})
        assert resp.status_code == 200
        assert Driver.query.count() == 1

    def test_already_exists_different_departement(self, operateur):
        """Two drivers with same professional_licence id but different
        departements are considered different."""
        assert Driver.query.count() == 0

# Path: APITaxi_models2/unittest/factories.py
# class DepartementFactory(BaseFactory):
#     class Meta:
#         model = Departement
#         sqlalchemy_get_or_create = ['numero']
# 
#     nom = factory.Sequence(lambda n: 'DEPARTEMENT_%d' % n)
#     numero = factory.Sequence(lambda n: '%d' % n)
# 
# 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'


# Path: APITaxi2/tests/test_drivers.py
from unittest import mock
from APITaxi_models2 import db, Driver
from APITaxi_models2.unittest.factories import DepartementFactory, DriverFactory
import psycopg2.errors

            }
        }]})
        assert resp.status_code == 404
        assert len(resp.json['errors']['data']['0']['departement']['nom']) > 0
        assert len(resp.json['errors']['data']['0']['departement']['numero']) > 0

    def test_already_exists(self, operateur):
        """POST to an existing driver doesn't create the driver."""
        assert Driver.query.count() == 0

        driver = DriverFactory(added_by=operateur.user)
        assert Driver.query.count() == 1

        # Driver already exists, Driver is updated but no new driver created
        resp = operateur.client.post('/drivers', json={'data': [{
            'first_name': driver.first_name,
            'last_name': driver.last_name,
            'professional_licence': driver.professional_licence,
            'departement': {
                'nom': driver.departement.nom,
                'numero': driver.departement.numero
            }
        }]})
        assert resp.status_code == 200
        assert Driver.query.count() == 1

    def test_already_exists_different_departement(self, operateur):
        """Two drivers with same professional_licence id but different
        departements are considered different."""
        assert Driver.query.count() == 0

        driver = DriverFactory()