# Path: APITaxi_models2/unittest/factories.py
# class TownFactory(BaseFactory):
#     class Meta:
#         model = Town
#         sqlalchemy_get_or_create = ['insee']
# 
#     name = 'Paris'
#     insee = '75056'
# 
#     # The MUTLIPOLYGON below is a simple square containing Paris. It has been
#     # generated with a WKT editor such as:
#     #
#     # http://arthur-e.github.io/Wicket/sandbox-gmaps3.html
#     # https://clydedacruz.github.io/openstreetmap-wkt-playground/
#     #
#     # To convert a POLYGON (as returned by these editors) to a MULTIPOLYGON (as
#     # expected by ZUPC.shape), run the following query from a postgis database:
#     #
#     # SELECT ST_AsText(ST_Multi(ST_GeomFromText('POLYGON((2.24......))')));
#     shape = 'MULTIPOLYGON(((2.24332732355285 48.9066360266329,2.42460173761535 48.9066360266329,2.42460173761535 48.8122203058303,2.24332732355285 48.8122203058303,2.24332732355285 48.9066360266329)))'
# 
#     class Params:
#         bordeaux = factory.Trait(
#             name='Bordeaux',
#             insee='33063',
#             shape='MULTIPOLYGON(((-0.686737474226045 44.9009485734125,-0.494476732038545 44.9009485734125,-0.494476732038545 44.7826391041975,-0.686737474226045 44.7826391041975,-0.686737474226045 44.9009485734125)))',
#         )
#         charenton = factory.Trait(
#             name='Charenton-le-Pont',
#             insee='94018',
#             shape='MULTIPOLYGON(((2.40222930908203 48.8296390842375,2.41973876953125 48.8241580560601,2.41939544677734 48.8177721847637,2.40119934082031 48.8211630141963,2.39235877990723 48.8267008756382,2.40222930908203 48.8296390842375)))',
#         )
# 
# 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 APITaxi_models2.unittest.factories import (
    TownFactory,
    ZUPCFactory,
)

        assert resp.status_code == 200
        assert resp.json['data'] == [{
            'type': 'ZUPC',
            'name': zupc.nom,
            'zupc_id': zupc.zupc_id,
            'stats': {},
        }]

        resp = operateur.client.get('zupc?lon=2.35&lat=48.86')
        assert resp.status_code == 200
        assert resp.json['data'] == [{
            'type': 'ZUPC',
            'name': zupc.nom,
            'zupc_id': zupc.zupc_id,
            'stats': {
                'operators': {
                    operateur.user.email: 0,
                }
            },
        }]


class TestZUPCLive:
    def test_invalid(self, anonymous):
        resp = anonymous.client.get('/zupc/live')
        assert resp.status_code == 401

    def test_ok(self, operateur, QueriesTracker):
        zupc = ZUPCFactory()

# Path: APITaxi_models2/unittest/factories.py
# class TownFactory(BaseFactory):
#     class Meta:
#         model = Town
#         sqlalchemy_get_or_create = ['insee']
# 
#     name = 'Paris'
#     insee = '75056'
# 
#     # The MUTLIPOLYGON below is a simple square containing Paris. It has been
#     # generated with a WKT editor such as:
#     #
#     # http://arthur-e.github.io/Wicket/sandbox-gmaps3.html
#     # https://clydedacruz.github.io/openstreetmap-wkt-playground/
#     #
#     # To convert a POLYGON (as returned by these editors) to a MULTIPOLYGON (as
#     # expected by ZUPC.shape), run the following query from a postgis database:
#     #
#     # SELECT ST_AsText(ST_Multi(ST_GeomFromText('POLYGON((2.24......))')));
#     shape = 'MULTIPOLYGON(((2.24332732355285 48.9066360266329,2.42460173761535 48.9066360266329,2.42460173761535 48.8122203058303,2.24332732355285 48.8122203058303,2.24332732355285 48.9066360266329)))'
# 
#     class Params:
#         bordeaux = factory.Trait(
#             name='Bordeaux',
#             insee='33063',
#             shape='MULTIPOLYGON(((-0.686737474226045 44.9009485734125,-0.494476732038545 44.9009485734125,-0.494476732038545 44.7826391041975,-0.686737474226045 44.7826391041975,-0.686737474226045 44.9009485734125)))',
#         )
#         charenton = factory.Trait(
#             name='Charenton-le-Pont',
#             insee='94018',
#             shape='MULTIPOLYGON(((2.40222930908203 48.8296390842375,2.41973876953125 48.8241580560601,2.41939544677734 48.8177721847637,2.40119934082031 48.8211630141963,2.39235877990723 48.8267008756382,2.40222930908203 48.8296390842375)))',
#         )
# 
# 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_zupc.py
from APITaxi_models2.unittest.factories import (
    TownFactory,
    ZUPCFactory,
)


        assert resp.status_code == 200
        assert resp.json['data'] == [{
            'type': 'ZUPC',
            'name': zupc.nom,
            'zupc_id': zupc.zupc_id,
            'stats': {},
        }]

        resp = operateur.client.get('zupc?lon=2.35&lat=48.86')
        assert resp.status_code == 200
        assert resp.json['data'] == [{
            'type': 'ZUPC',
            'name': zupc.nom,
            'zupc_id': zupc.zupc_id,
            'stats': {
                'operators': {
                    operateur.user.email: 0,
                }
            },
        }]


class TestZUPCLive:
    def test_invalid(self, anonymous):
        resp = anonymous.client.get('/zupc/live')
        assert resp.status_code == 401

    def test_ok(self, operateur, QueriesTracker):
        zupc = ZUPCFactory()

        zupc2 = ZUPCFactory(bordeaux=True)