# 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
            # SELECT permissions, SELECT departement, SELECT driver (to check
            # if exists), INSERT driver
            assert qtracker.count == 4

        assert resp.status_code == 201
        assert Driver.query.count() == 1

    def test_mispelled_departement(self, operateur):
        """If departement numero is correct but not the name, request should
        still succeed."""
        departement = DepartementFactory()

        resp = operateur.client.post('/drivers', json={'data': [{
            'first_name': 'Evander',
            'last_name': 'Holyfield',
            'professional_licence': 'xxx',
            'departement': {
                'nom': 'xxxxxxxxxxx',
                'numero': departement.numero
            }
        }]})

        assert resp.status_code == 201
        assert Driver.query.count() == 1

    def test_duplicates_departement(self, operateur):
        """We specify a valid departement numero and nom, but they refer to two
        different departements.
        """
        departement = DepartementFactory()

# 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

            # SELECT permissions, SELECT departement, SELECT driver (to check
            # if exists), INSERT driver
            assert qtracker.count == 4

        assert resp.status_code == 201
        assert Driver.query.count() == 1

    def test_mispelled_departement(self, operateur):
        """If departement numero is correct but not the name, request should
        still succeed."""
        departement = DepartementFactory()

        resp = operateur.client.post('/drivers', json={'data': [{
            'first_name': 'Evander',
            'last_name': 'Holyfield',
            'professional_licence': 'xxx',
            'departement': {
                'nom': 'xxxxxxxxxxx',
                'numero': departement.numero
            }
        }]})

        assert resp.status_code == 201
        assert Driver.query.count() == 1

    def test_duplicates_departement(self, operateur):
        """We specify a valid departement numero and nom, but they refer to two
        different departements.
        """
        departement = DepartementFactory()

        departement2 = DepartementFactory()