# 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


from tests.blindrtest import BlindrTest
from unittest import mock
import json

class MeTest(BlindrTest):

    @mock.patch('blindr.api.history.Event.fetch_history')
    def test_get_history(self, mock_history):
        mock_history.return_value = [dict(foo='bar')]

        rv = self.auth_get('/events/user2', query_string=dict(since=12300))

        rv_data = json.loads(rv.data.decode('utf-8'))
        self.assert_200(rv)

        self.assertEqual([{'foo':'bar'}], rv_data)
        mock_history.assert_called_with(
            user='auth_user',
            other='user2',
            since=12300
        )

    def test_auth(self):
        rv = self.client.get('/events/city:montreal')

# 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/api/test_history.py
from tests.blindrtest import BlindrTest
from unittest import mock
import json


class MeTest(BlindrTest):

    @mock.patch('blindr.api.history.Event.fetch_history')
    def test_get_history(self, mock_history):
        mock_history.return_value = [dict(foo='bar')]

        rv = self.auth_get('/events/user2', query_string=dict(since=12300))

        rv_data = json.loads(rv.data.decode('utf-8'))
        self.assert_200(rv)

        self.assertEqual([{'foo':'bar'}], rv_data)
        mock_history.assert_called_with(
            user='auth_user',
            other='user2',
            since=12300
        )

    def test_auth(self):
        rv = self.client.get('/events/city:montreal')

        self.assert_401(rv)