# 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.sites.models import Site
from django.test import TestCase
from staticgen.models import LogEntry, Page

    def test_log_action_page(self):
        log = LogEntry.objects.all()[0]
        self.assertEqual(self.page, log.page)


class TestStaticgenPageManager(TestCase):

    def setUp(self):
        site2 = Site.objects.create(name='Site 2', domain='acme.com')

        Page.objects.create(path='/page1/', site_id=settings.SITE_ID)
        Page.objects.create(
            path='/page2/', site_id=settings.SITE_ID,
            publisher_state=Page.PUBLISHER_STATE_CHANGED)
        Page.objects.create(
            path='/page3/', site_id=settings.SITE_ID,
            publisher_state=Page.PUBLISHER_STATE_PUBLISHED)
        Page.objects.create(
            path='/page4/', site_id=settings.SITE_ID,
            publisher_state=Page.PUBLISHER_STATE_ERROR)
        Page.objects.create(
            path='/page5/', site=site2,
            publisher_state=Page.PUBLISHER_STATE_DELETE
        )

    def test_page_manager_default(self):
        self.failUnlessEqual(Page.objects.all().count(), 5)

    def test_page_manager_changed(self):

# 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_managers.py
from django.conf import settings
from django.contrib.sites.models import Site
from django.test import TestCase
from staticgen.models import LogEntry, Page


    def test_log_action_page(self):
        log = LogEntry.objects.all()[0]
        self.assertEqual(self.page, log.page)


class TestStaticgenPageManager(TestCase):

    def setUp(self):
        site2 = Site.objects.create(name='Site 2', domain='acme.com')

        Page.objects.create(path='/page1/', site_id=settings.SITE_ID)
        Page.objects.create(
            path='/page2/', site_id=settings.SITE_ID,
            publisher_state=Page.PUBLISHER_STATE_CHANGED)
        Page.objects.create(
            path='/page3/', site_id=settings.SITE_ID,
            publisher_state=Page.PUBLISHER_STATE_PUBLISHED)
        Page.objects.create(
            path='/page4/', site_id=settings.SITE_ID,
            publisher_state=Page.PUBLISHER_STATE_ERROR)
        Page.objects.create(
            path='/page5/', site=site2,
            publisher_state=Page.PUBLISHER_STATE_DELETE
        )

    def test_page_manager_default(self):
        self.failUnlessEqual(Page.objects.all().count(), 5)

    def test_page_manager_changed(self):

        self.failUnlessEqual(Page.objects.changed().count(), 1)