當前位置: 首頁>>代碼示例>>Python>>正文


Python Box.add_content方法代碼示例

本文整理匯總了Python中models.Box.add_content方法的典型用法代碼示例。如果您正苦於以下問題:Python Box.add_content方法的具體用法?Python Box.add_content怎麽用?Python Box.add_content使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Box的用法示例。


在下文中一共展示了Box.add_content方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_box_timeline

# 需要導入模塊: from models import Box [as 別名]
# 或者: from models.Box import add_content [as 別名]
    def test_box_timeline(self):
        if not settings.BOX_USES_TIMELINE: return
        # What is the latest time, before we start?
        start = self._get_latest_time()

        # @ Time 1: Create empty box.
        b = Box()
        b.save()
        box_created = self._get_latest_time()
        self.assertTrue( (box_created > start),
                         "Timeline not advanced on box creation." )

        # @ Time 2: Add pages to box.
        b.add_content( [p1, p2] )
        pages_added = self._get_latest_time()
        self.assertTrue( (pages_added > box_created),
                         "Timeline not advanced on content addition." )

        # @ Time 4: Remove page 1 from box.
        b.remove_content(p1)
        page_removed = self._get_latest_time()
        self.assertTrue( (page_removed > pages_added),
                         "Timeline not advanced on content removal." )

        # Verify that box contains one page at the present time.
        self.assertEqual(len(b.contents.all()), 1,
                         "Box contents at present time not correct.")

        # View box pages @ time 2 again.
        way_back_when = b.contents.filter(added__lte=pages_added,
                                          removed__gt=pages_added)
        self.assertEqual(len(way_back_when), 2,
                         "Box contents at prior time not correct.")
開發者ID:pombredanne,項目名稱:django-dogwood,代碼行數:35,代碼來源:tests.py

示例2: test_move_contents_together

# 需要導入模塊: from models import Box [as 別名]
# 或者: from models.Box import add_content [as 別名]
    def test_move_contents_together(self):
        # Make some test pages.
        p1 = Page()
        p1.title = 'Test Page 1'
        p1.save()
        p2 = Page()
        p2.title = 'Test Page 2'
        p2.save()

        # Make two test boxes.
        b1 = Box()
        b1.save()
        b2 = Box()
        b2.save()

        # Put two pages in box 1.
        b1.add_content( (p1, p2) )

        # Put two pages in the same box into an envelope.
        e.add_content( (p1, p2) )

        # Move the envelope to box 2.
        e.move_to_box(b2)

        self.assertFalse(b1.contains_content(p1), "Page 1 did not leave box 1.")
        self.assertFalse(b1.contains_content(p2), "Page 2 did not leave box 1.")
        self.assertTrue(b2.contains_content(p1), "Page 1 did not move to box 2.")
        self.assertTrue(b2.contains_content(p2), "Page 2 did not move to box 2.")
開發者ID:pombredanne,項目名稱:django-dogwood,代碼行數:30,代碼來源:tests.py

示例3: test_envelope_integrity

# 需要導入模塊: from models import Box [as 別名]
# 或者: from models.Box import add_content [as 別名]
    def test_envelope_integrity(self):
        """ Contents in an envelope must move from box to box together. """
        # Make some test pages.
        p1 = Page()
        p1.title = 'Test Page 1'
        p1.save()
        p2 = Page()
        p2.title = 'Test Page 2'
        p2.save()
        p3 = Page()
        p3.title = 'Test Page 3'
        p3.save()

        # Make two test boxes.
        b1 = Box()
        b1.save()
        b2 = Box()
        b2.save()

        # Put two pages in box 1.
        b1.add_content(p1)
        b1.add_content(p2)

        # Put the last page in box 2.
        b2.add_content(p3)

        # Put two pages in the same box into an envelope.
        e.add_content(p1)
        e.add_content(p2)

        # Try to put the last page (which is in a different box) into the envelope.
        try:
            e.add_content(p3)
            self.fail("Envelope allowed content from multiple boxes.")
        except EnvelopeIntegrityError:
            # It should have gotten this exception, if it's working right.
            pass

        # Try to take a page out of a box without the other pages in the envelope.
        try:
            b1.remove_content(p1)
            self.fail("Envelope allowed content to be removed from box by itself.")
        except EnvelopeIntegrityError:
            # It should have gotten this exception, if it's working right.
            pass
開發者ID:pombredanne,項目名稱:django-dogwood,代碼行數:47,代碼來源:tests.py

示例4: test_box_contents

# 需要導入模塊: from models import Box [as 別名]
# 或者: from models.Box import add_content [as 別名]
    def test_box_contents(self):
        b = Box()
        b.save()
        self.assertEqual(len(b.contents.all()), 0, "Box should start out empty.")

        p1 = Page()
        p1.title = 'Test Page 1'
        b.add_content(p1)
        p2 = Page()
        p2.title = 'Test Page 2'
        b.add_content(p2)
        self.assertTrue(b.contains_content(p1), "Page 1 not found in box.")
        self.assertTrue(b.contains_content(p2), "Page 2 not found in box.")

        b.remove_content(p1)
        self.assertFalse(b.contains_content(p1), "Page 1 not removed from box.")
        b.remove_content(p2)
        self.assertFalse(b.contains_content(p2), "Page 2 not removed from box.")

        self.assertEqual(len(b.contents.all()), 0, "Box should now be empty.")
開發者ID:pombredanne,項目名稱:django-dogwood,代碼行數:22,代碼來源:tests.py


注:本文中的models.Box.add_content方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。