# Path: tests/blindrtest.py
# class BlindrTest(TestCase):
#     def create_app(self):
#         return create_app('config.test')
# 
#     def setUp(self):
#         db.create_all()
#         self.auth_user = UserFactory(
#             id='auth_user',
#             fake_name='Foo Bar',
#             real_name='Auth User',
#             last_poll=datetime(2000,1,1)
#         )
# 
#     def tearDown(self):
#         db.session.remove()
#         db.drop_all()
# 
#     def auth_post(self, *args, **kwargs):
#         self._add_header_auth_token(kwargs)
#         return self.client.post(*args, **kwargs)
# 
#     def auth_get(self, *args, **kwargs):
#         self._add_header_auth_token(kwargs)
#         return self.client.get(*args, **kwargs)
# 
#     def _add_header_auth_token(self, kwargs):
#         s = itsdangerous.Signer(self.app.config['AUTH_SECRET'])
#         token = s.sign(b'auth_user').decode('utf-8')
# 
#         if not 'headers' in kwargs:
#             kwargs['headers'] = {}
# 
#         kwargs['headers']['X-User-Token'] = token
# 
# Path: tests/factory_boy/user_factory.py
# class UserFactory(factory.alchemy.SQLAlchemyModelFactory):
#     class Meta:
#         model = User
#         sqlalchemy_session = db.session
# 
#     id = factory.Sequence(lambda n: str(n))
# 
#     fake_name = 'Fakename'
#     real_name = 'Realname'
#     gender = 'm'


from tests.blindrtest import BlindrTest
from tests.factory_boy.user_factory import UserFactory
from unittest import mock
import json

class AuthTest(BlindrTest):

    @mock.patch('blindr.api.auth.User.from_facebook')
    def test_success_auth(self, mock_user):
        user = UserFactory.create(id='123123')
        mock_user.return_value = user

        rv = self.client.post('/auth', data=dict(fb_token='token_123'))


# Path: tests/blindrtest.py
# class BlindrTest(TestCase):
#     def create_app(self):
#         return create_app('config.test')
# 
#     def setUp(self):
#         db.create_all()
#         self.auth_user = UserFactory(
#             id='auth_user',
#             fake_name='Foo Bar',
#             real_name='Auth User',
#             last_poll=datetime(2000,1,1)
#         )
# 
#     def tearDown(self):
#         db.session.remove()
#         db.drop_all()
# 
#     def auth_post(self, *args, **kwargs):
#         self._add_header_auth_token(kwargs)
#         return self.client.post(*args, **kwargs)
# 
#     def auth_get(self, *args, **kwargs):
#         self._add_header_auth_token(kwargs)
#         return self.client.get(*args, **kwargs)
# 
#     def _add_header_auth_token(self, kwargs):
#         s = itsdangerous.Signer(self.app.config['AUTH_SECRET'])
#         token = s.sign(b'auth_user').decode('utf-8')
# 
#         if not 'headers' in kwargs:
#             kwargs['headers'] = {}
# 
#         kwargs['headers']['X-User-Token'] = token
# 
# Path: tests/factory_boy/user_factory.py
# class UserFactory(factory.alchemy.SQLAlchemyModelFactory):
#     class Meta:
#         model = User
#         sqlalchemy_session = db.session
# 
#     id = factory.Sequence(lambda n: str(n))
# 
#     fake_name = 'Fakename'
#     real_name = 'Realname'
#     gender = 'm'


# Path: tests/api/test_auth.py
from tests.blindrtest import BlindrTest
from tests.factory_boy.user_factory import UserFactory
from unittest import mock
import json


class AuthTest(BlindrTest):

    @mock.patch('blindr.api.auth.User.from_facebook')
    def test_success_auth(self, mock_user):
        user = UserFactory.create(id='123123')
        mock_user.return_value = user

        rv = self.client.post('/auth', data=dict(fb_token='token_123'))


        mock_user.assert_called_with('token_123')