本文整理匯總了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.")