# Path: APITaxi_models2/unittest/factories.py
# class CustomerFactory(BaseFactory):
#     class Meta:
#         model = Customer
# 
#     id = factory.Sequence(lambda n: 'CUSTOMER_%d' % n)
#     added_at = factory.LazyFunction(datetime.datetime.now)
#     added_by = factory.SubFactory(UserFactory)
#     added_via = 'api'
#     source = 'added_by'
#     phone_number = factory.Sequence(lambda n: '+336%09d' % n)
# 
# class HailFactory(BaseFactory):
#     class Meta:
#         model = Hail
# 
#     id = factory.Sequence(lambda n: 'HAIL_%d' % n)
#     creation_datetime = datetime.datetime(2012, 12, 21, 13, 37, 13)
#     taxi = factory.SubFactory(TaxiFactory, added_by=factory.SelfAttribute('..operateur'))
#     status = 'received'
#     customer = factory.SubFactory(CustomerFactory, added_by=factory.SelfAttribute('..added_by'))
#     customer_lat = 48.850690
#     customer_lon = 2.308620
#     operateur = factory.SubFactory(UserFactory)
#     customer_address = '20 Avenue de Ségur, 75007 Paris'
#     customer_phone_number = '0799100222'
#     added_at = factory.LazyFunction(datetime.datetime.now)
#     added_by = factory.SubFactory(UserFactory)
#     added_via = 'api'
#     source = 'added_by'
# 
# 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)


import dateutil
from APITaxi_models2.unittest.factories import (
    CustomerFactory,
    HailFactory,
    UserFactory,
)



class TestSession:
    def test_invalid(self, anonymous, moteur, operateur, admin):
        resp = anonymous.client.get('/sessions')
        assert resp.status_code == 401

        resp = operateur.client.get('/sessions')
        assert resp.status_code == 403

        # Invalid querystring parameters
        resp = admin.client.get('/sessions?x=y')
        assert resp.status_code == 400
        assert 'x' in resp.json['errors']

        resp = moteur.client.get('/sessions?x=y')
        assert resp.status_code == 400
        assert 'x' in resp.json['errors']

    def test_ok(self, admin, moteur, QueriesTracker):
        customer = CustomerFactory(added_by=moteur.user)

        other_user = UserFactory()

# Path: APITaxi_models2/unittest/factories.py
# class CustomerFactory(BaseFactory):
#     class Meta:
#         model = Customer
# 
#     id = factory.Sequence(lambda n: 'CUSTOMER_%d' % n)
#     added_at = factory.LazyFunction(datetime.datetime.now)
#     added_by = factory.SubFactory(UserFactory)
#     added_via = 'api'
#     source = 'added_by'
#     phone_number = factory.Sequence(lambda n: '+336%09d' % n)
# 
# class HailFactory(BaseFactory):
#     class Meta:
#         model = Hail
# 
#     id = factory.Sequence(lambda n: 'HAIL_%d' % n)
#     creation_datetime = datetime.datetime(2012, 12, 21, 13, 37, 13)
#     taxi = factory.SubFactory(TaxiFactory, added_by=factory.SelfAttribute('..operateur'))
#     status = 'received'
#     customer = factory.SubFactory(CustomerFactory, added_by=factory.SelfAttribute('..added_by'))
#     customer_lat = 48.850690
#     customer_lon = 2.308620
#     operateur = factory.SubFactory(UserFactory)
#     customer_address = '20 Avenue de Ségur, 75007 Paris'
#     customer_phone_number = '0799100222'
#     added_at = factory.LazyFunction(datetime.datetime.now)
#     added_by = factory.SubFactory(UserFactory)
#     added_via = 'api'
#     source = 'added_by'
# 
# 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_sessions.py
import dateutil
from APITaxi_models2.unittest.factories import (
    CustomerFactory,
    HailFactory,
    UserFactory,
)




class TestSession:
    def test_invalid(self, anonymous, moteur, operateur, admin):
        resp = anonymous.client.get('/sessions')
        assert resp.status_code == 401

        resp = operateur.client.get('/sessions')
        assert resp.status_code == 403

        # Invalid querystring parameters
        resp = admin.client.get('/sessions?x=y')
        assert resp.status_code == 400
        assert 'x' in resp.json['errors']

        resp = moteur.client.get('/sessions?x=y')
        assert resp.status_code == 400
        assert 'x' in resp.json['errors']

    def test_ok(self, admin, moteur, QueriesTracker):
        customer = CustomerFactory(added_by=moteur.user)

        other_user = UserFactory()

        other_customer = CustomerFactory(added_by=other_user)