当前位置: 首页>>代码示例>>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;未经允许,请勿转载。