# Path: privagal/core/factories.py
# class TokenFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Token
# 
# Path: privagal/core/utils.py
# class PrivagalTestCase(TestCase):
#     client_class = PrivagalClient
#     login_template_name = None
# 
#     @classmethod
#     def setUpClass(cls):
#         super(PrivagalTestCase, cls).setUpClass()
#         if settings.PRIVAGAL_AUTH_TOKEN_REQUIRED:
#             cls.login_template_name = 'token_required.html'
#         else:
#             cls.login_template_name = 'password_required.html'
# 
#     @classmethod
#     def setUpTestData(cls):
#         cls.timeline = Page.objects.get(slug='timeline').specific
# 
#     def assertPageLogged(self, response):
#         self.assertTemplateNotUsed(
#             response, self.login_template_name, msg_prefix='Not page logged in')
# 
#     def assertNotPageLogged(self, response):
#         self.assertTemplateUsed(
#             response, self.login_template_name, msg_prefix='Page logged in')


from wagtail.wagtailcore.models import PageViewRestriction
from ..factories import TokenFactory
from ..utils import PrivagalTestCase
# -*- coding: utf-8 -*-
from __future__ import unicode_literals




class AuthTokenMiddlewareTestCase(PrivagalTestCase):

    def test_no_token_url(self):
        response = self.client.get(self.timeline.url)
        self.assertNotPageLogged(response)

    def test_unknown_token(self):
        response = self.client.get(self.timeline.url, data={'token': 'foo'})
        self.assertNotPageLogged(response)

    def test_token_valid(self):
        token = TokenFactory()
        response = self.client.get(self.timeline.url, data={'token': token.key})
        self.assertPageLogged(response)

    def test_restriction_changed(self):

# Path: privagal/core/factories.py
# class TokenFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Token
# 
# Path: privagal/core/utils.py
# class PrivagalTestCase(TestCase):
#     client_class = PrivagalClient
#     login_template_name = None
# 
#     @classmethod
#     def setUpClass(cls):
#         super(PrivagalTestCase, cls).setUpClass()
#         if settings.PRIVAGAL_AUTH_TOKEN_REQUIRED:
#             cls.login_template_name = 'token_required.html'
#         else:
#             cls.login_template_name = 'password_required.html'
# 
#     @classmethod
#     def setUpTestData(cls):
#         cls.timeline = Page.objects.get(slug='timeline').specific
# 
#     def assertPageLogged(self, response):
#         self.assertTemplateNotUsed(
#             response, self.login_template_name, msg_prefix='Not page logged in')
# 
#     def assertNotPageLogged(self, response):
#         self.assertTemplateUsed(
#             response, self.login_template_name, msg_prefix='Page logged in')


# Path: privagal/core/tests/test_middleware.py
from wagtail.wagtailcore.models import PageViewRestriction
from ..factories import TokenFactory
from ..utils import PrivagalTestCase

# -*- coding: utf-8 -*-
from __future__ import unicode_literals




class AuthTokenMiddlewareTestCase(PrivagalTestCase):

    def test_no_token_url(self):
        response = self.client.get(self.timeline.url)
        self.assertNotPageLogged(response)

    def test_unknown_token(self):
        response = self.client.get(self.timeline.url, data={'token': 'foo'})
        self.assertNotPageLogged(response)

    def test_token_valid(self):
        token = TokenFactory()
        response = self.client.get(self.timeline.url, data={'token': token.key})
        self.assertPageLogged(response)

    def test_restriction_changed(self):

        token = TokenFactory()