示例#1
0
    def testMakeDraft(self):
        book = models.Book.objects.get(vid=1)
        self.assertEqual(book.name, 'Book1')

        # draft cannot make draft -- return nothing inside make_draft function.
        with self.assertRaises(AssertionError):
            book.make_draft()

        klass = book.get_version_class()
        book = klass.normal.get(vid=1)
        book.make_draft()
        self.assertEqual(
            models.Book.objects.filter(object_id=book.object_id).count(), 1)

        book = klass.normal.get(vid=1)
        book.publish()

        # prepare a draft for deleting when calling make_draft
        draft = klass.normal.get(object_id=book.object_id,
                                 state=models.Book.DRAFT)
        self.assertEqual(draft.last_scheduled, draft.last_save)
        draft.name = 'book2'
        draft.save()
        self.assertTrue(klass.normal.filter(name='book2').exists())

        # need to get the object again to get updated last_save value, coz the
        # one cached by django is not updated.
        draft = klass.normal.get(object_id=book.object_id,
                                 state=models.Book.DRAFT)
        self.assertEqual(draft.last_scheduled, book.last_scheduled)
        self.assertTrue(draft.last_scheduled < draft.last_save)

        book = klass.normal.get(object_id=book.object_id,
                                state=models.Book.PUBLISHED)
        book.make_draft()
        # make sure the old draft get deleted
        self.assertFalse(klass.normal.filter(name='book2').exists())

        # make sure the underlying two versions of book are "same"
        manager.deactivate()
        bd = models.Book.objects.get(object_id=book.object_id,
                                     state=models.Book.DRAFT)
        bp = models.Book.objects.get(object_id=book.object_id,
                                     state=models.Book.PUBLISHED)
        manager.activate('draft')

        self.assertEqual(bd.name, 'Book1')
        self._check_different_book_versions(bd, bp)
示例#2
0
    def testLazyEval(self):
        schema = manager.get_schema()
        self.assertEqual(schema, None)
        book = models.Book.objects.get(vid=1)
        book.publish()

        manager.activate('published')
        qs = models.Book.objects.filter(pk=1)
        self.assertEqual(qs.count(), 1)
        manager.deactivate()

        manager.activate('draft')
        self.assertEqual(qs.count(), 1)
        manager.deactivate()

        self.assertEqual(qs.count(), 2)
示例#3
0
    def testActivate(self):
        schema = manager.get_schema()
        self.assertEqual(schema, None)

        book = models.Book.objects.get(vid=1)
        book.publish()
        self.assertTrue(
            models.Book.objects.filter(state=models.Book.PUBLISHED,
                                       object_id=book.object_id))

        manager.activate('draft')
        self.assertFalse(
            models.Book.objects.filter(state=models.Book.PUBLISHED,
                                       object_id=book.object_id))
        schema = manager.get_schema()
        self.assertEqual(schema, 'draft')

        manager.deactivate()
        self.assertTrue(
            models.Book.objects.filter(state=models.Book.PUBLISHED,
                                       object_id=book.object_id))
        schema = manager.get_schema()
        self.assertEqual(schema, None)
示例#4
0
 def setUp(self):
     manager.activate('draft')