本文整理汇总了Python中models.Box.contains_content方法的典型用法代码示例。如果您正苦于以下问题:Python Box.contains_content方法的具体用法?Python Box.contains_content怎么用?Python Box.contains_content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Box
的用法示例。
在下文中一共展示了Box.contains_content方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_move_contents_together
# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import contains_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.")
示例2: test_box_contents
# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import contains_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.")