# 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/timeline/factories.py
# class TimelineFactory(PageFactory):
# 
#     class Meta:
#         model = Timeline
# 
#     @factory.post_generation
#     def create(self, created, extracted, **kwargs):
#         """
#         Timeline doesn't really need a known parent but only the root page so
#         BUILD_STRATEGY isn't really required. Anyway, this is more simple to
#         achieve it in that way (instead of setting CREATE_STRATEGY and playing
#         with a lazy path attribute and MP tree...)
#         """
#         if extracted is False:
#             return
#         root = self.get_first_root_node()
#         root.add_child(instance=self)
# 
#     @factory.post_generation
#     def galleries(self, created, extracted, **kwargs):
#         galleries = extracted or []
#         for gallery in galleries:
#             self.add_child(instance=gallery)
# 
# Path: privagal/timeline/models.py
# class Timeline(AuthTokenPageMixin, Page):
# 
#     parent_page_types = []
#     subpage_types = ['gallery.Gallery']
# 
#     paginate_by = 20
# 
#     class Meta:
#         db_table = 'privagal_timeline'
# 
#     def get_context(self, request, *args, **kwargs):
#         context = super(Timeline, self).get_context(request, *args, **kwargs)
# 
#         search_query = request.GET.get('query', None)
#         context['search_query'] = search_query
# 
#         paginator, page = self.get_galleries(request, search_query)
#         context['page_obj'] = page
#         context['object_list'] = page.object_list
#         context['is_paginated'] = page.has_other_pages()
# 
#         return context
# 
#     def get_galleries(self, request, search_query):
#         qs = (
#             Gallery.objects
#             .live()
#             .prefetch_related(
#                 Prefetch(
#                     'images',
#                     queryset=ImageGallery.objects.select_related('image'),
#                 )
#             )
#             .order_by('-date')
#         )
# 
#         if search_query:
#             qs = qs.search(search_query, order_by_relevance=False)
# 
#         return paginate(request, qs, per_page=self.paginate_by)


from django.test import TestCase
from wagtail.wagtailcore.models import Page
from privagal.gallery.factories import GalleryFactory
from ..factories import TimelineFactory
from ..models import Timeline
# -*- coding: utf-8 -*-
from __future__ import unicode_literals






class TimelineFactoryTestCase(TestCase):

    def tearDown(self):
        Page.objects.type(Timeline).exclude(slug='timeline').delete()

    def test_create_strategy(self):
        timeline = TimelineFactory()
        self.assertTrue(timeline.pk)
        self.assertEqual(timeline.path, '00010002')
        self.assertEqual(timeline.depth, 2)

    def test_add_sibling(self):
        TimelineFactory()
        timeline = TimelineFactory()
        self.assertEqual(timeline.path, '00010003')

    def test_build_strategy(self):
        timeline = TimelineFactory(create=False)
        self.assertFalse(timeline.pk)

    def test_add_galleries(self):
        gallery_1 = GalleryFactory()

# 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/timeline/factories.py
# class TimelineFactory(PageFactory):
# 
#     class Meta:
#         model = Timeline
# 
#     @factory.post_generation
#     def create(self, created, extracted, **kwargs):
#         """
#         Timeline doesn't really need a known parent but only the root page so
#         BUILD_STRATEGY isn't really required. Anyway, this is more simple to
#         achieve it in that way (instead of setting CREATE_STRATEGY and playing
#         with a lazy path attribute and MP tree...)
#         """
#         if extracted is False:
#             return
#         root = self.get_first_root_node()
#         root.add_child(instance=self)
# 
#     @factory.post_generation
#     def galleries(self, created, extracted, **kwargs):
#         galleries = extracted or []
#         for gallery in galleries:
#             self.add_child(instance=gallery)
# 
# Path: privagal/timeline/models.py
# class Timeline(AuthTokenPageMixin, Page):
# 
#     parent_page_types = []
#     subpage_types = ['gallery.Gallery']
# 
#     paginate_by = 20
# 
#     class Meta:
#         db_table = 'privagal_timeline'
# 
#     def get_context(self, request, *args, **kwargs):
#         context = super(Timeline, self).get_context(request, *args, **kwargs)
# 
#         search_query = request.GET.get('query', None)
#         context['search_query'] = search_query
# 
#         paginator, page = self.get_galleries(request, search_query)
#         context['page_obj'] = page
#         context['object_list'] = page.object_list
#         context['is_paginated'] = page.has_other_pages()
# 
#         return context
# 
#     def get_galleries(self, request, search_query):
#         qs = (
#             Gallery.objects
#             .live()
#             .prefetch_related(
#                 Prefetch(
#                     'images',
#                     queryset=ImageGallery.objects.select_related('image'),
#                 )
#             )
#             .order_by('-date')
#         )
# 
#         if search_query:
#             qs = qs.search(search_query, order_by_relevance=False)
# 
#         return paginate(request, qs, per_page=self.paginate_by)


# Path: privagal/timeline/tests/test_factories.py
from django.test import TestCase
from wagtail.wagtailcore.models import Page
from privagal.gallery.factories import GalleryFactory
from ..factories import TimelineFactory
from ..models import Timeline

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






class TimelineFactoryTestCase(TestCase):

    def tearDown(self):
        Page.objects.type(Timeline).exclude(slug='timeline').delete()

    def test_create_strategy(self):
        timeline = TimelineFactory()
        self.assertTrue(timeline.pk)
        self.assertEqual(timeline.path, '00010002')
        self.assertEqual(timeline.depth, 2)

    def test_add_sibling(self):
        TimelineFactory()
        timeline = TimelineFactory()
        self.assertEqual(timeline.path, '00010003')

    def test_build_strategy(self):
        timeline = TimelineFactory(create=False)
        self.assertFalse(timeline.pk)

    def test_add_galleries(self):
        gallery_1 = GalleryFactory()

        gallery_2 = GalleryFactory()