# Path: elephantblog/contents.py
# class BlogCategoryListContent(models.Model):
#     show_empty_categories = models.BooleanField(_("show empty categories?"))
# 
#     class Meta:
#         abstract = True
#         verbose_name = _("Blog category list")
#         verbose_name_plural = _("Blog category lists")
# 
#     def render(self, **kwargs):
#         if self.show_empty_categories:
#             categories = Category.objects.all()
#         else:
#             categories = Category.objects.exclude(blogentries__isnull=True)
# 
#         return (
#             "content/elephantblog/category_list.html",
#             {"content": self, "categories": categories},
#         )
# 
# class BlogEntryListContent(models.Model):
#     category = models.ForeignKey(
#         Category,
#         blank=True,
#         null=True,
#         related_name="+",
#         on_delete=models.CASCADE,
#         verbose_name=_("category"),
#         help_text=_("Only show entries from this category."),
#     )
#     paginate_by = models.PositiveIntegerField(
#         _("entries per page"), default=0, help_text=_("Set to 0 to disable pagination.")
#     )
#     featured_only = models.BooleanField(
#         _("featured only"),
#         blank=True,
#         default=False,
#         help_text=_("Only show articles marked as featured"),
#     )
# 
#     only_active_language = False
# 
#     class Meta:
#         abstract = True
#         verbose_name = _("Blog entry list")
#         verbose_name_plural = _("Blog entry lists")
# 
#     def process(self, request, **kwargs):
#         if self.featured_only:
#             entries = Entry.objects.featured()
#         else:
#             entries = Entry.objects.active()
# 
#         if self.category:
#             entries = entries.filter(categories=self.category)
# 
#         if self.only_active_language:
#             entries = entries.filter(language=get_language())
# 
#         entries = entries.transform(entry_list_lookup_related)
# 
#         if self.paginate_by:
#             paginator = Paginator(entries, self.paginate_by)
#             page = request.GET.get("page", 1)
#             try:
#                 self.entries = paginator.page(page)
#             except PageNotAnInteger:
#                 self.entries = paginator.page(1)
#             except EmptyPage:
#                 self.entries = paginator.page(paginator.num_pages)
# 
#         else:
#             self.entries = entries
# 
#     def render(self, **kwargs):
#         template_names = ["content/elephantblog/entry_list.html"]
#         if self.featured_only:
#             template_names.insert(0, "entry_list_featured.html")
#         return template_names, {"content": self}
# 
# Path: tests/testapp/factories.py
# class EntryFactory(DjangoModelFactory):
#     class Meta:
#         model = Entry
# 
#     is_active = True
#     is_featured = False
# 
# def create_category(title):
#     category = CategoryFactory.create()
#     CategoryTranslationFactory.create(parent=category, title=title, slug=slugify(title))
#     return category
# 
# def create_entries(factory):
#     tz = zoneinfo.ZoneInfo(settings.TIME_ZONE)
#     author = UserFactory()
#     entries = []
#     date1 = datetime.datetime(2012, 8, 12, 11, 0, 0, tzinfo=tz)
#     delta = datetime.timedelta(hours=4)
#     date2 = datetime.datetime(2012, 10, 12, 11, 1, 0, tzinfo=tz)
# 
#     entries.append(
#         factory.create(
#             pk=1,
#             author=author,
#             title="Entry 1",
#             published_on=date1,
#             last_changed=date1 + delta,
#             slug="entry-1",
#             language="en",
#         )
#     )
#     entries.append(
#         factory.create(
#             pk=2,
#             author=author,
#             title="Eintrag 1",
#             published_on=date2,
#             last_changed=date2 + delta,
#             slug="eintrag-1",
#             language="en",
#         )
#     )
#     return entries


from django.template.loader import render_to_string
from django.test import TestCase
from elephantblog.contents import BlogCategoryListContent, BlogEntryListContent
from .factories import EntryFactory, create_category, create_entries




class Request:
    GET = {"page": 1}


class ContentsTestCase(TestCase):
    def test_contents(self):

# Path: elephantblog/contents.py
# class BlogCategoryListContent(models.Model):
#     show_empty_categories = models.BooleanField(_("show empty categories?"))
# 
#     class Meta:
#         abstract = True
#         verbose_name = _("Blog category list")
#         verbose_name_plural = _("Blog category lists")
# 
#     def render(self, **kwargs):
#         if self.show_empty_categories:
#             categories = Category.objects.all()
#         else:
#             categories = Category.objects.exclude(blogentries__isnull=True)
# 
#         return (
#             "content/elephantblog/category_list.html",
#             {"content": self, "categories": categories},
#         )
# 
# class BlogEntryListContent(models.Model):
#     category = models.ForeignKey(
#         Category,
#         blank=True,
#         null=True,
#         related_name="+",
#         on_delete=models.CASCADE,
#         verbose_name=_("category"),
#         help_text=_("Only show entries from this category."),
#     )
#     paginate_by = models.PositiveIntegerField(
#         _("entries per page"), default=0, help_text=_("Set to 0 to disable pagination.")
#     )
#     featured_only = models.BooleanField(
#         _("featured only"),
#         blank=True,
#         default=False,
#         help_text=_("Only show articles marked as featured"),
#     )
# 
#     only_active_language = False
# 
#     class Meta:
#         abstract = True
#         verbose_name = _("Blog entry list")
#         verbose_name_plural = _("Blog entry lists")
# 
#     def process(self, request, **kwargs):
#         if self.featured_only:
#             entries = Entry.objects.featured()
#         else:
#             entries = Entry.objects.active()
# 
#         if self.category:
#             entries = entries.filter(categories=self.category)
# 
#         if self.only_active_language:
#             entries = entries.filter(language=get_language())
# 
#         entries = entries.transform(entry_list_lookup_related)
# 
#         if self.paginate_by:
#             paginator = Paginator(entries, self.paginate_by)
#             page = request.GET.get("page", 1)
#             try:
#                 self.entries = paginator.page(page)
#             except PageNotAnInteger:
#                 self.entries = paginator.page(1)
#             except EmptyPage:
#                 self.entries = paginator.page(paginator.num_pages)
# 
#         else:
#             self.entries = entries
# 
#     def render(self, **kwargs):
#         template_names = ["content/elephantblog/entry_list.html"]
#         if self.featured_only:
#             template_names.insert(0, "entry_list_featured.html")
#         return template_names, {"content": self}
# 
# Path: tests/testapp/factories.py
# class EntryFactory(DjangoModelFactory):
#     class Meta:
#         model = Entry
# 
#     is_active = True
#     is_featured = False
# 
# def create_category(title):
#     category = CategoryFactory.create()
#     CategoryTranslationFactory.create(parent=category, title=title, slug=slugify(title))
#     return category
# 
# def create_entries(factory):
#     tz = zoneinfo.ZoneInfo(settings.TIME_ZONE)
#     author = UserFactory()
#     entries = []
#     date1 = datetime.datetime(2012, 8, 12, 11, 0, 0, tzinfo=tz)
#     delta = datetime.timedelta(hours=4)
#     date2 = datetime.datetime(2012, 10, 12, 11, 1, 0, tzinfo=tz)
# 
#     entries.append(
#         factory.create(
#             pk=1,
#             author=author,
#             title="Entry 1",
#             published_on=date1,
#             last_changed=date1 + delta,
#             slug="entry-1",
#             language="en",
#         )
#     )
#     entries.append(
#         factory.create(
#             pk=2,
#             author=author,
#             title="Eintrag 1",
#             published_on=date2,
#             last_changed=date2 + delta,
#             slug="eintrag-1",
#             language="en",
#         )
#     )
#     return entries


# Path: tests/testapp/test_contents.py
from django.template.loader import render_to_string
from django.test import TestCase
from elephantblog.contents import BlogCategoryListContent, BlogEntryListContent
from .factories import EntryFactory, create_category, create_entries





class Request:
    GET = {"page": 1}


class ContentsTestCase(TestCase):
    def test_contents(self):

        entries = create_entries(EntryFactory)