# Path: privagal/gallery/factories.py
# class GalleryFactory(PageFactory):
# 
#     class Meta:
#         model = Gallery
# 
#     date = fuzzy.FuzzyDate(datetime.date(2016, 1, 1))
#     body = factory.LazyAttribute(
#         lambda x: "<p>{}</p>".format(faker.paragraph()))
# 
#     @factory.post_generation
#     def images(self, created, extracted, **kwargs):
#         """
#         Usage example:
#         >>> GalleryFactory(images__images=[ImageFactory()])
#         """
#         images = kwargs.pop('images', [])
#         if not images:
#             images = [ImageFactory() for i in range(0, 3)]
# 
#         self.images = [ImageGalleryFactory.build(page=self, image=i) for i in images]
# 
# 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 django.contrib.auth import get_user_model
from django.test import override_settings
from privagal.gallery.factories import GalleryFactory
from ..utils import PrivagalTestCase




@override_settings(PRIVAGAL_AUTH_TOKEN_REQUIRED=False)
class AuthTokenNotRequiredTestCase(PrivagalTestCase):

    @classmethod
    def setUpTestData(cls):
        super(AuthTokenNotRequiredTestCase, cls).setUpTestData()
        cls.gallery = GalleryFactory()
        cls.timeline.add_child(instance=cls.gallery)

    def test_password_required_timeline(self):
        response = self.client.get(self.timeline.url)
        self.assertTemplateUsed(response, 'password_required.html')

    def test_password_required_gallery(self):
        response = self.client.get(self.gallery.url)
        self.assertTemplateUsed(response, 'password_required.html')


@override_settings(PRIVAGAL_AUTH_TOKEN_REQUIRED=True)
class AuthTokenRequiredTestCase(PrivagalTestCase):

    @classmethod
    def setUpTestData(cls):
        super(AuthTokenRequiredTestCase, cls).setUpTestData()
        cls.user_staff = get_user_model().objects.create_user(
            'foo', is_staff=True)

# Path: privagal/gallery/factories.py
# class GalleryFactory(PageFactory):
# 
#     class Meta:
#         model = Gallery
# 
#     date = fuzzy.FuzzyDate(datetime.date(2016, 1, 1))
#     body = factory.LazyAttribute(
#         lambda x: "<p>{}</p>".format(faker.paragraph()))
# 
#     @factory.post_generation
#     def images(self, created, extracted, **kwargs):
#         """
#         Usage example:
#         >>> GalleryFactory(images__images=[ImageFactory()])
#         """
#         images = kwargs.pop('images', [])
#         if not images:
#             images = [ImageFactory() for i in range(0, 3)]
# 
#         self.images = [ImageGalleryFactory.build(page=self, image=i) for i in images]
# 
# 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_mixins.py
from django.contrib.auth import get_user_model
from django.test import override_settings
from privagal.gallery.factories import GalleryFactory
from ..utils import PrivagalTestCase





@override_settings(PRIVAGAL_AUTH_TOKEN_REQUIRED=False)
class AuthTokenNotRequiredTestCase(PrivagalTestCase):

    @classmethod
    def setUpTestData(cls):
        super(AuthTokenNotRequiredTestCase, cls).setUpTestData()
        cls.gallery = GalleryFactory()
        cls.timeline.add_child(instance=cls.gallery)

    def test_password_required_timeline(self):
        response = self.client.get(self.timeline.url)
        self.assertTemplateUsed(response, 'password_required.html')

    def test_password_required_gallery(self):
        response = self.client.get(self.gallery.url)
        self.assertTemplateUsed(response, 'password_required.html')


@override_settings(PRIVAGAL_AUTH_TOKEN_REQUIRED=True)
class AuthTokenRequiredTestCase(PrivagalTestCase):

    @classmethod
    def setUpTestData(cls):
        super(AuthTokenRequiredTestCase, cls).setUpTestData()
        cls.user_staff = get_user_model().objects.create_user(
            'foo', is_staff=True)

        cls.gallery = GalleryFactory()