# Path: APITaxi_models2/unittest/factories.py
# class UserFactory(BaseFactory):
#     class Meta:
#         model = User
#         sqlalchemy_get_or_create = ('email',)
# 
#     email = factory.Sequence(lambda n: 'test_user_%d' % n)
#     password = 'super_password'
#     active = True
#     confirmed_at = datetime.datetime(2015, 12, 1, 13, 37)
#     apikey = factory.Sequence(lambda n: 'API_KEY_%d' % n)


from APITaxi_models2.unittest.factories import UserFactory
        # user id is not an integer, route is not found
        resp = anonymous.client.get('/users/xxx')
        assert resp.status_code == 404

        # Login required
        resp = anonymous.client.get('/users/999')
        assert resp.status_code == 401

        for role in (operateur, moteur):
            # User does not exist
            resp = role.client.get('/users/999')
            assert resp.status_code == 404

            # User exists but client is not the owner
            resp = role.client.get('/users/%s' % user.id)
            assert resp.status_code == 403

        # 404
        resp = admin.client.get('/users/999')
        assert resp.status_code == 404

    def test_ok(self, operateur, QueriesTracker):
        with QueriesTracker() as qtrack:
            resp = operateur.client.get('/users/%d' % operateur.user.id)
            # SELECT for permissions, SELECT users
            assert qtrack.count == 2

        assert resp.status_code == 200

    def test_admin(self, admin):

# Path: APITaxi_models2/unittest/factories.py
# class UserFactory(BaseFactory):
#     class Meta:
#         model = User
#         sqlalchemy_get_or_create = ('email',)
# 
#     email = factory.Sequence(lambda n: 'test_user_%d' % n)
#     password = 'super_password'
#     active = True
#     confirmed_at = datetime.datetime(2015, 12, 1, 13, 37)
#     apikey = factory.Sequence(lambda n: 'API_KEY_%d' % n)


# Path: APITaxi2/tests/test_users.py
from APITaxi_models2.unittest.factories import UserFactory

        # user id is not an integer, route is not found
        resp = anonymous.client.get('/users/xxx')
        assert resp.status_code == 404

        # Login required
        resp = anonymous.client.get('/users/999')
        assert resp.status_code == 401

        for role in (operateur, moteur):
            # User does not exist
            resp = role.client.get('/users/999')
            assert resp.status_code == 404

            # User exists but client is not the owner
            resp = role.client.get('/users/%s' % user.id)
            assert resp.status_code == 403

        # 404
        resp = admin.client.get('/users/999')
        assert resp.status_code == 404

    def test_ok(self, operateur, QueriesTracker):
        with QueriesTracker() as qtrack:
            resp = operateur.client.get('/users/%d' % operateur.user.id)
            # SELECT for permissions, SELECT users
            assert qtrack.count == 2

        assert resp.status_code == 200

    def test_admin(self, admin):

        user = UserFactory(commercial_name='Bob Dylan')