Esempio n. 1
0
    def test_approve_from_review_sets_publish_date(self):
        entry = Entry.objects.get(id=1)
        sm = BlogEntryWorkflow(instance=entry)

        sm.take_action('review')
        self.assertEqual('Review', sm.state)
        self.assertIsNone(entry.publish_date)

        sm.take_action('approve')
        self.assertEqual('Published', sm.state)
        self.assertIsNotNone(entry.publish_date)
Esempio n. 2
0
    def test_archive_action_method(self):
        entry = Entry.objects.get(id=1)
        entry.state = 5  # force the state for now
        entry.save()

        sm = BlogEntryWorkflow(instance=entry)

        self.assertTrue(entry.allow_comments)
        sm.take_action('archive')

        self.assertEqual('Archived', sm.state)
        self.assertFalse(entry.allow_comments)
Esempio n. 3
0
    def test_publish_action_method(self):
        entry = Entry.objects.get(id=1)
        sm = BlogEntryWorkflow(instance=entry)

        self.assertEqual('Private', sm.state)
        self.assertEqual(None, entry.publish_date)

        sm.take_action('publish')

        # Now the state should be updated ...
        self.assertEqual('Published', sm.state)

        # ... and the publish date should also be updated
        self.assertGreaterEqual(timezone.now(), entry.publish_date)
Esempio n. 4
0
    def test_public_returns_only_published(self):
        create_objects()

        self.assertEqual([], list(Entry.objects.published()))

        # We need some published items
        for item in Entry.objects.filter(id__in=[2, 3]):
            sm = BlogEntryWorkflow(instance=item)
            sm.take_action('publish')
            item.save()

        self.assertEqual(
            [2, 3],
            list(Entry.objects.published().values_list('id', flat=True)))
Esempio n. 5
0
    def test_retract_from_published_can_reset_date(self):
        entry = Entry.objects.get(id=1)
        sm = BlogEntryWorkflow(instance=entry)
        sm.take_action('publish')

        sm.take_action('retract')
        self.assertEqual('Private', sm.state)
        self.assertIsNotNone(entry.publish_date)

        sm.take_action('publish')
        # Now test with the reset feature
        sm.take_action('retract', reset_publish_date=True)
        self.assertEqual('Private', sm.state)
        self.assertIsNone(entry.publish_date)
Esempio n. 6
0
 def entry_state(self, obj):
     sm = BlogEntryWorkflow(instance=obj)
     return sm.state