本文整理汇总了Python中turses.models.Timeline.add_statuses方法的典型用法代码示例。如果您正苦于以下问题:Python Timeline.add_statuses方法的具体用法?Python Timeline.add_statuses怎么用?Python Timeline.add_statuses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turses.models.Timeline
的用法示例。
在下文中一共展示了Timeline.add_statuses方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TimelineTest
# 需要导入模块: from turses.models import Timeline [as 别名]
# 或者: from turses.models.Timeline import add_statuses [as 别名]
class TimelineTest(ActiveListTest):
def setUp(self):
self.timeline = Timeline()
self.assert_null_index()
def active_index(self):
return self.timeline.active_index
# unique elements
def test_unique_statuses_in_timeline(self):
status = create_status()
self.timeline.add_status(status)
self.timeline.add_status(status)
self.assertEqual(len(self.timeline), 1)
# active index
def test_active_index_is_0_when_creating_timeline_with_statuses(self):
status = create_status()
self.timeline = Timeline(statuses=[status])
self.assertEqual(self.timeline.active_index, 0)
def test_active_index_becomes_0_when_adding_first_status(self):
status = create_status()
self.timeline.add_status(status)
self.assertEqual(self.timeline.active_index, 0)
def test_active_index_does_not_change_when_adding_various_statuses(self):
a_status = create_status(id=1)
another_status = create_status(id=2)
# first
self.timeline.add_status(a_status)
self.assertEqual(self.timeline.active_index, 0)
# second
self.timeline.add_status(another_status)
self.assertEqual(self.timeline.active_index, 0)
# insertion
def test_insert_different_statuses_individually(self):
old_status = create_status(created_at=datetime(1988, 12, 19))
new_status = create_status(id=2)
# first
self.timeline.add_status(old_status)
self.assertEqual(len(self.timeline), 1)
# second
self.timeline.add_status(new_status)
self.assertEqual(len(self.timeline), 2)
def test_insert_different_statuses(self):
old_status = create_status(created_at=datetime(1988, 12, 19))
new_status = create_status(id=2)
self.timeline.add_statuses([old_status, new_status])
self.assertEqual(len(self.timeline), 2)
# order
def test_statuses_ordered_reversely_by_date(self):
old_status = create_status(created_at=datetime(1988, 12, 19))
new_status = create_status(id=2)
# ordered
self.timeline = Timeline(statuses=[new_status, old_status])
self.assertEqual(self.timeline[0], new_status)
self.assertEqual(self.timeline[1], old_status)
# unordered
self.timeline = Timeline(statuses=[old_status, new_status])
self.assertEqual(self.timeline[0], new_status)
self.assertEqual(self.timeline[1], old_status)
# unread
def test_unread_count(self):
self.assertEqual(self.timeline.unread_count, 0)
# a status
status = create_status(id=1)
self.timeline.add_status(status)
self.assertEqual(self.timeline.unread_count, 1)
self.timeline.mark_all_as_read()
self.assertEqual(self.timeline.unread_count, 0)
# new statuses
statuses = [create_status(id=id_num) for id_num in xrange(2, 10)]
#.........这里部分代码省略.........
示例2: TimelineTest
# 需要导入模块: from turses.models import Timeline [as 别名]
# 或者: from turses.models.Timeline import add_statuses [as 别名]
class TimelineTest(unittest.TestCase):
def setUp(self):
self.timeline = Timeline()
self.timeline.clear()
self.assertEqual(len(self.timeline), 0)
self.assertEqual(self.timeline.active_index, ActiveList.NULL_INDEX)
def test_unique_statuses_in_timeline(self):
self.assertEqual(len(self.timeline), 0)
# create and add the status
status = create_status()
self.timeline.add_status(status)
self.assertEqual(len(self.timeline), 1)
# check that adding more than once does not duplicate element
self.timeline.add_status(status)
self.assertEqual(len(self.timeline), 1)
def test_active_index_becomes_0_when_adding_first_status(self):
status = create_status()
self.timeline.add_status(status)
self.assertEqual(self.timeline.active_index, 0)
# check that adding than once does not move the active
self.timeline.add_status(status)
self.assertEqual(self.timeline.active_index, 0)
def test_insert_different_statuses(self):
old_status = create_status(created_at=datetime(1988, 12, 19))
new_status = create_status(id=2)
self.timeline.add_statuses([old_status, new_status])
self.assertEqual(len(self.timeline), 2)
def assert_active(self, status):
active_status = self.timeline.get_active()
if active_status:
self.assertEqual(status, active_status)
else:
raise Exception("There is no active status")
def test_active_is_the_same_when_inserting_statuses(self):
"""
Test that when inserting new statuses the active doesn't change.
"""
active_status = create_status(created_at=datetime(1988, 12, 19))
self.timeline.add_status(active_status)
self.assert_active(active_status)
older_status = create_status(id=2,
created_at=datetime(1978, 12, 19))
self.timeline.add_status(older_status)
self.assert_active(active_status)
newer_status = create_status(id=2)
self.timeline.add_status(newer_status)
self.assert_active(active_status)
def test_insert_different_statuses_individually(self):
old_status = create_status(created_at=datetime(1988, 12, 19))
new_status = create_status(id=2)
self.timeline.add_status(old_status)
self.assertEqual(len(self.timeline), 1)
self.timeline.add_status(new_status)
self.assertEqual(len(self.timeline), 2)
def test_statuses_ordered_reversely_by_date(self):
old_status = create_status(created_at=datetime(1988, 12, 19))
new_status = create_status(id=2)
self.timeline.add_statuses([old_status, new_status])
self.assertEqual(self.timeline[0], new_status)
self.assertEqual(self.timeline[1], old_status)
def test_get_newer_than(self):
old_created_at = datetime(1988, 12, 19)
old_status = create_status(created_at=old_created_at)
new_created_at = datetime.now()
new_status = create_status(id=2,
created_at=new_created_at)
self.timeline.add_statuses([old_status, new_status])
# get newers than `old_status`
newers = self.timeline.get_newer_than(old_created_at)
self.assertEqual(len(newers), 1)
self.assertEqual(newers[0].id, new_status.id)
# get newers than `new_status`
newers = self.timeline.get_newer_than(new_created_at)
self.assertEqual(len(newers), 0)
def test_clear(self):
old_created_at = datetime(1988, 12, 19)
old_status = create_status(created_at=old_created_at)
new_created_at = datetime.now()
new_status = create_status(id=2,
created_at=new_created_at)
self.timeline.add_statuses([old_status, new_status])
self.timeline.clear()
self.assertEqual(len(self.timeline), 0)
# add them again and check that they are inserted back
self.timeline.add_statuses([old_status, new_status])
self.assertEqual(len(self.timeline), 2)
def test_get_unread_count(self):
self.assertEqual(self.timeline.get_unread_count(), 0)
#.........这里部分代码省略.........