# Path: staticgen/models.py
# class LogEntry(models.Model):
#     site = models.ForeignKey(Site, verbose_name=_('Site'))
#     page = models.ForeignKey(Page, blank=True, null=True, on_delete=models.CASCADE)
#     change_message = models.TextField(_('change message'))
#     action_time = models.DateTimeField(_('action time'), auto_now=True)
# 
#     objects = LogEntryManager()
# 
#     class Meta:
#         verbose_name = _('log entry')
#         verbose_name_plural = _('log entries')
#         ordering = ('-action_time',)
# 
#     def __str__(self):
#         return self.change_message
# 
# class Page(models.Model):
#     PUBLISHER_STATE_DEFAULT = 0
#     PUBLISHER_STATE_CHANGED = 1
#     PUBLISHER_STATE_PUBLISHED = 2
#     PUBLISHER_STATE_ERROR = 3
#     PUBLISHER_STATE_DELETE = 4
# 
#     PUBLISHER_STATES = (
#         (PUBLISHER_STATE_DEFAULT, _('Pending')),
#         (PUBLISHER_STATE_CHANGED, _('Changed')),
#         (PUBLISHER_STATE_PUBLISHED, _('Published')),
#         (PUBLISHER_STATE_ERROR, _('Error')),
#         (PUBLISHER_STATE_DELETE, _('Deleted'))
#     )
# 
#     site = models.ForeignKey(Site, verbose_name=_('Site'))
#     path = models.CharField(_('URL'), max_length=255)
#     publisher_state = models.SmallIntegerField(
#         _('State'), choices=PUBLISHER_STATES, default=PUBLISHER_STATE_DEFAULT,
#         editable=False, db_index=True)
#     updated_at = models.DateTimeField(auto_now=True)
#     objects = PageManager()
# 
#     class Meta:
#         verbose_name = _('page')
#         verbose_name_plural = _('pages')
#         ordering = ('path', )
#         unique_together = ('site', 'path')
# 
#     def __str__(self):
#         return self.path
# 
#     @property
#     def has_changed(self):
#         return self.publisher_state == self.PUBLISHER_STATE_CHANGED


from django.conf import settings
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils.encoding import force_text
from mock import patch
from staticgen.models import LogEntry, Page
            'action': 'make_dirty',
            '_selected_action': Page.objects.all().values_list('pk', flat=True)
        }
        self.client.post(reverse('admin:staticgen_page_changelist'), data)
        self.assertEqual(Page.objects.changed().count(), 5)

    def test_history_view(self):
        response = self.client.get(reverse('admin:staticgen_page_history', args=(1,)))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['action_list']), 1)

    def test_publish_history_view(self):
        response = self.client.get(reverse('admin:staticgen_page_publish_history'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['action_list']), 1)

    @patch('staticgen.tasks.publish_pages.delay')
    def test_publish_view(self, mocked_task):
        # task to publish/update all registered pages should be called
        publish_url = '{url}?action=all'.format(url=self.publisher_url)
        response = self.client.get(publish_url)
        self.assertRedirects(response, self.page_changelist)
        self.assertTrue(mocked_task.called)

    @patch('staticgen.tasks.publish_pending.delay')
    def test_publish_pending_view(self, mocked_task):
        # task to publish pending pages should be called
        publish_url = '{url}?action=pending'.format(url=self.publisher_url)
        response = self.client.get(publish_url)


# Path: staticgen/models.py
# class LogEntry(models.Model):
#     site = models.ForeignKey(Site, verbose_name=_('Site'))
#     page = models.ForeignKey(Page, blank=True, null=True, on_delete=models.CASCADE)
#     change_message = models.TextField(_('change message'))
#     action_time = models.DateTimeField(_('action time'), auto_now=True)
# 
#     objects = LogEntryManager()
# 
#     class Meta:
#         verbose_name = _('log entry')
#         verbose_name_plural = _('log entries')
#         ordering = ('-action_time',)
# 
#     def __str__(self):
#         return self.change_message
# 
# class Page(models.Model):
#     PUBLISHER_STATE_DEFAULT = 0
#     PUBLISHER_STATE_CHANGED = 1
#     PUBLISHER_STATE_PUBLISHED = 2
#     PUBLISHER_STATE_ERROR = 3
#     PUBLISHER_STATE_DELETE = 4
# 
#     PUBLISHER_STATES = (
#         (PUBLISHER_STATE_DEFAULT, _('Pending')),
#         (PUBLISHER_STATE_CHANGED, _('Changed')),
#         (PUBLISHER_STATE_PUBLISHED, _('Published')),
#         (PUBLISHER_STATE_ERROR, _('Error')),
#         (PUBLISHER_STATE_DELETE, _('Deleted'))
#     )
# 
#     site = models.ForeignKey(Site, verbose_name=_('Site'))
#     path = models.CharField(_('URL'), max_length=255)
#     publisher_state = models.SmallIntegerField(
#         _('State'), choices=PUBLISHER_STATES, default=PUBLISHER_STATE_DEFAULT,
#         editable=False, db_index=True)
#     updated_at = models.DateTimeField(auto_now=True)
#     objects = PageManager()
# 
#     class Meta:
#         verbose_name = _('page')
#         verbose_name_plural = _('pages')
#         ordering = ('path', )
#         unique_together = ('site', 'path')
# 
#     def __str__(self):
#         return self.path
# 
#     @property
#     def has_changed(self):
#         return self.publisher_state == self.PUBLISHER_STATE_CHANGED


# Path: tests/test_admin.py
from django.conf import settings
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils.encoding import force_text
from mock import patch
from staticgen.models import LogEntry, Page

            'action': 'make_dirty',
            '_selected_action': Page.objects.all().values_list('pk', flat=True)
        }
        self.client.post(reverse('admin:staticgen_page_changelist'), data)
        self.assertEqual(Page.objects.changed().count(), 5)

    def test_history_view(self):
        response = self.client.get(reverse('admin:staticgen_page_history', args=(1,)))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['action_list']), 1)

    def test_publish_history_view(self):
        response = self.client.get(reverse('admin:staticgen_page_publish_history'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['action_list']), 1)

    @patch('staticgen.tasks.publish_pages.delay')
    def test_publish_view(self, mocked_task):
        # task to publish/update all registered pages should be called
        publish_url = '{url}?action=all'.format(url=self.publisher_url)
        response = self.client.get(publish_url)
        self.assertRedirects(response, self.page_changelist)
        self.assertTrue(mocked_task.called)

    @patch('staticgen.tasks.publish_pending.delay')
    def test_publish_pending_view(self, mocked_task):
        # task to publish pending pages should be called
        publish_url = '{url}?action=pending'.format(url=self.publisher_url)
        response = self.client.get(publish_url)


        self.assertRedirects(response, self.page_changelist)