# Path: timeline_logger/models.py
# class TimelineLog(models.Model):
#     content_type = models.ForeignKey(
#         ContentType,
#         verbose_name=_('content type'),
#         on_delete=models.SET_NULL,
#         blank=True, null=True,
#     )
#     object_id = models.TextField(
#         verbose_name=_('object id'),
#         blank=True, null=True
#     )
#     content_object = GenericForeignKey('content_type', 'object_id')
#     timestamp = models.DateTimeField(verbose_name=_('timestamp'), auto_now_add=True)
#     extra_data = JSONField(
#         verbose_name=_('extra data'),
#         null=True, blank=True,
#     )
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         verbose_name=_('user'),
#         on_delete=models.SET_NULL,
#         blank=True, null=True,
#     )
#     template = models.CharField(max_length=200, default=DEFAULT_TEMPLATE)
# 
#     class Meta:
#         verbose_name = _('timeline log entry')
#         verbose_name_plural = _('timeline log entries')
# 
#     def __str__(self):
#         if self.object_id:
#             return "{ct} - {pk}".format(
#                 ct=self.content_type.name,
#                 pk=self.object_id
#             )
# 
#         return ugettext('TimelineLog Object')
# 
#     @classmethod
#     def log_from_request(cls, request, content_object, template=None, **extra_data):
#         """
#         Given an ``HTTPRequest`` object and a generic content, it creates a
#         ``TimelineLog`` object to store the data of that request.
# 
#         :param request: A Django ``HTTPRequest`` object.
#         :param content_object: A Django model instance. Any object can be
#         related.
#         :param template: String representing the template to be used to render
#         the message. Defaults to 'default.txt'.
#         :param extra_data: A dictionary (translatable into JSON) determining
#         specifications of the action performed.
#         :return: A newly created ``TimelineLog`` instance.
#         """
#         try:
#             user = request.user
#         except AttributeError:
#             user = None
# 
#         if template is not None:
#             # Ensure that the expected template actually exists.
#             get_template(template)
# 
#         timeline_log = cls.objects.create(
#             content_object=content_object,
#             extra_data=extra_data or None,
#             template=template or DEFAULT_TEMPLATE,
#             user=user,
#         )
#         logger.debug('Logged event in %s %s', content_object._meta.object_name, content_object.pk)
#         return timeline_log
# 
#     def get_message(self, template=None, **extra_context):
#         """
#         Gets the 'log' message, describing the event performed.
# 
#         :param template: String representing the template to be used to render
#         the message. Defaults to ``self.template``.
#         :return: The log message string.
#         """
#         context = {'log': self}
#         context.update(**extra_context)
#         return render_to_string(template or self.template, context)
# 
# Path: tests/factories.py
# class ArticleFactory(factory.django.DjangoModelFactory):
# 
#     class Meta:
#         model = 'tests.Article'
# 
#     title = factory.Faker('sentence')
#     date = factory.Faker('date')
# 
# class UserFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = 'auth.User'
# 
#     first_name = 'Test'
#     last_name = 'User'
#     username = factory.Sequence(lambda n: 'user_{0}'.format(n))
#     email = factory.Sequence(lambda n: 'user_{0}@maykinmedia.nl'.format(n))
#     password = factory.PostGenerationMethodCall('set_password', 'testing')


from datetime import timedelta
from django.conf import settings
from django.core import mail
from django.core.management import CommandError, call_command
from django.template.defaultfilters import date
from django.test import TestCase, override_settings
from django.utils import timezone
from timeline_logger.models import TimelineLog
from .factories import ArticleFactory, UserFactory





class ReportMailingTestCase(TestCase):
    def setUp(self):
        self.article = ArticleFactory.create()

        self.user = UserFactory.create(email='jose@maykinmedia.nl')
        self.staff_user = UserFactory.create(is_staff=True)
        self.admin_user = UserFactory.create(is_staff=True, is_superuser=True)


# Path: timeline_logger/models.py
# class TimelineLog(models.Model):
#     content_type = models.ForeignKey(
#         ContentType,
#         verbose_name=_('content type'),
#         on_delete=models.SET_NULL,
#         blank=True, null=True,
#     )
#     object_id = models.TextField(
#         verbose_name=_('object id'),
#         blank=True, null=True
#     )
#     content_object = GenericForeignKey('content_type', 'object_id')
#     timestamp = models.DateTimeField(verbose_name=_('timestamp'), auto_now_add=True)
#     extra_data = JSONField(
#         verbose_name=_('extra data'),
#         null=True, blank=True,
#     )
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         verbose_name=_('user'),
#         on_delete=models.SET_NULL,
#         blank=True, null=True,
#     )
#     template = models.CharField(max_length=200, default=DEFAULT_TEMPLATE)
# 
#     class Meta:
#         verbose_name = _('timeline log entry')
#         verbose_name_plural = _('timeline log entries')
# 
#     def __str__(self):
#         if self.object_id:
#             return "{ct} - {pk}".format(
#                 ct=self.content_type.name,
#                 pk=self.object_id
#             )
# 
#         return ugettext('TimelineLog Object')
# 
#     @classmethod
#     def log_from_request(cls, request, content_object, template=None, **extra_data):
#         """
#         Given an ``HTTPRequest`` object and a generic content, it creates a
#         ``TimelineLog`` object to store the data of that request.
# 
#         :param request: A Django ``HTTPRequest`` object.
#         :param content_object: A Django model instance. Any object can be
#         related.
#         :param template: String representing the template to be used to render
#         the message. Defaults to 'default.txt'.
#         :param extra_data: A dictionary (translatable into JSON) determining
#         specifications of the action performed.
#         :return: A newly created ``TimelineLog`` instance.
#         """
#         try:
#             user = request.user
#         except AttributeError:
#             user = None
# 
#         if template is not None:
#             # Ensure that the expected template actually exists.
#             get_template(template)
# 
#         timeline_log = cls.objects.create(
#             content_object=content_object,
#             extra_data=extra_data or None,
#             template=template or DEFAULT_TEMPLATE,
#             user=user,
#         )
#         logger.debug('Logged event in %s %s', content_object._meta.object_name, content_object.pk)
#         return timeline_log
# 
#     def get_message(self, template=None, **extra_context):
#         """
#         Gets the 'log' message, describing the event performed.
# 
#         :param template: String representing the template to be used to render
#         the message. Defaults to ``self.template``.
#         :return: The log message string.
#         """
#         context = {'log': self}
#         context.update(**extra_context)
#         return render_to_string(template or self.template, context)
# 
# Path: tests/factories.py
# class ArticleFactory(factory.django.DjangoModelFactory):
# 
#     class Meta:
#         model = 'tests.Article'
# 
#     title = factory.Faker('sentence')
#     date = factory.Faker('date')
# 
# class UserFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = 'auth.User'
# 
#     first_name = 'Test'
#     last_name = 'User'
#     username = factory.Sequence(lambda n: 'user_{0}'.format(n))
#     email = factory.Sequence(lambda n: 'user_{0}@maykinmedia.nl'.format(n))
#     password = factory.PostGenerationMethodCall('set_password', 'testing')


# Path: tests/test_management_commands.py
from datetime import timedelta
from django.conf import settings
from django.core import mail
from django.core.management import CommandError, call_command
from django.template.defaultfilters import date
from django.test import TestCase, override_settings
from django.utils import timezone
from timeline_logger.models import TimelineLog
from .factories import ArticleFactory, UserFactory






class ReportMailingTestCase(TestCase):
    def setUp(self):
        self.article = ArticleFactory.create()

        self.user = UserFactory.create(email='jose@maykinmedia.nl')
        self.staff_user = UserFactory.create(is_staff=True)
        self.admin_user = UserFactory.create(is_staff=True, is_superuser=True)


        self.log_1 = TimelineLog.objects.create(